X Tutup
Skip to content

Commit ca15164

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

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 arguments (via array).
50+
*/
51+
public void testVarArgsNotEmptyViaArray() {
52+
int[] args = new int[]{4,7,9};
53+
String s = new CVarArgs().fVarArgsInt(args);
54+
assertEquals("ints: 4 7 9 ", s);
55+
}
56+
57+
/**
58+
* Call a varArgs method with a mandatory arguments and no optional arguments.
59+
*/
60+
public void testStringPlusVarArgsEmpty() {
61+
String s = new CVarArgs().fStringVarArgsInt("demo ");
62+
assertEquals("demo ", s);
63+
}
64+
65+
/**
66+
* Call a varArgs method with a mandatory arguments and exactly one optional arguments.
67+
*/
68+
public void testStringPlusVarArgsExactlyOneArg() {
69+
String s = new CVarArgs().fStringVarArgsInt("demo ", 4);
70+
assertEquals("demo 4 ", s);
71+
}
72+
73+
/**
74+
* Call a varArgs method with a mandatory arguments and some optional arguments.
75+
*/
76+
public void testStringPlusVarArgsNotEmpty() {
77+
String s = new CVarArgs().fStringVarArgsInt("demo ", 4, 7);
78+
assertEquals("demo 4 7 ", s);
79+
}
80+
81+
/**
82+
* Call a varArgs method of array type (here int[]) with not arguments.
83+
*/
84+
public void testIntArrVarArgsEmpty() {
85+
String s = new CVarArgs().fIntArr();
86+
assertEquals("intss ", s);
87+
}
88+
89+
/**
90+
* Call a varArgs method of array type (here int[]) with some arguments.
91+
*/
92+
public void testIntArrVarArgsNotEmpty() {
93+
String s = new CVarArgs().fIntArr(new int[]{3,5,7}, new int[]{2,4});
94+
assertEquals("intss [3 5 7 ] [2 4 ] ", s);
95+
}
96+
97+
/**
98+
* Call a varArgs method of array type (here int[]) with exactly one argument.
99+
*/
100+
public void testIntArrVarArgsExactlyOneArg() {
101+
String s = new CVarArgs().fIntArr(new int[]{2,4});
102+
assertEquals("intss [2 4 ] ", s);
103+
}
104+
105+
/**
106+
* Call a varArgs method of array type (here int[]) with some arguments (via array).
107+
*/
108+
public void testIntArrVarArgsNotEmptyViaArray() {
109+
int[][] args = new int[][]{new int[]{3,5,7}, new int[]{2,4}};
110+
String s = new CVarArgs().fIntArr(args );
111+
assertEquals("intss [3 5 7 ] [2 4 ] ", s);
112+
}
113+
}
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
public String fStringVarArgsInt(String s, int... ns) {
13+
String result = s;
14+
for (int i = 0; i < ns.length; i++) {
15+
result += ns[i] + " ";
16+
}
17+
return result;
18+
}
19+
20+
public String fIntArr(int[]... nss) {
21+
String result = "intss ";
22+
for (int j = 0; j < nss.length; j++) {
23+
int[] ns = nss[j];
24+
result += "[";
25+
for (int i = 0; i < ns.length; i++) {
26+
result += ns[i] + " ";
27+
}
28+
result += "] ";
29+
}
30+
return result;
31+
}
32+
}

0 commit comments

Comments
 (0)
X Tutup