/** * Get email of user by user's id. * * @param userId user's id * @return an email of user by user's id */ private String getEmailOfUser(long userId) { try { JCUser user = userService.get(userId); return user.getEmail(); } catch (NotFoundException e) { return null; } }
@Test public void renderAvatarShouldNotReturnNotModifiedAvatarInResponse() throws IOException, NotFoundException { JCUser user = getUser(); user.setAvatar(validAvatar); user.setAvatarLastModificationTime(new DateTime(0)); when(userService.get(anyLong())).thenReturn(user); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader(avatarController.IF_MODIFIED_SINCE_HEADER, new Date(1000)); avatarController.renderAvatar(request, response, 0L); assertEquals(response.getStatus(), HttpServletResponse.SC_NOT_MODIFIED); assertNotSame(response.getContentAsByteArray(), validAvatar); assertEquals(response.getHeader("Pragma"), "public"); List<String> cacheControlHeaders = response.getHeaders("Cache-Control"); assertTrue(cacheControlHeaders.contains("public")); assertTrue(cacheControlHeaders.contains("must-revalidate")); assertTrue(cacheControlHeaders.contains("max-age=0")); assertNotNull(response.getHeader("Expires")); // System.currentTimeMillis() is used assertNotNull(response.getHeader("Last-Modified")); // depends on current timezone }
@BeforeMethod public void init() throws NotFoundException { initMocks(this); when(userService.get(anyLong())).thenReturn(user); validator = new ChangedEmailValidator(userService, userDao); }