### Question:
DeclaredParameter { void setValue(String value) throws IllegalArgumentException, IllegalAccessException { this.stringValue = value; this.handler.setValue(source, field, value); } DeclaredParameter(Parameter param, Object source, Field field);   }### Answer:
@Test public void testTypes() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Random rnd = new Random(); TestSource source = new TestSource(); String[] names = { "testInt", "testDouble", "testBool", "testEnum", "testString" }; Object[] values = { rnd.nextInt(), rnd.nextDouble(), rnd.nextBoolean(), EnumTest.values()[rnd.nextInt(3)], RandomStringUtils.randomAlphanumeric(rnd.nextInt(500)) }; for (int i = 0; i < names.length; i++) { Field f = TestSource.class.getField(names[i]); Parameter a1 = f.getAnnotation(Parameter.class); DeclaredParameter test = new DeclaredParameter(a1, source, f); test.setValue(values[i].toString()); assertEquals(values[i], f.get(source)); assertEquals(names[i], test.name); assertFalse(test.optional); } }
@Test public void testBadParameter() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { TestSource source = new TestSource(); Field f = TestSource.class.getField("testInt"); Parameter a = f.getAnnotation(Parameter.class); DeclaredParameter test = new DeclaredParameter(a, source, f); try { test.setValue("0.5"); fail(); } catch (NumberFormatException e) { } f = TestSource.class.getField("testDouble"); a = f.getAnnotation(Parameter.class); test = new DeclaredParameter(a, source, f); try { test.setValue("hi"); fail(); } catch (NumberFormatException e) { } f = TestSource.class.getField("testBool"); a = f.getAnnotation(Parameter.class); test = new DeclaredParameter(a, source, f); test.setValue("true"); assertEquals(true, f.get(source)); test.setValue("hi"); assertEquals(false, f.get(source)); f = TestSource.class.getField("testEnum"); a = f.getAnnotation(Parameter.class); test = new DeclaredParameter(a, source, f); try { test.setValue("1"); fail(); } catch (IllegalArgumentException e) { } }