@Test void inject_failed() { SimpleType simpleType = new SimpleType(); Throwable fakegenException = catchThrowable(() -> FakegenUtils.inject(simpleType, "namo", "Hello World")); assertThat(fakegenException) .isInstanceOf(FakegenException.class) .hasMessage("Could not find field `namo`, but a similar named one called `name` was found."); }
public static void inject(@NonNull Object target, @NonNull String fieldName, Object value) { Field field; try { field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(target, value); } catch (NoSuchFieldException e) { throw new FakegenException(createExceptionMessage(target.getClass(), fieldName), e); } catch (IllegalAccessException e) { throw new FakegenException("Could not set field " + fieldName, e); } }
FakegenUtils { public static void inject(@NonNull Object target, @NonNull String fieldName, Object value) { Field field; try { field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(target, value); } catch (NoSuchFieldException e) { throw new FakegenException(createExceptionMessage(target.getClass(), fieldName), e); } catch (IllegalAccessException e) { throw new FakegenException("Could not set field " + fieldName, e); } } }
FakegenUtils { public static void inject(@NonNull Object target, @NonNull String fieldName, Object value) { Field field; try { field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(target, value); } catch (NoSuchFieldException e) { throw new FakegenException(createExceptionMessage(target.getClass(), fieldName), e); } catch (IllegalAccessException e) { throw new FakegenException("Could not set field " + fieldName, e); } }  }
FakegenUtils { public static void inject(@NonNull Object target, @NonNull String fieldName, Object value) { Field field; try { field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(target, value); } catch (NoSuchFieldException e) { throw new FakegenException(createExceptionMessage(target.getClass(), fieldName), e); } catch (IllegalAccessException e) { throw new FakegenException("Could not set field " + fieldName, e); } }  static void inject(@NonNull Object target, @NonNull String fieldName, Object value); @SafeVarargs static void modifyCollection(@NonNull Iterable<T> targets, @NonNull Consumer<T>... suppliers); }
FakegenUtils { public static void inject(@NonNull Object target, @NonNull String fieldName, Object value) { Field field; try { field = target.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(target, value); } catch (NoSuchFieldException e) { throw new FakegenException(createExceptionMessage(target.getClass(), fieldName), e); } catch (IllegalAccessException e) { throw new FakegenException("Could not set field " + fieldName, e); } }  static void inject(@NonNull Object target, @NonNull String fieldName, Object value); @SafeVarargs static void modifyCollection(@NonNull Iterable<T> targets, @NonNull Consumer<T>... suppliers);  }