### Question:
DatabaseLogExceptionFactory { public static LogExceptionBehaviourInterface getExceptionStrategy( LogTableCoreInterface table ) { return getExceptionStrategy( table, null ); }  static LogExceptionBehaviourInterface getExceptionStrategy( LogTableCoreInterface table ); static LogExceptionBehaviourInterface getExceptionStrategy( LogTableCoreInterface table, Exception e ); static final String KETTLE_GLOBAL_PROP_NAME; }### Answer:
@Test public void testGetExceptionStrategyWithoutException() { LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE, strategyName ); }
@Test public void testGetExceptionStrategyWithoutExceptionPropSetY() { System.setProperty( DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( THROWABLE, strategyName ); }
@Test public void testExceptionStrategyWithException() { LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new Exception() ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE, strategyName ); }
@Test public void testGetExceptionStrategyWithExceptionPropSetY() { System.setProperty( DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new Exception() ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( THROWABLE, strategyName ); }
@Test public void testExceptionStrategyWithPacketTooBigException() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); PacketTooBigException e = new PacketTooBigException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
@Test public void testExceptionStrategyWithMaxAllowedPacketException() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MariaDBDatabaseMeta(); MaxAllowedPacketException e = new MaxAllowedPacketException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
@Test public void testExceptionStrategyWithMysqlDataTruncationException() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); MysqlDataTruncation e = new MysqlDataTruncation(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
@Test public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() { System.setProperty( DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE ); DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); PacketTooBigException e = new PacketTooBigException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( THROWABLE, strategyName ); }