EncryptResultDecoratorEngine implements ResultDecoratorEngine<EncryptRule> { @Override public ResultDecorator newInstance(final DatabaseType databaseType, final SchemaMetaData schemaMetaData, final EncryptRule encryptRule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext) { if (sqlStatementContext instanceof SelectStatementContext) { return new EncryptDQLResultDecorator(new EncryptAlgorithmMetaData(schemaMetaData, encryptRule, (SelectStatementContext) sqlStatementContext), props.<Boolean>getValue(ConfigurationPropertyKey.QUERY_WITH_CIPHER_COLUMN)); } if (sqlStatementContext.getSqlStatement() instanceof DALStatement) { return new EncryptDALResultDecorator(); } return new TransparentResultDecorator(); }  @Override ResultDecorator newInstance(final DatabaseType databaseType, final SchemaMetaData schemaMetaData,
                                       final EncryptRule encryptRule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext); @Override int getOrder(); @Override Class<EncryptRule> getTypeClass();  }
@Test public void assertNewInstanceWithSelectStatement() { EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(Collections.singleton(rule), ResultProcessEngine.class).get(rule); ResultDecorator actual = engine.newInstance(databaseType, schemaMetaData, rule, props, mock(SelectStatementContext.class)); assertThat(actual, instanceOf(EncryptDQLResultDecorator.class)); }
@Test public void assertNewInstanceWithDALStatement() { SQLStatementContext<MySQLDescribeStatement> sqlStatementContext = mock(DescribeStatementContext.class); when(sqlStatementContext.getSqlStatement()).thenReturn(mock(MySQLDescribeStatement.class)); EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(Collections.singleton(rule), ResultProcessEngine.class).get(rule); ResultDecorator actual = engine.newInstance(databaseType, schemaMetaData, rule, props, sqlStatementContext); assertThat(actual, instanceOf(EncryptDALResultDecorator.class)); }
@Test public void assertNewInstanceWithOtherStatement() { EncryptResultDecoratorEngine engine = (EncryptResultDecoratorEngine) OrderedSPIRegistry.getRegisteredServices(Collections.singleton(rule), ResultProcessEngine.class).get(rule); ResultDecorator actual = engine.newInstance(databaseType, schemaMetaData, rule, props, mock(InsertStatementContext.class)); assertThat(actual, instanceOf(TransparentResultDecorator.class)); }