@@ -84,4 +84,89 @@ public void testCopyConstructorWithModifications() {
84
84
assertEquals (150 , original .getValue ());
85
85
assertEquals (300 , copy .getValue ());
86
86
}
87
+
88
+ /** Test getModifications method. */
89
+ @ Test
90
+ public void testGetModifications () {
91
+ ModifiableInteger integer = new ModifiableInteger ();
92
+ integer .setOriginalValue (100 );
93
+
94
+ // Initially no modifications
95
+ assertNull (integer .getModifications ());
96
+
97
+ // Add modifications
98
+ IntegerAddModification addMod = new IntegerAddModification (50 );
99
+ IntegerMultiplyModification multiplyMod = new IntegerMultiplyModification (2 );
100
+ integer .addModification (addMod );
101
+ integer .addModification (multiplyMod );
102
+
103
+ // Get modifications
104
+ List <VariableModification <Integer >> mods = integer .getModifications ();
105
+ assertNotNull (mods );
106
+ assertEquals (2 , mods .size ());
107
+ assertEquals (addMod , mods .get (0 ));
108
+ assertEquals (multiplyMod , mods .get (1 ));
109
+
110
+ // Clear modifications
111
+ integer .clearModifications ();
112
+ assertNull (integer .getModifications ());
113
+ }
114
+
115
+ /** Test containsAssertion method. */
116
+ @ Test
117
+ public void testContainsAssertion () {
118
+ ModifiableInteger integer = new ModifiableInteger ();
119
+
120
+ // Initially no assertion
121
+ assertFalse (integer .containsAssertion ());
122
+
123
+ // Set assertEquals value
124
+ integer .setAssertEquals (150 );
125
+ assertTrue (integer .containsAssertion ());
126
+
127
+ // Create new instance without assertion
128
+ ModifiableInteger noAssertion = new ModifiableInteger ();
129
+ assertFalse (noAssertion .containsAssertion ());
130
+ }
131
+
132
+ /** Test innerToString method through subclass toString. */
133
+ @ Test
134
+ public void testInnerToString () {
135
+ // Test with no modifications or assertions
136
+ ModifiableInteger integer1 = new ModifiableInteger ();
137
+ integer1 .setOriginalValue (100 );
138
+ String str1 = integer1 .toString ();
139
+ assertTrue (str1 .contains ("originalValue=100" ));
140
+ assertFalse (str1 .contains ("modifications=" ));
141
+ assertFalse (str1 .contains ("assertEquals=" ));
142
+
143
+ // Test with modifications
144
+ ModifiableInteger integer2 = new ModifiableInteger ();
145
+ integer2 .setOriginalValue (100 );
146
+ integer2 .addModification (new IntegerAddModification (50 ));
147
+ integer2 .addModification (new IntegerMultiplyModification (2 ));
148
+ String str2 = integer2 .toString ();
149
+ assertTrue (str2 .contains ("originalValue=100" ));
150
+ assertTrue (str2 .contains ("modifications=[" ));
151
+ assertTrue (str2 .contains ("IntegerAddModification" ));
152
+ assertTrue (str2 .contains ("IntegerMultiplyModification" ));
153
+
154
+ // Test with assertions
155
+ ModifiableInteger integer3 = new ModifiableInteger ();
156
+ integer3 .setOriginalValue (100 );
157
+ integer3 .setAssertEquals (150 );
158
+ String str3 = integer3 .toString ();
159
+ assertTrue (str3 .contains ("originalValue=100" ));
160
+ assertTrue (str3 .contains ("assertEquals=150" ));
161
+
162
+ // Test with both modifications and assertions
163
+ ModifiableInteger integer4 = new ModifiableInteger ();
164
+ integer4 .setOriginalValue (100 );
165
+ integer4 .addModification (new IntegerAddModification (50 ));
166
+ integer4 .setAssertEquals (150 );
167
+ String str4 = integer4 .toString ();
168
+ assertTrue (str4 .contains ("originalValue=100" ));
169
+ assertTrue (str4 .contains ("modifications=[" ));
170
+ assertTrue (str4 .contains ("assertEquals=150" ));
171
+ }
87
172
}
0 commit comments