UpgradeTask implements MaintenanceTaskProcess { public Supplier<Boolean> condition() { final Supplier<Boolean> needUpgradeCondition = () -> upgradeService.needUpgrade(); final Supplier<Boolean> hasRepositoryConfiguration = forAll.condition().operational(repository); return () -> needUpgradeCondition.get() && hasRepositoryConfiguration.get(); }  void performTask(); Supplier<Boolean> condition(); @Override ScheduleFrequency getFrequency();  }
@Test public void shouldPerformUpgrade() { when(upgradeService.needUpgrade()).thenReturn(true); when(forAll.condition()).thenReturn(o -> () -> true); doAnswer((Answer<Void>) invocation -> { ((Runnable) invocation.getArguments()[1]).run(); return null; }).when(forAll).execute(any(), any()); doAnswer((Answer<Void>) invocation -> { ((Runnable) invocation.getArguments()[0]).run(); return null; }).when(executor).execute(any()); upgradeTask.execute(); verify(security, times(2)).getTenantId(); verify(upgradeService, times(1)).upgradeVersion(); }
@Test public void shouldNotPerformUpgrade() { when(upgradeService.needUpgrade()).thenReturn(false); doAnswer((Answer<Void>) invocation -> { ((Runnable) invocation.getArguments()[1]).run(); return null; }).when(forAll).execute(any(), any()); when(forAll.condition()).thenReturn(o -> () -> true); upgradeTask.execute(); verify(security, times(0)).getTenantId(); verify(upgradeService, times(0)).upgradeVersion(); }