Skip to content

Commit 1c1ab86

Browse files
author
Andrew Lee
committed
Merge branch 'master' of ssh://github.com/java2script/java2script
2 parents 7cc560d + 25afd1d commit 1c1ab86

File tree

12 files changed

+487
-0
lines changed

12 files changed

+487
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.basic;
13+
14+
import junit.framework.Test;
15+
import junit.framework.TestCase;
16+
import junit.framework.TestSuite;
17+
18+
public class AllBasicTests extends TestCase {
19+
20+
public static Test suite() {
21+
TestSuite suite = new TestSuite("All Basic Tests");
22+
23+
suite.addTestSuite(FieldInitTest.class);
24+
suite.addTestSuite(OverloadTest.class);
25+
suite.addTestSuite(SubclassTest.class);
26+
suite.addTestSuite(ThisTest.class);
27+
28+
return suite;
29+
}
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.basic;
13+
14+
import junit.framework.TestCase;
15+
import net.sf.j2s.test.junit.sample.CF;
16+
import net.sf.j2s.test.junit.sample.CF1;
17+
import net.sf.j2s.test.junit.util.Output;
18+
19+
public class FieldInitTest extends TestCase {
20+
21+
/**
22+
* The field is initialized before the constructor is called.
23+
*/
24+
public void testFieldFirst() {
25+
Output.clear();
26+
27+
new CF();
28+
29+
assertEquals("F(\"CF.f\")\nCF()\n", Output.text());
30+
}
31+
32+
/**
33+
* The field and constructor of the superclass are handled before
34+
* the field and constructor of a subclass.
35+
*/
36+
public void testSuperClassFirst() {
37+
Output.clear();
38+
39+
new CF1();
40+
41+
assertEquals("F(\"CF.f\")\nCF()\nF(\"CF1.f\")\nCF1()\n", Output.text());
42+
}
43+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.basic;
13+
14+
import junit.framework.TestCase;
15+
import net.sf.j2s.test.junit.sample.C;
16+
import net.sf.j2s.test.junit.sample.CF;
17+
import net.sf.j2s.test.junit.sample.CF1;
18+
import net.sf.j2s.test.junit.util.Output;
19+
20+
public class OverloadTest extends TestCase {
21+
22+
/**
23+
* The correct constructor is called when overloaded, here "String".
24+
*/
25+
public void testOverloadedConstructorString() {
26+
Output.clear();
27+
28+
new C("A");
29+
30+
assertEquals("C(\"A\")\n", Output.text());
31+
}
32+
33+
/**
34+
* The correct constructor is called when overloaded, here "int".
35+
*/
36+
public void testOverloadedConstructorInt() {
37+
Output.clear();
38+
39+
new C(1);
40+
41+
assertEquals("C(1)\n", Output.text());
42+
}
43+
44+
/**
45+
* The correct constructor is called when overloaded, here "long".
46+
*/
47+
public void testOverloadedConstructorLong() {
48+
Output.clear();
49+
50+
new C(2L);
51+
52+
assertEquals("C((long)2)\n", Output.text());
53+
}
54+
55+
/**
56+
* The correct constructor is called when overloaded, here "float".
57+
*/
58+
public void testOverloadedConstructorFloat() {
59+
Output.clear();
60+
61+
new C(1.2f);
62+
63+
assertEquals("C((float)1.2)\n", Output.text());
64+
}
65+
66+
/**
67+
* The correct constructor is called when overloaded, here "double".
68+
*/
69+
public void testOverloadedConstructorDouble() {
70+
Output.clear();
71+
72+
new C(1.3);
73+
74+
assertEquals("C((double)1.3)\n", Output.text());
75+
}
76+
77+
/**
78+
* The correct constructor is called when overloaded, here "boolean".
79+
*/
80+
public void testOverloadedConstructorBoolean() {
81+
Output.clear();
82+
83+
new C(true);
84+
85+
assertEquals("C(true)\nC.baz()\n", Output.text());
86+
}
87+
88+
89+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.basic;
13+
14+
import junit.framework.TestCase;
15+
import net.sf.j2s.test.junit.sample.C1;
16+
import net.sf.j2s.test.junit.util.Output;
17+
18+
public class SubclassTest extends TestCase {
19+
20+
/**
21+
* A call in a superclass constructor to an overridden method ("foo")
22+
* runs the method in the subclass.
23+
*/
24+
public void testSuperClassConstructorCallsOverridingMethod() {
25+
Output.clear();
26+
27+
new C1();
28+
assertEquals("C()\nC1.foo()\nC.bar()\nC1()\n", Output.text());
29+
}
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+
}
43+
}
44+
45+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.basic;
13+
14+
import junit.framework.TestCase;
15+
import net.sf.j2s.test.junit.sample.C;
16+
import net.sf.j2s.test.junit.sample.C2;
17+
import net.sf.j2s.test.junit.sample.CF;
18+
import net.sf.j2s.test.junit.sample.CF1;
19+
import net.sf.j2s.test.junit.util.Output;
20+
21+
public class ThisTest extends TestCase {
22+
23+
/**
24+
* The correct overload is called when using "this(...)" in a constructor, here "float".
25+
*/
26+
public void testThisCallWithFloat() {
27+
Output.clear();
28+
29+
new C2(); // calls "this(1.3f)"
30+
31+
assertEquals("C()\nC.foo()\nC.bar()\nC2((float)1.3)\nC2()-end\n", Output.text());
32+
}
33+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.sample;
13+
14+
import net.sf.j2s.test.junit.util.Output;
15+
16+
public class C {
17+
18+
public C() {
19+
Output.add("C()\n");
20+
foo();
21+
bar();
22+
}
23+
24+
public C(String string) {
25+
Output.add("C(\""+string+"\")\n");
26+
}
27+
28+
public C(int n) {
29+
Output.add("C("+n+")\n");
30+
}
31+
32+
public C(long n) {
33+
Output.add("C((long)"+n+")\n");
34+
}
35+
36+
public C(float n) {
37+
Output.add("C((float)"+n+")\n");
38+
}
39+
40+
public C(double n) {
41+
Output.add("C((double)"+n+")\n");
42+
}
43+
44+
public C(boolean b) {
45+
Output.add("C("+b+")\n");
46+
baz();
47+
}
48+
49+
public void foo() {
50+
Output.add("C.foo()\n");
51+
}
52+
53+
public void bar() {
54+
Output.add("C.bar()\n");
55+
}
56+
57+
private void baz() {
58+
Output.add("C.baz()\n");
59+
}
60+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.sample;
13+
14+
import net.sf.j2s.test.junit.util.Output;
15+
16+
public class C1 extends C {
17+
18+
public C1() {
19+
Output.add("C1()\n");
20+
}
21+
22+
public C1(boolean b) {
23+
super(b);
24+
Output.add("C1("+b+")\n");
25+
baz();
26+
}
27+
28+
public void foo() {
29+
Output.add("C1.foo()\n");
30+
}
31+
32+
public void baz() {
33+
Output.add("C1.baz()\n");
34+
}
35+
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Udo Borkowski - initial implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.test.junit.sample;
13+
14+
import net.sf.j2s.test.junit.util.Output;
15+
16+
public class C2 extends C {
17+
18+
public C2() {
19+
this(1.3f);
20+
Output.add("C2()-end\n");
21+
}
22+
23+
public C2(float n) {
24+
Output.add("C2((float)"+n+")\n");
25+
}
26+
27+
public C2(double n) {
28+
Output.add("C2((double)"+n+")\n");
29+
}
30+
31+
32+
}

0 commit comments

Comments
 (0)