@Test(expected = UsernameMismatchException.class) public void testUserMismatch() { Application application = mockApplication(); doReturn(MOCK_INVALID_USERNAME).when(certificateService) .getCommonNameFromApplicationCertificate(application); userService.getUsername(application); }
public String getUsername(Application application) { String username = application.getUsername(); String cname = certificateService.getCommonNameFromApplicationCertificate(application); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(cname) && !username.equals(cname)) { String message = logMessage.getMessage(USER_MISMATCH_DESCRIPTION, cname, username); String solution = logMessage.getMessage(USER_MISMATCH_SOLUTION); throw new UsernameMismatchException(message, solution); } return StringUtils.isNotEmpty(username) ? username : cname; }
UserService { public String getUsername(Application application) { String username = application.getUsername(); String cname = certificateService.getCommonNameFromApplicationCertificate(application); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(cname) && !username.equals(cname)) { String message = logMessage.getMessage(USER_MISMATCH_DESCRIPTION, cname, username); String solution = logMessage.getMessage(USER_MISMATCH_SOLUTION); throw new UsernameMismatchException(message, solution); } return StringUtils.isNotEmpty(username) ? username : cname; } }
UserService { public String getUsername(Application application) { String username = application.getUsername(); String cname = certificateService.getCommonNameFromApplicationCertificate(application); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(cname) && !username.equals(cname)) { String message = logMessage.getMessage(USER_MISMATCH_DESCRIPTION, cname, username); String solution = logMessage.getMessage(USER_MISMATCH_SOLUTION); throw new UsernameMismatchException(message, solution); } return StringUtils.isNotEmpty(username) ? username : cname; }  }
UserService { public String getUsername(Application application) { String username = application.getUsername(); String cname = certificateService.getCommonNameFromApplicationCertificate(application); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(cname) && !username.equals(cname)) { String message = logMessage.getMessage(USER_MISMATCH_DESCRIPTION, cname, username); String solution = logMessage.getMessage(USER_MISMATCH_SOLUTION); throw new UsernameMismatchException(message, solution); } return StringUtils.isNotEmpty(username) ? username : cname; }  @PostConstruct void init(); void setupBotUser(Application application); User getUser(String username); User getUser(Long userId); String getUsername(Application application); }
UserService { public String getUsername(Application application) { String username = application.getUsername(); String cname = certificateService.getCommonNameFromApplicationCertificate(application); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(cname) && !username.equals(cname)) { String message = logMessage.getMessage(USER_MISMATCH_DESCRIPTION, cname, username); String solution = logMessage.getMessage(USER_MISMATCH_SOLUTION); throw new UsernameMismatchException(message, solution); } return StringUtils.isNotEmpty(username) ? username : cname; }  @PostConstruct void init(); void setupBotUser(Application application); User getUser(String username); User getUser(Long userId); String getUsername(Application application);  }