EulaWebService { @Path(CURRENT) @GET public UserEulaStatus currentUserEulaStatus() { return new UserEulaStatus(settingsService.retrieve().userHasAgreedToLicense()); } @Inject  EulaWebService(SettingsService settingsService); @Path(CURRENT_EULA) @GET Eula current(); @Path(CURRENT) @GET UserEulaStatus currentUserEulaStatus(); @Path(CURRENT) @PUT void currentUserEulaStatus(UserEulaStatus newStatus);  }
@Test public void getCurrentUserEulaStatus() { doReturn(new Settings()).when(settingsService).retrieve(); UserEulaStatus current = service.currentUserEulaStatus(); assertFalse(current.userHasAgreedToLicense()); doReturn(new Settings().withUserHasAgreedToLicense(true)).when(settingsService).retrieve(); current = service.currentUserEulaStatus(); assertTrue(current.userHasAgreedToLicense()); }
@Test public void putCurrentUserEulaStatus() { doReturn(new Settings()).when(settingsService).retrieve(); service.currentUserEulaStatus(new UserEulaStatus(true)); ArgumentCaptor<Settings> settingsCaptor = ArgumentCaptor.forClass(Settings.class); verify(settingsService).update(settingsCaptor.capture()); Settings settings = settingsCaptor.getValue(); assertNotNull(settings); assertEquals(true, settings.userHasAgreedToLicense()); }
@Test public void putCurrentUserEulaStatusNotAccepted() { doReturn(new Settings()).when(settingsService).retrieve(); thrown.expect(ValidationException.class); thrown.expectMessage("You must agree to the license in order to use Green Beans."); service.currentUserEulaStatus(new UserEulaStatus(false)); }