ByIdResultSelector implements ResultSelector { @Override public Optional<ResultAction> get(final Run<?, ?> build) { List<ResultAction> actions = build.getActions(ResultAction.class); for (ResultAction action : actions) { if (id.equals(action.getId())) { return Optional.of(action); } } return Optional.empty(); } ByIdResultSelector(final String id); @Override Optional<ResultAction> get(final Run<?, ?> build); @Override String toString();  }
@Test void shouldBeEmptyIfActionsAreEmpty() { ByIdResultSelector selector = new ByIdResultSelector("1"); Run<?, ?> run = createRunStub(new ArrayList<>()); assertThat(selector.get(run)).isEmpty(); }
@Test void shouldBeEmptyIfActionsHasDifferentId() { ByIdResultSelector selector = new ByIdResultSelector("1"); List<ResultAction> resultActions = new ArrayList<>(); resultActions.add(createResultActionStub("2")); Run<?, ?> run = createRunStub(resultActions); assertThat(selector.get(run)).isEmpty(); }
@Test void shouldFindActionWithSameId() { ByIdResultSelector selector = new ByIdResultSelector("1"); List<ResultAction> resultActions = new ArrayList<>(); resultActions.add(createResultActionStub("1")); Run<?, ?> run = createRunStub(resultActions); assertThat(selector.get(run)).isPresent(); }
@Test void shouldFindEmptyIfListContainsTwoDifferentIds() { ByIdResultSelector selector = new ByIdResultSelector("1"); List<ResultAction> resultActions = new ArrayList<>(); resultActions.add(createResultActionStub("2")); resultActions.add(createResultActionStub("3")); Run<?, ?> run = createRunStub(resultActions); assertThat(selector.get(run)).isEmpty(); }
@Test void shouldFindActionWithSameIdIfListContainsTwoDifferentIds() { ByIdResultSelector selector = new ByIdResultSelector("1"); List<ResultAction> resultActions = new ArrayList<>(); resultActions.add(createResultActionStub("2")); resultActions.add(createResultActionStub("1")); Run<?, ?> run = createRunStub(resultActions); assertThat(selector.get(run)).isPresent(); }