-
Notifications
You must be signed in to change notification settings - Fork 22
/
ChainedSetterTest.java
99 lines (85 loc) · 3.15 KB
/
ChainedSetterTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.remondis.remap.fluent;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import com.remondis.remap.AssertMapping;
import com.remondis.remap.Mapper;
import com.remondis.remap.Mapping;
import com.remondis.remap.MappingConfiguration;
import com.remondis.remap.MappingException;
public class ChainedSetterTest {
@Test
public void testChainedSetter() {
Mapper<FluentSetterDto, FluentSetterDto> m = Mapping.from(FluentSetterDto.class)
.to(FluentSetterDto.class)
.allowFluentSetters()
.mapper();
FluentSetterDto expected = new FluentSetterDto().setInteger(5)
.setI(22)
.setS("str")
.setB1(true)
.setB2(true);
FluentSetterDto actual = m.map(expected);
assertThat(actual).isEqualToComparingFieldByField(expected);
}
@Test
public void shouldComplainAboutEnabledFluentSetters() {
Mapper<FluentSetterDto, FluentSetterDto> mapper = Mapping.from(FluentSetterDto.class)
.to(FluentSetterDto.class)
.allowFluentSetters()
.mapper();
Assertions.assertThatThrownBy(() -> {
AssertMapping.of(mapper)
.ensure();
})
.isInstanceOf(AssertionError.class)
.hasMessageContaining(
"The mapper was expected to only support Java Bean compliant setter methods, but the current mapper is configured to also support fluent setter methods.");
}
@Test
public void shouldComplainAboutDisabledFluentSetters() {
Mapper<FluentSetterDto, FluentSetterDto> mapper = Mapping.from(FluentSetterDto.class)
.to(FluentSetterDto.class)
.omitOthers()
.mapper();
Assertions.assertThatThrownBy(() -> {
AssertMapping.of(mapper)
.expectOthersToBeOmitted()
.expectFluentSettersAllowed()
.ensure();
})
.isInstanceOf(AssertionError.class)
.hasMessageContaining(
"The mapper was expected to support fluent setter methods, but the current mapper is configured to only handle Java Bean compliant setter methods.");
}
@Test
public void shouldTestTheMapperWithoutErrors() {
Mapper<FluentSetterDto, FluentSetterDto> mapper = Mapping.from(FluentSetterDto.class)
.to(FluentSetterDto.class)
.omitOthers()
.mapper();
AssertMapping.of(mapper)
.expectOthersToBeOmitted()
.ensure();
}
@Test(expected = MappingException.class)
public void shouldComplainAboutUnmappedProperties_dueToFluentSettersDisabled() {
Mapping.from(FluentSetterDto.class)
.to(FluentSetterDto.class)
.mapper();
}
@Test
public void shouldNotComplainAboutMissingMappings_ifFluentSettersEnabled() {
Mapping.from(FluentSetterDto.class)
.to(FluentSetterDto.class)
.allowFluentSetters()
.mapper();
}
@Test
public void fluentSettersShouldBeDisabledByDefault_backwardsCompatibility() {
MappingConfiguration<FluentSetterDto, FluentSetterDto> mappingConfiguration = Mapping.from(FluentSetterDto.class)
.to(FluentSetterDto.class);
assertFalse(mappingConfiguration.isFluentSettersAllowed());
}
}