### Question:
EmbeddedOpenDJManager { public State upgrade() throws ServletException { if (state.equals(State.NO_EMBEDDED_INSTANCE)) { throw new IllegalStateException("Cannot upgrade embedded instance as no embedded instance has " + "been configured"); } if (!state.equals(State.UPGRADE_REQUIRED)) { throw new IllegalStateException("Embedded instance does not require upgrading"); } try { upgrader.upgrade(); state = State.UPGRADED; return state; } catch (Exception e) { logger.error("Failed to upgrade OpenDJ", e); throw new ServletException("An error occurred while upgrading the embedded OpenDJ instance", e); } } EmbeddedOpenDJManager(Debug logger, String baseDirectory, OpenDJUpgrader upgrader); State getState(); State upgrade(); static final String OPENDJ_DIR; }### Answer:
@Test public void whenInNoEmbeddedInstanceStateItShouldNotPerformUpgrade() throws Exception { createBaseDirectory("empty-base-directory"); final EmbeddedOpenDJManager embeddedOpenDJManager = new EmbeddedOpenDJManager(logger, baseDirectory, upgrader); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() throws Throwable { embeddedOpenDJManager.upgrade(); } }).isInstanceOf(IllegalStateException.class) .hasMessageContaining("Cannot upgrade embedded instance as no embedded instance has been configured"); }
@Test public void whenInConfiguredStateItShouldNotPerformUpgrade() throws Exception { final EmbeddedOpenDJManager embeddedOpenDJManager = setupInstallOpenDJNotRequiringUpgrade(); assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() throws Throwable { embeddedOpenDJManager.upgrade(); } }).isInstanceOf(IllegalStateException.class) .hasMessageContaining("Embedded instance does not require upgrading"); }
@Test public void whenInUpgradeRequiredStateItShouldPerformUpgrade() throws Exception { EmbeddedOpenDJManager embeddedOpenDJManager = setupInstallOpenDJRequiringUpgrade(); embeddedOpenDJManager.upgrade(); verify(upgrader).upgrade(); }