### Question:
Environment { public static void throwExceptionIfRxJava2IsNotAvailable(@NonNull String messagePrefix) { if (RX_JAVA_2_IS_IN_THE_CLASS_PATH == false) { throw new IllegalStateException(messagePrefix + " requires RxJava2 in classpath, please add it as compile dependency to the application"); } } private  Environment(); static void throwExceptionIfRxJava2IsNotAvailable(@NonNull String messagePrefix); static final boolean RX_JAVA_2_IS_IN_THE_CLASS_PATH; }### Answer:
@Test public void shouldThrowExceptionIfRxJavaIsNotInTheClassPath() throws NoSuchFieldException, IllegalAccessException { Field field = Environment.class.getDeclaredField("RX_JAVA_2_IS_IN_THE_CLASS_PATH"); field.setAccessible(true); Field modifiersFieldOfTheField = Field.class.getDeclaredField("modifiers"); modifiersFieldOfTheField.setAccessible(true); modifiersFieldOfTheField.setInt(field, field.getModifiers() & ~FINAL); final Object prevValue = field.get(null); field.set(null, false); try { Environment.throwExceptionIfRxJava2IsNotAvailable("yolo"); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException expected) { assertThat(expected).hasMessage("yolo requires RxJava2 in classpath," + " please add it as compile dependency to the application"); } finally { field.set(null, prevValue); modifiersFieldOfTheField.setInt(field, field.getModifiers() & FINAL); } }
@Test public void shouldNotThrowExceptionIfRxJavaIsInTheClassPath() { Environment.throwExceptionIfRxJava2IsNotAvailable("no exceptions please"); }