Skip to content

Commit cef1a4d

Browse files
authored
Merge pull request #9 from BobHanson/master
update of jadav1
2 parents a8c7d60 + 645d256 commit cef1a4d

File tree

8 files changed

+250
-0
lines changed

8 files changed

+250
-0
lines changed
2.26 MB
Binary file not shown.
2.26 MB
Binary file not shown.
2.26 MB
Binary file not shown.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static Test suite() {
2424
suite.addTestSuite(OverloadTest.class);
2525
suite.addTestSuite(SubclassTest.class);
2626
suite.addTestSuite(ThisTest.class);
27+
suite.addTestSuite(VarArgsTest.class);
2728

2829
return suite;
2930
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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.sample.CVarArgs;
20+
import net.sf.j2s.test.junit.util.Output;
21+
22+
public class VarArgsTest extends TestCase {
23+
24+
/**
25+
* Call a varArgs method with not arguments.
26+
*/
27+
public void testVarArgsEmpty() {
28+
String s = new CVarArgs().fVarArgsInt();
29+
assertEquals("ints: ", s);
30+
}
31+
32+
/**
33+
* Call a varArgs method with exactly one argument.
34+
*/
35+
public void testVarArgsExactlyOneArg() {
36+
String s = new CVarArgs().fVarArgsInt(4);
37+
assertEquals("ints: 4 ", s);
38+
}
39+
40+
/**
41+
* Call a varArgs method with some arguments.
42+
*/
43+
public void testVarArgsNotEmpty() {
44+
String s = new CVarArgs().fVarArgsInt(4,7,9);
45+
assertEquals("ints: 4 7 9 ", s);
46+
}
47+
48+
/**
49+
* Call a varArgs method with some "float" arguments, to check if
50+
* the correct overload ("float ..." vs. "int ...") is selected.
51+
*/
52+
public void testVarArgsNotEmpty_WithFloat() {
53+
String s = new CVarArgs().fVarArgsInt(4.0f,7,9);
54+
assertEquals("floats: 4.0 7.0 9.0 ", s);
55+
}
56+
57+
/**
58+
* Call a varArgs method with some arguments (via array).
59+
*/
60+
public void testVarArgsNotEmptyViaArray() {
61+
int[] args = new int[]{4,7,9};
62+
String s = new CVarArgs().fVarArgsInt(args);
63+
assertEquals("ints: 4 7 9 ", s);
64+
}
65+
66+
/**
67+
* Call a varArgs method with a mandatory arguments and no optional arguments.
68+
*/
69+
public void testStringPlusVarArgsEmpty() {
70+
String s = new CVarArgs().fStringVarArgsInt("demo ");
71+
assertEquals("demo ", s);
72+
}
73+
74+
/**
75+
* Call a varArgs method with a mandatory arguments and exactly one optional arguments.
76+
*/
77+
public void testStringPlusVarArgsExactlyOneArg() {
78+
String s = new CVarArgs().fStringVarArgsInt("demo ", 4);
79+
assertEquals("demo 4 ", s);
80+
}
81+
82+
/**
83+
* Call a varArgs method with a mandatory arguments and some optional arguments.
84+
*/
85+
public void testStringPlusVarArgsNotEmpty() {
86+
String s = new CVarArgs().fStringVarArgsInt("demo ", 4, 7);
87+
assertEquals("demo 4 7 ", s);
88+
}
89+
90+
/**
91+
* Call a varArgs method of array type (here int[]) with not arguments.
92+
*/
93+
public void testIntArrVarArgsEmpty() {
94+
String s = new CVarArgs().fIntArr();
95+
assertEquals("intss ", s);
96+
}
97+
98+
/**
99+
* Call a varArgs method of array type (here int[]) with some arguments.
100+
*/
101+
public void testIntArrVarArgsNotEmpty() {
102+
String s = new CVarArgs().fIntArr(new int[]{3,5,7}, new int[]{2,4});
103+
assertEquals("intss [3 5 7 ] [2 4 ] ", s);
104+
}
105+
106+
/**
107+
* Call a varArgs method of array type (here int[]) with exactly one argument.
108+
*/
109+
public void testIntArrVarArgsExactlyOneArg() {
110+
String s = new CVarArgs().fIntArr(new int[]{2,4});
111+
assertEquals("intss [2 4 ] ", s);
112+
}
113+
114+
/**
115+
* Call a varArgs method of array type (here int[]) with some arguments (via array).
116+
*/
117+
public void testIntArrVarArgsNotEmptyViaArray() {
118+
int[][] args = new int[][]{new int[]{3,5,7}, new int[]{2,4}};
119+
String s = new CVarArgs().fIntArr(args );
120+
assertEquals("intss [3 5 7 ] [2 4 ] ", s);
121+
}
122+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.issue;
13+
14+
import junit.framework.TestCase;
15+
16+
public class Issue18Test extends TestCase {
17+
18+
/**
19+
* Boolean.FALSE must evaluate to <code>false</code> when used in a boolean expression,
20+
* e.g. as a literal in a ternary operation's condition.
21+
*/
22+
public void testFALSEInInTernaryCondition() {
23+
assertEquals("OK", Boolean.FALSE ? "FAILED" : "OK");
24+
}
25+
26+
/**
27+
* Boolean.FALSE must evaluate to <code>false</code> when used in a boolean expression,
28+
* e.g. as the value of a variable in a ternary operation's condition.
29+
*/
30+
public void testFALSEInInTernaryConditionViaVariable() {
31+
Boolean b = Boolean.FALSE;
32+
assertEquals("OK", b ? "FAILED" : "OK");
33+
}
34+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.java.lang;
13+
14+
import junit.framework.TestCase;
15+
16+
public class BooleanTest extends TestCase {
17+
18+
/**
19+
* Boolean.FALSE must evaluate to <code>false</code> when used in a boolean expression.
20+
*/
21+
public void testFALSEInInBooleanExpression() {
22+
assertFalse(Boolean.FALSE);
23+
}
24+
25+
/**
26+
* Boolean.FALSE must evaluate to <code>false</code> when used in a boolean expression,
27+
* e.g. as a literal in an if-statement's condition.
28+
*/
29+
public void testFALSEInIfCondition() {
30+
if (Boolean.FALSE) {
31+
fail("Boolean.FALSE does not evaluate to false");
32+
}
33+
}
34+
35+
/**
36+
* Boolean.TRUE must evaluate to <code>true</code> when used in a boolean expression,
37+
* e.g. as a literal in an if-statement's condition.
38+
*/
39+
public void testTRUEInIfCondition() {
40+
if (Boolean.TRUE) {
41+
// do nothing
42+
} else {
43+
fail("Boolean.TRUE does not evaluate to true");
44+
}
45+
}
46+
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package net.sf.j2s.test.junit.sample;
2+
3+
public class CVarArgs {
4+
public String fVarArgsInt(int... ns) {
5+
String result = "ints: ";
6+
for (int i = 0; i < ns.length; i++) {
7+
result += ns[i] + " ";
8+
}
9+
return result;
10+
}
11+
12+
/**
13+
* Attention: DON'T change the "misleading" method name (e.g. to "<code>fVarArgsFloat</code>").
14+
*
15+
* <p> This method is used to check for ambiguity resolution of methods with same name and
16+
* different var args types (<code>int...</code> vs <code>float...</code>)
17+
*/
18+
public String fVarArgsInt(float... ns) {
19+
String result = "floats: ";
20+
for (int i = 0; i < ns.length; i++) {
21+
result += ns[i] + " ";
22+
}
23+
return result;
24+
}
25+
26+
public String fStringVarArgsInt(String s, int... ns) {
27+
String result = s;
28+
for (int i = 0; i < ns.length; i++) {
29+
result += ns[i] + " ";
30+
}
31+
return result;
32+
}
33+
34+
public String fIntArr(int[]... nss) {
35+
String result = "intss ";
36+
for (int j = 0; j < nss.length; j++) {
37+
int[] ns = nss[j];
38+
result += "[";
39+
for (int i = 0; i < ns.length; i++) {
40+
result += ns[i] + " ";
41+
}
42+
result += "] ";
43+
}
44+
return result;
45+
}
46+
}

0 commit comments

Comments
 (0)