@Test public void setPopulatorsForOverride() throws SQLException { CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); populator.setPopulators(mockedDatabasePopulator1); populator.setPopulators(mockedDatabasePopulator2); // override populator.populate(mockedConnection); verify(mockedDatabasePopulator1, times(0)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); }
@Test public void addPopulators() throws SQLException { CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); populator.addPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); populator.populate(mockedConnection); verify(mockedDatabasePopulator1,times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); }
@Test public void constructWithVarargs() throws SQLException { CompositeDatabasePopulator populator = new CompositeDatabasePopulator(mockedDatabasePopulator1, mockedDatabasePopulator2); populator.populate(mockedConnection); verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); }
@Bean public DatabasePopulator databasePopulator() { ResourceDatabasePopulator schemaPopulator = new ResourceDatabasePopulator( new ClassPathResource("firebird-schema.sql")); schemaPopulator.setSeparator("!!"); DatabasePopulator dataPopulator = new ResourceDatabasePopulator( new ClassPathResource("firebird-data.sql")); return new CompositeDatabasePopulator(schemaPopulator, dataPopulator); }
@Test public void constructWithCollection() throws SQLException { Set<DatabasePopulator> populators = new LinkedHashSet<>(); populators.add(mockedDatabasePopulator1); populators.add(mockedDatabasePopulator2); CompositeDatabasePopulator populator = new CompositeDatabasePopulator(populators); populator.populate(mockedConnection); verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); }
@Test public void setPopulatorsWithMultiple() throws SQLException { CompositeDatabasePopulator populator = new CompositeDatabasePopulator(); populator.setPopulators(mockedDatabasePopulator1, mockedDatabasePopulator2); // multiple populator.populate(mockedConnection); verify(mockedDatabasePopulator1, times(1)).populate(mockedConnection); verify(mockedDatabasePopulator2, times(1)).populate(mockedConnection); }