### Question:
ReflectionHelper { public static void set(Object mediator, Field field, Object source) { if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(mediator, source); } catch (IllegalAccessException e) { throw new IllegalStateException("Unable to set field " + field.getName() + " from " + mediator.getClass().getName() + " to " + source, e); } } private  ReflectionHelper(); static void set(Object mediator, Field field, Object source); static void invokeFunction(Object mediator, Method method); static void invokeTransformationMethod(Object mediator, Method method); static Object getSourceToInject(Class<?> clazz, Type type, Source<Object> source); static void inject(Object mediator);  }### Answer:
@Test public void testValidSet() throws NoSuchFieldException { Test1 test = new Test1(); Field field = Test1.class.getDeclaredField("foo"); ReflectionHelper.set(test, field, "hello"); assertThat(test.foo).isEqualTo("hello"); }
@Test(expected = IllegalArgumentException.class) public void testInvalidSet() throws NoSuchFieldException { Test1 test = new Test1(); Field field = Test1.class.getDeclaredField("foo"); ReflectionHelper.set(test, field, 10); }