### Question:
ConfigurationAdminBackend { @Invalidate public void unregisterQuietly() { if (reg == null) { return; } try { reg.unregister(); } catch (IllegalStateException e) { } reg = null; } ConfigurationAdminBackend(@Context BundleContext context,
                                     @Requires ApplicationConfiguration configuration); @Invalidate void unregisterQuietly(); static final String LOCATION; }### Answer:
@Test public void backendEnabledWithDefaultLocation() { BundleContext context = mock(BundleContext.class); ServiceRegistration<PersistenceManager> registration = mock(ServiceRegistration.class); when(context.registerService(any(Class.class), any(PersistenceManager.class), any(Dictionary.class))).thenReturn(registration); ApplicationConfiguration configuration = mock(ApplicationConfiguration.class); when(configuration.getBaseDir()).thenReturn(new File("target/junk")); when(configuration.getBooleanWithDefault("configadmin.persistence", true)).thenReturn(true); when(configuration.getWithDefault("configadmin.storage", ConfigurationAdminBackend.LOCATION)).thenReturn (ConfigurationAdminBackend.LOCATION); ConfigurationAdminBackend backend = new ConfigurationAdminBackend(context, configuration); assertThat(backend.reg).isNotNull(); assertThat(backend.reg).isEqualTo(registration); backend.unregisterQuietly(); }
@Test public void backendDisabledWithDefaultLocation() { BundleContext context = mock(BundleContext.class); ServiceRegistration<PersistenceManager> registration = mock(ServiceRegistration.class); when(context.registerService(any(Class.class), any(PersistenceManager.class), any(Dictionary.class))).thenReturn(registration); ApplicationConfiguration configuration = mock(ApplicationConfiguration.class); when(configuration.getBaseDir()).thenReturn(new File("target/junk")); when(configuration.getBooleanWithDefault("configadmin.persistence", true)).thenReturn(false); when(configuration.getWithDefault("configadmin.storage", ConfigurationAdminBackend.LOCATION)).thenReturn (ConfigurationAdminBackend.LOCATION); ConfigurationAdminBackend backend = new ConfigurationAdminBackend(context, configuration); assertThat(backend.reg).isNull(); backend.unregisterQuietly(); }