@Test public void testArityForOption_listFieldImplicitArity1() throws Exception { class ImplicitList { @Option(names = "-a") List<Integer> listIntegers; } Range arity = Range.optionArity(ImplicitList.class.getDeclaredField("listIntegers")); assertEquals(Range.valueOf("1"), arity); assertEquals("1", arity.toString()); } @Test
@Test public void testArityForOption_isExplicitlyDeclaredValue() throws Exception { class Params { @Option(names = "-timeUnitList", type = TimeUnit.class, arity = "3") List<TimeUnit> timeUnitList; } Range arity = Range.optionArity(Params.class.getDeclaredField("timeUnitList")); assertEquals(Range.valueOf("3"), arity); assertEquals("3", arity.toString()); } @Test
@Test public void testArityForOption_booleanFieldImplicitArity0() throws Exception { Range arity = Range.optionArity(SupportedTypes2.class.getDeclaredField("booleanField")); assertEquals(Range.valueOf("0"), arity); assertEquals("0", arity.toString()); } @Test
@Test public void testArityForOption_intFieldImplicitArity1() throws Exception { Range arity = Range.optionArity(SupportedTypes2.class.getDeclaredField("intField")); assertEquals(Range.valueOf("1"), arity); assertEquals("1", arity.toString()); } @Test
/** Returns a new {@code Range} based on the {@link Option#arity()} annotation on the specified field, * or the field type's default arity if no arity was specified. * @param field the field whose Option annotation to inspect * @return a new {@code Range} based on the Option arity annotation on the specified field */ public static Range optionArity(Field field) { return optionArity(new TypedMember(field)); } private static Range optionArity(TypedMember member) {
@Test public void testOptionArity_forNonAnnotatedField() throws Exception { Range arity = Range.optionArity(SupportedTypes2.class.getDeclaredField("nonOptionField")); assertEquals(0, arity.max); assertEquals(0, arity.min); assertEquals(false, arity.isVariable); assertEquals("0", arity.toString()); } @Test
@Test public void testArityForOption_listFieldImplicitArity1() throws Exception { class ImplicitList { @Option(names = "-a") List<Integer> listIntegers; } Range arity = Range.optionArity(ImplicitList.class.getDeclaredField("listIntegers")); assertEquals(Range.valueOf("1"), arity); assertEquals("1", arity.toString()); } @Test
@Test public void testArityForOption_arrayFieldImplicitArity1() throws Exception { class ImplicitList { @Option(names = "-a") int[] intArray; } Range arity = Range.optionArity(ImplicitList.class.getDeclaredField("intArray")); assertEquals(Range.valueOf("1"), arity); assertEquals("1", arity.toString()); }
@Test public void testArityForOption_isExplicitlyDeclaredValue() throws Exception { class Params { @Option(names = "-timeUnitList", type = TimeUnit.class, arity = "3") List<TimeUnit> timeUnitList; } Range arity = Range.optionArity(Params.class.getDeclaredField("timeUnitList")); assertEquals(Range.valueOf("3"), arity); assertEquals("3", arity.toString()); } @Test
@Test public void testArityForOption_booleanFieldImplicitArity0() throws Exception { Range arity = Range.optionArity(SupportedTypes2.class.getDeclaredField("booleanField")); assertEquals(Range.valueOf("0"), arity); assertEquals("0", arity.toString()); } @Test
@Test public void testArityForOption_arrayFieldImplicitArity1() throws Exception { class ImplicitList { @Option(names = "-a") int[] intArray; } Range arity = Range.optionArity(ImplicitList.class.getDeclaredField("intArray")); assertEquals(Range.valueOf("1"), arity); assertEquals("1", arity.toString()); }
@Test public void testArityForOption_intFieldImplicitArity1() throws Exception { Range arity = Range.optionArity(SupportedTypes2.class.getDeclaredField("intField")); assertEquals(Range.valueOf("1"), arity); assertEquals("1", arity.toString()); } @Test
@Test public void testOptionArity_forNonAnnotatedField() throws Exception { Range arity = Range.optionArity(SupportedTypes2.class.getDeclaredField("nonOptionField")); assertEquals(0, arity.max); assertEquals(0, arity.min); assertEquals(false, arity.isVariable); assertEquals("0", arity.toString()); } @Test
/** Returns a new {@code Range} based on the {@link Option#arity()} annotation on the specified field, * or the field type's default arity if no arity was specified. * @param field the field whose Option annotation to inspect * @return a new {@code Range} based on the Option arity annotation on the specified field */ public static Range optionArity(Field field) { return optionArity(new TypedMember(field)); } private static Range optionArity(IAnnotatedElement member) {