Skip to content

Commit 25afd1d

Browse files
committed
Quality: add unit test
A call in a superclass constructor to a private method ("baz") does not run a (public) subclass method with the same signature but the method in the superclass.
1 parent 54c0618 commit 25afd1d

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

tests/net.sf.j2s.test.junit/src/net/sf/j2s/test/junit/basic/AllBasicTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class AllBasicTests extends TestCase {
1919

2020
public static Test suite() {
21-
TestSuite suite = new TestSuite("Kernel");
21+
TestSuite suite = new TestSuite("All Basic Tests");
2222

2323
suite.addTestSuite(FieldInitTest.class);
2424
suite.addTestSuite(OverloadTest.class);

tests/net.sf.j2s.test.junit/src/net/sf/j2s/test/junit/basic/OverloadTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testOverloadedConstructorBoolean() {
8282

8383
new C(true);
8484

85-
assertEquals("C(true)\n", Output.text());
85+
assertEquals("C(true)\nC.baz()\n", Output.text());
8686
}
8787

8888

tests/net.sf.j2s.test.junit/src/net/sf/j2s/test/junit/basic/SubclassTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ public void testSuperClassConstructorCallsOverridingMethod() {
2727
new C1();
2828
assertEquals("C()\nC1.foo()\nC.bar()\nC1()\n", Output.text());
2929
}
30+
31+
/**
32+
* A call in a superclass constructor to a private method ("baz") does
33+
* not run a (public) subclass method with the same signature but the
34+
* method in the superclass.
35+
*
36+
*/
37+
public void testSuperClassConstructorCallsPrivatePseudoOverriddenMethod() {
38+
Output.clear();
39+
40+
new C1(true);
41+
assertEquals("C(true)\nC.baz()\nC1(true)\nC1.baz()\n", Output.text());
42+
}
3043
}
3144

3245

tests/net.sf.j2s.test.junit/src/net/sf/j2s/test/junit/sample/C.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public C(double n) {
4343

4444
public C(boolean b) {
4545
Output.add("C("+b+")\n");
46+
baz();
4647
}
4748

4849
public void foo() {
@@ -52,4 +53,8 @@ public void foo() {
5253
public void bar() {
5354
Output.add("C.bar()\n");
5455
}
56+
57+
private void baz() {
58+
Output.add("C.baz()\n");
59+
}
5560
}

tests/net.sf.j2s.test.junit/src/net/sf/j2s/test/junit/sample/C1.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ public C1() {
1919
Output.add("C1()\n");
2020
}
2121

22+
public C1(boolean b) {
23+
super(b);
24+
Output.add("C1("+b+")\n");
25+
baz();
26+
}
27+
2228
public void foo() {
2329
Output.add("C1.foo()\n");
2430
}
2531

32+
public void baz() {
33+
Output.add("C1.baz()\n");
34+
}
35+
2636
}

0 commit comments

Comments
 (0)