30
30
import java .util .Map ;
31
31
32
32
@ Category (UnitTests .class )
33
- public class ImmutableCapabilitiesTest {
33
+ public class CapabilitiesTest {
34
34
35
35
@ Test
36
36
public void canCreateEmptyCapabilities () {
@@ -60,14 +60,14 @@ public void canCreateThreePairCapabilities() {
60
60
public void canCreateFourPairCapabilities () {
61
61
Capabilities caps = new ImmutableCapabilities ("c1" , "v1" , "c2" , 2 , "c3" , true , "c4" , "v4" );
62
62
assertThat (caps .asMap ())
63
- .isEqualTo (ImmutableMap .of ("c1" , "v1" , "c2" , 2 , "c3" , true , "c4" , "v4" ));
63
+ .isEqualTo (ImmutableMap .of ("c1" , "v1" , "c2" , 2 , "c3" , true , "c4" , "v4" ));
64
64
}
65
65
66
66
@ Test
67
67
public void canCreateFivePairCapabilities () {
68
68
Capabilities caps = new ImmutableCapabilities ("c1" , "v1" , "c2" , 2 , "c3" , true , "c4" , "v4" , "c5" , "v5" );
69
69
assertThat (caps .asMap ())
70
- .isEqualTo (ImmutableMap .of ("c1" , "v1" , "c2" , 2 , "c3" , true , "c4" , "v4" , "c5" , "v5" ));
70
+ .isEqualTo (ImmutableMap .of ("c1" , "v1" , "c2" , 2 , "c3" , true , "c4" , "v4" , "c5" , "v5" ));
71
71
}
72
72
73
73
@ Test
@@ -88,7 +88,36 @@ public void shouldCheckKeyType() {
88
88
Map <Object , Object > map = new HashMap <>();
89
89
map .put (new Object (), new Object ());
90
90
assertThatExceptionOfType (IllegalArgumentException .class )
91
- .isThrownBy (() -> new ImmutableCapabilities (map ));
91
+ .isThrownBy (() -> new ImmutableCapabilities (map ));
92
92
}
93
93
94
+ @ Test
95
+ public void canMergeImmutableCapabilities () {
96
+ Map <String , Object > map1 = ImmutableMap .of ("c1" , "v1" , "c2" , "v2" );
97
+ Map <String , Object > map2 = ImmutableMap .of ("c1" , "new value" , "c3" , "v3" );
98
+ Capabilities caps1 = new ImmutableCapabilities (map1 );
99
+ Capabilities caps2 = new ImmutableCapabilities (map2 );
100
+ Capabilities merged = caps1 .merge (caps2 );
101
+ assertThat (merged ).isNotSameAs (caps1 ).isNotSameAs (caps2 );
102
+ assertThat (merged .asMap ()).containsExactlyEntriesOf (
103
+ ImmutableMap .of (
104
+ "c1" , "new value" , "c2" , "v2" , "c3" , "v3" ));
105
+ assertThat (caps1 .asMap ()).containsExactlyEntriesOf (map1 );
106
+ assertThat (caps2 .asMap ()).containsExactlyEntriesOf (map2 );
107
+ }
108
+
109
+ @ Test
110
+ public void canMergeMutableCapabilities () {
111
+ Map <String , Object > map1 = ImmutableMap .of ("c1" , "v1" , "c2" , "v2" );
112
+ Map <String , Object > map2 = ImmutableMap .of ("c1" , "new value" , "c3" , "v3" );
113
+ Capabilities caps1 = new MutableCapabilities (map1 );
114
+ Capabilities caps2 = new MutableCapabilities (map2 );
115
+ Capabilities merged = caps1 .merge (caps2 );
116
+ assertThat (merged ).isNotSameAs (caps1 ).isNotSameAs (caps2 );
117
+ assertThat (merged .asMap ()).containsExactlyEntriesOf (
118
+ ImmutableMap .of (
119
+ "c1" , "new value" , "c2" , "v2" , "c3" , "v3" ));
120
+ assertThat (caps1 .asMap ()).containsExactlyEntriesOf (map1 );
121
+ assertThat (caps2 .asMap ()).containsExactlyEntriesOf (map2 );
122
+ }
94
123
}
0 commit comments