001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.cli2; 018 019import java.util.Arrays; 020import java.util.Collection; 021import java.util.Collections; 022import java.util.Iterator; 023import java.util.LinkedList; 024import java.util.List; 025 026import junit.framework.TestCase; 027 028public abstract class CLITestCase extends TestCase { 029 030 public static List list() { 031 return Collections.EMPTY_LIST; 032 } 033 034 public static List list(final Object args[]) { 035 return new LinkedList(Arrays.asList(args)); 036 } 037 038 public static List list(final Object arg0) { 039 return list(new Object[] { arg0 }); 040 } 041 042 public static List list(final Object arg0, final Object arg1) { 043 return list(new Object[] { arg0, arg1 }); 044 } 045 046 public static List list(final Object arg0, final Object arg1, final Object arg2) { 047 return list(new Object[] { arg0, arg1, arg2 }); 048 } 049 050 public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3) { 051 return list(new Object[] { arg0, arg1, arg2, arg3 }); 052 } 053 054 public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4) { 055 return list(new Object[] { arg0, arg1, arg2, arg3, arg4 }); 056 } 057 058 public static List list(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5) { 059 return list(new Object[] { arg0, arg1, arg2, arg3, arg4, arg5 }); 060 } 061 062 public static void assertListContentsEqual(final List expected, final List found) { 063 064 final Iterator e = expected.iterator(); 065 final Iterator f = found.iterator(); 066 067 while (e.hasNext() && f.hasNext()) { 068 assertEquals(e.next(), f.next()); 069 } 070 071 if (e.hasNext()) { 072 fail("Expected more elements"); 073 } 074 075 if (f.hasNext()) { 076 fail("Found more elements"); 077 } 078 } 079 080 public static void assertContentsEqual(final Collection expected, final Collection found) { 081 assertTrue(expected.containsAll(found)); 082 assertTrue(found.containsAll(expected)); 083 assertEquals(expected.size(), found.size()); 084 } 085}