ValidateApplicationExists implements UninstallApplicationValidator { @Override public void validate(final UninstallApplicationValidationContext validationContext) throws RestErrorException { logger.info("Validating that application exists"); final String appName = validationContext.getApplicationName(); final Application app = validationContext.getAdmin().getApplications().waitFor( validationContext.getApplicationName(), 10, TimeUnit.SECONDS); if (app == null) { logger.log(Level.INFO, "Cannot uninstall application " + appName + " since it has not been discovered yet."); throw new RestErrorException(FAILED_TO_LOCATE_APP, appName); } }  @Override void validate(final UninstallApplicationValidationContext validationContext);  }
@Test public void test() { UninstallApplicationValidationContext context = new UninstallApplicationValidationContext(); DefaultAdmin admin = Mockito.mock(DefaultAdmin.class); Applications applications = Mockito.mock(DefaultApplications.class); Mockito.when(applications.getAdmin()).thenReturn(admin); Mockito.when(applications.waitFor(APP_NAME, TIMEOUT_SECONDS, TimeUnit.SECONDS)).thenReturn(null); Mockito.when(admin.getApplications()).thenReturn(applications); context.setAdmin(admin); context.setApplicationName(APP_NAME); ValidateApplicationExists validator = new ValidateApplicationExists(); try { validator.validate(context); Assert.fail("RestErrorException expected"); } catch (RestErrorException e) { Assert.assertEquals(ResponseConstants.FAILED_TO_LOCATE_APP, e.getMessage()); } }