### Question:
ShouldRunChangeSetFilter implements ChangeSetFilter { @SuppressWarnings({"RedundantIfStatement"}) public boolean accepts(ChangeSet changeSet) { for (RanChangeSet ranChangeSet : ranChangeSets) { if (ranChangeSet.getId().equals(changeSet.getId()) && ranChangeSet.getAuthor().equals(changeSet.getAuthor()) && isPathEquals(changeSet, ranChangeSet)) { if (changeSet.shouldAlwaysRun() && ranChangeSet.getLastCheckSum() != null) { return true; } else if (changeSet.shouldRunOnChange() && !changeSet.generateCheckSum().equals(ranChangeSet.getLastCheckSum())) { return true; } else { return false; } } } return true; } ShouldRunChangeSetFilter(Database database); @SuppressWarnings({"RedundantIfStatement"}) boolean accepts(ChangeSet changeSet); public List<RanChangeSet> ranChangeSets; }### Answer:
@Test public void accepts_noneRun() throws DatabaseException { Database database = createMock(Database.class); expect(database.getRanChangeSetList()).andReturn(new ArrayList<RanChangeSet>()); replay(database); ShouldRunChangeSetFilter filter = new ShouldRunChangeSetFilter(database); assertTrue(filter.accepts(new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null))); }
@Test public void accepts() throws DatabaseException { ArrayList<RanChangeSet> ranChanges = new ArrayList<RanChangeSet>(); ranChanges.add(new RanChangeSet("path/changelog", "1", "testAuthor", CheckSum.parse("12345"), new Date(), null, null)); ranChanges.add(new RanChangeSet("path/changelog", "2", "testAuthor", CheckSum.parse("12345"), new Date(), null, null)); Database database = createMock(Database.class); expect(database.getRanChangeSetList()).andReturn(ranChanges); expect(database.getDatabaseChangeLogTableName()).andReturn("DATABASECHANGELOG").anyTimes(); expect(database.getDefaultSchemaName()).andReturn(null).anyTimes(); Executor template = createMock(Executor.class); expect(template.update(isA(UpdateStatement.class))).andReturn(1).anyTimes(); replay(database); replay(template); ExecutorService.getInstance().setExecutor(database, template); ShouldRunChangeSetFilter filter = new ShouldRunChangeSetFilter(database); assertFalse(filter.accepts(new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null))); assertTrue(filter.accepts(new ChangeSet("1", "testAuthor", true, false, "path/changelog", null, null))); assertTrue(filter.accepts(new ChangeSet("1", "testAuthor", false, true, "path/changelog", null, null))); assertTrue(filter.accepts(new ChangeSet("3", "testAuthor", false, false, "path/changelog", null, null))); assertTrue(filter.accepts(new ChangeSet("1", "otherAuthor", false, false, "path/changelog", null, null))); assertTrue(filter.accepts(new ChangeSet("1", "testAuthor", false, false, "other/changelog", null, null))); }