Search in sources :

Example 1 with TestConfigSupplier

use of net.morimekta.providence.config.util.TestConfigSupplier in project providence by morimekta.

the class ProvidenceConfigSupplierTest method testParentConfigUpdatesPropagaing.

@Test
public void testParentConfigUpdatesPropagaing() throws IOException {
    TestConfigSupplier<Database, Database._Field> parent = new TestConfigSupplier<>(Database.builder().setUri("foo").build());
    File bar = writeContentTo("config.Database { driver = \"bar\" }", tmp.newFile("bar.config"));
    SimpleTypeRegistry registry = new SimpleTypeRegistry();
    registry.registerRecursively(Database.kDescriptor);
    parser = new ProvidenceConfigParser(registry, false);
    ProvidenceConfigSupplier<Database, Database._Field> config = new ProvidenceConfigSupplier<>(bar, parent, watcher, parser, clock);
    assertThat(config.get(), is(Database.builder().setUri("foo").setDriver("bar").build()));
    ConfigListener<Database, Database._Field> listener = mock(ConfigListener.class);
    config.addListener(listener);
    parent.testUpdate(Database.builder().setUri("fish").build());
    verify(listener).onConfigChange(Database.builder().setUri("fish").setDriver("bar").build());
    reset(listener);
    config.removeListener(listener);
    parent.testUpdate(Database.builder().build());
    verifyZeroInteractions(listener);
}
Also used : TestConfigSupplier(net.morimekta.providence.config.util.TestConfigSupplier) SimpleTypeRegistry(net.morimekta.providence.util.SimpleTypeRegistry) Database(net.morimekta.test.providence.config.Database) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 TestConfigSupplier (net.morimekta.providence.config.util.TestConfigSupplier)1 SimpleTypeRegistry (net.morimekta.providence.util.SimpleTypeRegistry)1 Database (net.morimekta.test.providence.config.Database)1 Test (org.junit.Test)1