SuiteRemoveCondition { public boolean evaluate(final Suite suite) { boolean remove = false; if (minKeepVersion != null) { remove = suite.getVersion() < minKeepVersion; } if (removeTimestamp != null) { final long suiteCreated = suite.getRunTimestamp().get(); remove &= suiteCreated <= removeTimestamp; } return remove; } SuiteRemoveCondition(final Collection<Suite> suiteRunVersions,
      final CleanerContext cleanerContext, LocalDateTimeProvider dateTimeProvider); boolean evaluate(final Suite suite);  }
@TestWith({ "A-1 ; null ; 1 ; A-1 ; 10", "A-1 ; null ; null ; A-1 ; 10", "A-1 ; 100 ; 1 ; A-1; 10", "A-1 ; 100 ; null ; A-1 ; 10" }) public void evaluate_whenOnlyOneSuite_expectFalseNoMatterConditions(String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertFalse(remove); }
@TestWith({ "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; A-1 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; A-2 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; B-3 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; B-4 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; C-5 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; C-6 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; D-7 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; A-1 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; A-2 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; B-3 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; B-4 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; A-1 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; A-2 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; B-3 ; 10" }) public void evaluate_when8SuitesVersionsRemoveOldVersions_expectTrue(String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertTrue(remove); }
@TestWith({ "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 1 ; E-8 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; C-5 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; C-6 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; D-7 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 4 ; E-8 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; B-4 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; C-5 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; C-6 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; D-7 ; 10", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; null ; 5 ; E-8 ; 10" }) public void evaluate_when8SuitesVersionsKeepLastVersions_expectFalse(String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertFalse(remove); }
@TestWith({ "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; A-1 ; 8", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; A-2 ; 7", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; B-3 ; 6", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; B-4 ; 5", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; C-5 ; 4", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; A-1 ; 8", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; A-2 ; 7", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; B-3 ; 6", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; B-4 ; 5", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; C-5 ; 4", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; C-6 ; 3", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; D-7 ; 2" }) public void evaluate_when8SuitesRemoveOlderThanButAlwaysKeepLatestVersion_expectTrue( String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertTrue(remove); }
@TestWith({ "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; C-6 ; 3", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; D-7 ; 2", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; null ; E-8 ; 1", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 1 ; null ; E-8 ; 1" }) public void evaluate_when8SuitesKeepNewerThan_expectFalse(String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertFalse(remove); }
@TestWith({ "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; A-1 ; 8", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; A-2 ; 7", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; B-3 ; 6", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; B-4 ; 5" }) public void evaluate_when8SuitesKeepNewerThanAndAtLeastXVersions_expectTrue( String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertTrue(remove); }
@TestWith({ "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; C-5 ; 4", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; C-6 ; 3", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; D-7 ; 2", "A-1,A-2,B-3,B-4,C-5,C-6,D-7,E-8 ; 4 ; 4 ; E-8 ; 1" }) public void evaluate_when8SuitesKeepNewerThanAndAtLeastXVersions_expectFalse( String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertFalse(remove); }
@TestWith({ "A-1,A-2,B-2 ; null ; 1 ; A-1 ; 10" }) public void evaluate_whenDuplicatedVersion_expectRemoveOnlyOldVersions(String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertTrue(remove); }
@TestWith({ "A-1,A-2,B-2 ; null ; 1 ; A-2 ; 10", "A-1,A-2,B-2 ; null ; 1 ; B-2 ; 10" }) public void evaluate_whenDuplicatedVersion_expectKeepNewestVersion(String allSuitesVersions, Long removeOlderThan, Long keepNVersions, String evaluatedSuite, Integer createdDaysAgo) { final List<Suite> suites = SUITES_LIST_COERCER.toList(allSuitesVersions); Suite suite = mockSuiteVersionAndCreatedDate(evaluatedSuite, createdDaysAgo); SuiteRemoveCondition condition = new SuiteRemoveCondition(suites, mockRemoveConditions(removeOlderThan, keepNVersions), new SystemLocalDateTime()); final boolean remove = condition.evaluate(suite); assertFalse(remove); }