|
| 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 | +} |
0 commit comments