@Test public void getUserWhenGitLabServiceIsAvailable() throws Exception { Long userId = 10L; User user = new User(userId, "John Smith", "john.smith@mocked.com"); when(gitLabService.getUser(userId)).thenReturn(Response.success(user)); assertThat(service.getUser(Event.builder().userId(userId).build())).isEqualTo(user); verify(gitLabService, times(1)).getUser(userId); }
public User getUser(Event event) { try { Response<User> userResponse = gitLabService.getUser(event.getUserId()); Preconditions.checkArgument(userResponse.code() == 200); return userResponse.body(); } catch (Exception e) { log.error("Unable to get gitlab user with id <{}>, comment issue with pusher username <{}>", event.getUserId(), event.getUserName()); return new User(event.getUserId(), null, event.getUserName()); } }
IntegrationService { public User getUser(Event event) { try { Response<User> userResponse = gitLabService.getUser(event.getUserId()); Preconditions.checkArgument(userResponse.code() == 200); return userResponse.body(); } catch (Exception e) { log.error("Unable to get gitlab user with id <{}>, comment issue with pusher username <{}>", event.getUserId(), event.getUserName()); return new User(event.getUserId(), null, event.getUserName()); } } }
IntegrationService { public User getUser(Event event) { try { Response<User> userResponse = gitLabService.getUser(event.getUserId()); Preconditions.checkArgument(userResponse.code() == 200); return userResponse.body(); } catch (Exception e) { log.error("Unable to get gitlab user with id <{}>, comment issue with pusher username <{}>", event.getUserId(), event.getUserName()); return new User(event.getUserId(), null, event.getUserName()); } } @Inject  IntegrationService(GitLabService gitLabService, JiraService jiraService); }
IntegrationService { public User getUser(Event event) { try { Response<User> userResponse = gitLabService.getUser(event.getUserId()); Preconditions.checkArgument(userResponse.code() == 200); return userResponse.body(); } catch (Exception e) { log.error("Unable to get gitlab user with id <{}>, comment issue with pusher username <{}>", event.getUserId(), event.getUserName()); return new User(event.getUserId(), null, event.getUserName()); } } @Inject  IntegrationService(GitLabService gitLabService, JiraService jiraService); String getDateAsString(Date date); String buildComment(User user, String repositoryName, Commit commit); String buildCommentForTransition(User user, String repositoryName, Commit commit); void commentIssue(String repositoryName, User user, Collection<Commit> commits, String issue); void performPushEvent(Event event); User getUser(Event event); }
IntegrationService { public User getUser(Event event) { try { Response<User> userResponse = gitLabService.getUser(event.getUserId()); Preconditions.checkArgument(userResponse.code() == 200); return userResponse.body(); } catch (Exception e) { log.error("Unable to get gitlab user with id <{}>, comment issue with pusher username <{}>", event.getUserId(), event.getUserName()); return new User(event.getUserId(), null, event.getUserName()); } } @Inject  IntegrationService(GitLabService gitLabService, JiraService jiraService); String getDateAsString(Date date); String buildComment(User user, String repositoryName, Commit commit); String buildCommentForTransition(User user, String repositoryName, Commit commit); void commentIssue(String repositoryName, User user, Collection<Commit> commits, String issue); void performPushEvent(Event event); User getUser(Event event); static final DateFormat DATE_FORMAT; }