private void mockContext(final ImplicitNameSource source) { final MetadataBuildingContext context = Mockito.mock(MetadataBuildingContext.class); final InFlightMetadataCollector collector = Mockito.mock(InFlightMetadataCollector.class); final Database database = Mockito.mock(Database.class); final JdbcEnvironment jdbcEnvironment = Mockito.mock(JdbcEnvironment.class); final IdentifierHelper identifierHelper = Mockito.mock(IdentifierHelper.class); Mockito.when(identifierHelper.toIdentifier(ArgumentMatchers.anyString())).then(new Answer<Identifier>() { @Override public Identifier answer(final InvocationOnMock invocation) { return DatabaseIdentifier.toIdentifier((String)invocation.getArguments()[0]) ; } }); Mockito.when(jdbcEnvironment.getIdentifierHelper()).thenReturn(identifierHelper); Mockito.when(database.getJdbcEnvironment()).thenReturn(jdbcEnvironment); Mockito.when(collector.getDatabase()).thenReturn(database); Mockito.when(context.getMetadataCollector()).thenReturn(collector); Mockito.when(source.getBuildingContext()).thenReturn(context); }
private JdbcEnvironment newJdbcEnvironment() { JdbcEnvironment jdbcEnvironment = Mockito.mock(JdbcEnvironment.class); IdentifierHelper identifierHelper = Mockito.mock(IdentifierHelper.class); Mockito.when(identifierHelper.toIdentifier(ArgumentMatchers.anyString())).then(new Answer<Identifier>() { @Override public Identifier answer(InvocationOnMock invocation) { if (invocation.getArguments()[0] == null) return null; return new Identifier((String) invocation.getArguments()[0], false); } }); Mockito.when(jdbcEnvironment.getIdentifierHelper()).thenReturn(identifierHelper); return jdbcEnvironment; }
@Override public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData) throws SQLException { // only override this method in order to be able to access the database // metadata this.metadata = dbMetaData; return super.buildIdentifierHelper(builder, dbMetaData); }
@Override public IdentifierHelper buildIdentifierHelper(final IdentifierHelperBuilder builder, final DatabaseMetaData dbMetaData) throws SQLException { return this.wrapped.buildIdentifierHelper(builder, dbMetaData); }