Skip to content

Commit a816054

Browse files
authored
Add failing tests (#327)
Two new failing test due to a lack of automated `toString` in string concat bootstrap method.
1 parent 3feff22 commit a816054

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/tests/java11/StringConcatenationTest.java

+62
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,66 @@ public void testStringConcatenationWith_mixedTypes() {
132132
assertEquals(expected, actual);
133133
}
134134
}
135+
136+
@Test
137+
public void testStringConcatenationWith_toString() {
138+
if (verifyNoPropertyViolation()) {
139+
String begin = "Greetings, ";
140+
Person john = new Person("John");
141+
String actual = begin + john;
142+
String expected = "Greetings, John";
143+
assertEquals(expected, actual);
144+
}
145+
}
146+
147+
@Test
148+
public void testStringConcatenationWith_toStringNested() {
149+
if (verifyNoPropertyViolation()) {
150+
String begin = "Greetings, ";
151+
Person harold = createRobot("Harold");
152+
String actual = begin + harold;
153+
String expected = "Greetings, [Robot] Harold";
154+
assertEquals(expected, actual);
155+
}
156+
}
157+
158+
private Person createRobot(String name) {
159+
return new Robot(name);
160+
}
161+
162+
private class Person {
163+
private String name;
164+
165+
private Person(String name) {
166+
this.name = name;
167+
}
168+
169+
public String getType() {
170+
return "human";
171+
}
172+
173+
@Override
174+
public String toString() {
175+
return name;
176+
}
177+
}
178+
179+
private class Robot extends Person {
180+
private String name;
181+
182+
private Robot(String name) {
183+
super(name);
184+
this.name = name;
185+
}
186+
187+
@Override
188+
public String getType() {
189+
return "robot";
190+
}
191+
192+
@Override
193+
public String toString() {
194+
return "[Robot] " + name;
195+
}
196+
}
135197
}

0 commit comments

Comments
 (0)