@Test
  public void throwsErrorWhenMultipleDbConfigAvailable() throws Exception {
    DbConfig dbConfig1 = mock(DbConfig.class);
    when(dbConfig1.getName()).thenReturn("dbConfig1");
    DbConfig dbConfig2 = mock(DbConfig.class);
    when(dbConfig2.getName()).thenReturn("dbConfig2");

    DbConfigResolver dbConfigResolver1 = mock(DbConfigResolver.class);
    when(dbConfigResolver1.resolve(null)).thenReturn(dbConfig1);

    DbConfigResolver dbConfigResolver2 = mock(DbConfigResolver.class);
    when(dbConfigResolver2.resolve(null)).thenReturn(dbConfig2);

    MuleRegistry registry = mock(MuleRegistry.class);
    Collection<DbConfigResolver> foundDbConfigResolvers = new ArrayList<>();
    foundDbConfigResolvers.add(dbConfigResolver1);
    foundDbConfigResolvers.add(dbConfigResolver2);

    when(registry.lookupObjects(DbConfigResolver.class)).thenReturn(foundDbConfigResolvers);

    DefaultDbConfigResolver dbConfigResolver = new DefaultDbConfigResolver(registry);

    try {
      dbConfigResolver.resolve(muleEvent);
      fail("Was supposed to fail when there are multiple dbConfigs available");
    } catch (UnresolvableDbConfigException e) {
      assertThat(e.getMessage(), containsString("dbConfig1"));
      assertThat(e.getMessage(), containsString("dbConfig2"));
    }
  }
  @Test(expected = UnresolvableDbConfigException.class)
  public void throwsErrorWhenNoDbConfigAvailable() throws Exception {
    MuleRegistry registry = mock(MuleRegistry.class);
    Collection<DbConfig> foundDbConfigs = new ArrayList<DbConfig>();

    when(registry.lookupObjects(DbConfig.class)).thenReturn(foundDbConfigs);

    DefaultDbConfigResolver dbConfigResolver = new DefaultDbConfigResolver(registry);

    dbConfigResolver.resolve(muleEvent);
  }
  @Test
  public void resolvesDefaultDbConfig() throws Exception {
    DbConfigResolver dbConfigResolver = mock(DbConfigResolver.class);
    DbConfig dbConfig = mock(DbConfig.class);
    when(dbConfigResolver.resolve(muleEvent)).thenReturn(dbConfig);

    MuleRegistry registry = createMockRegistry(dbConfigResolver);
    DefaultDbConfigResolver defaultDbConfigResolver = new DefaultDbConfigResolver(registry);

    DbConfig resolvedDbConfig = defaultDbConfigResolver.resolve(muleEvent);

    assertThat(dbConfig, sameInstance(resolvedDbConfig));
  }