### Question:
SqlGeneratorChain { public ValidationErrors validate(SqlStatement statement, Database database) { if (sqlGenerators == null || !sqlGenerators.hasNext()) { return new ValidationErrors(); } return sqlGenerators.next().validate(statement, database, this); } SqlGeneratorChain(SortedSet<SqlGenerator> sqlGenerators); Sql[] generateSql(SqlStatement statement, Database database); Warnings warn(SqlStatement statement, Database database); ValidationErrors validate(SqlStatement statement, Database database);  }### Answer:
@Test public void validate_nullGenerators() { SqlGeneratorChain chain = new SqlGeneratorChain(null); ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase()); assertFalse(validationErrors.hasErrors()); }
@Test public void validate_oneGenerators_noErrors() { SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator()); generators.add(new MockSqlGenerator(1, "A1", "A2")); SqlGeneratorChain chain = new SqlGeneratorChain(generators); ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase()); assertFalse(validationErrors.hasErrors()); }
@Test public void validate_oneGenerators_hasErrors() { SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator()); generators.add(new MockSqlGenerator(1, "A1", "A2").addValidationError("E1")); SqlGeneratorChain chain = new SqlGeneratorChain(generators); ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase()); assertTrue(validationErrors.hasErrors()); }
@Test public void validate_twoGenerators_noErrors() { SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator()); generators.add(new MockSqlGenerator(2, "B1", "B2")); generators.add(new MockSqlGenerator(1, "A1", "A2")); SqlGeneratorChain chain = new SqlGeneratorChain(generators); ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase()); assertFalse(validationErrors.hasErrors()); }
@Test public void validate_twoGenerators_firstHasErrors() { SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator()); generators.add(new MockSqlGenerator(2, "B1", "B2").addValidationError("E1")); generators.add(new MockSqlGenerator(1, "A1", "A2")); SqlGeneratorChain chain = new SqlGeneratorChain(generators); ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase()); assertTrue(validationErrors.hasErrors()); }
@Test public void validate_twoGenerators_secondHasErrors() { SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator()); generators.add(new MockSqlGenerator(2, "B1", "B2")); generators.add(new MockSqlGenerator(1, "A1", "A2").addValidationError("E1")); SqlGeneratorChain chain = new SqlGeneratorChain(generators); ValidationErrors validationErrors = chain.validate(new MockSqlStatement(), new MockDatabase()); assertTrue(validationErrors.hasErrors()); }