@Test public void throws_ISE_if_handler_fails() throws Exception { Oracle dialect = new Oracle(); when(underTest.getHandler(dialect)).thenReturn(handler); when(db.getDialect()).thenReturn(dialect); doThrow(new SQLException("failure")).when(handler).handle(any(Connection.class), anySet()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("failure"); underTest.check(AUTO_REPAIR_COLLATION); }
@Test public void getHandler_throws_IAE_if_unsupported_db() throws Exception { Dialect unsupportedDialect = mock(Dialect.class); when(unsupportedDialect.getId()).thenReturn("foo"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Database not supported: foo"); underTest.getHandler(unsupportedDialect); }
@Test public void executes_handler() throws Exception { Oracle dialect = new Oracle(); when(underTest.getHandler(dialect)).thenReturn(handler); when(db.getDialect()).thenReturn(dialect); underTest.check(ENFORCE_UTF8); verify(handler) .handle( any(Connection.class), argThat( new TypeSafeMatcher<Set<DatabaseCharsetChecker.Flag>>() { @Override protected boolean matchesSafely(Set<DatabaseCharsetChecker.Flag> flags) { return flags.contains(ENFORCE_UTF8) && flags.size() == 1; } @Override public void describeTo(Description description) {} })); }
@Test public void getHandler_returns_MysqlCharsetHandler_if_mysql() throws Exception { assertThat(underTest.getHandler(new MySql())).isInstanceOf(MysqlCharsetHandler.class); }
@Test public void does_nothing_if_h2() throws Exception { assertThat(underTest.getHandler(new H2())).isNull(); }
@Test public void getHandler_returns_PostgresCharsetHandler_if_postgres() throws Exception { assertThat(underTest.getHandler(new PostgreSql())).isInstanceOf(PostgresCharsetHandler.class); }
@Test public void getHandler_returns_OracleCharsetHandler_if_oracle() throws Exception { assertThat(underTest.getHandler(new Oracle())).isInstanceOf(OracleCharsetHandler.class); }