View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.cli2;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  import java.util.Collections;
22  import java.util.Iterator;
23  import java.util.LinkedList;
24  import java.util.List;
25  
26  import junit.framework.TestCase;
27  
28  public abstract class CLITestCase extends TestCase {
29  
30  	public static List list() {
31  	    return Collections.EMPTY_LIST;
32  	}
33  
34  	public static List list(final Object args[]) {
35  	    return new LinkedList(Arrays.asList(args));
36  	}
37  
38  	public static List list(final Object arg0) {
39  	    return list(new Object[] { arg0 });
40  	}
41  
42  	public static List list(final Object arg0, final Object arg1) {
43  	    return list(new Object[] { arg0, arg1 });
44  	}
45  
46  	public static List list(final Object arg0, final Object arg1, final Object arg2) {
47  	    return list(new Object[] { arg0, arg1, arg2 });
48  	}
49  
50  	public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3) {
51  	    return list(new Object[] { arg0, arg1, arg2, arg3 });
52  	}
53  
54  	public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4) {
55  	    return list(new Object[] { arg0, arg1, arg2, arg3, arg4 });
56  	}
57  
58  	public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5) {
59  	    return list(new Object[] { arg0, arg1, arg2, arg3, arg4, arg5 });
60  	}
61  
62  	public static void assertListContentsEqual(final List expected, final List found) {
63  
64  	    final Iterator e = expected.iterator();
65  	    final Iterator f = found.iterator();
66  
67  	    while (e.hasNext() && f.hasNext()) {
68  	        assertEquals(e.next(), f.next());
69  	    }
70  
71  	    if (e.hasNext()) {
72  	        fail("Expected more elements");
73  	    }
74  
75  	    if (f.hasNext()) {
76  	        fail("Found more elements");
77  	    }
78  	}
79  
80  	public static void assertContentsEqual(final Collection expected, final Collection found) {
81  	    assertTrue(expected.containsAll(found));
82  	    assertTrue(found.containsAll(expected));
83  	    assertEquals(expected.size(), found.size());
84  	}
85  }