### Question:
KeyResultService { @Transactional public void updateSequence(Long objectiveId, Collection<Long> sequenceList, User user) throws Exception { Objective objective = objectiveService.findById(objectiveId); throwIfSequenceInvalid(objective, sequenceList); ArrayList<Long> sequenceArray = new ArrayList<>(sequenceList); objective .getKeyResults() .forEach( keyResult -> { int currentOrder = sequenceArray.indexOf(keyResult.getId()); keyResult.setSequence(currentOrder); keyResultRepository.save(keyResult); activityService.createActivity(user, keyResult, Action.EDITED); logger.info("Update sequence of KeyResult with id " + keyResult.getId()); }); } @Autowired  KeyResultService(
      KeyResultRepository keyResultRepository,
      NoteRepository noteRepository,
      ActivityService activityService,
      EntityCrawlerService entityCrawlerService,
      ObjectiveService objectiveService); KeyResult findById(long keyResultId); Collection<Note> findNotesOfKeyResult(long keyResultId); @Transactional KeyResult updateKeyResult(KeyResult updatedKeyResult, User user); @Transactional void deleteKeyResult(Long keyResultId, User user); @Transactional Note createNote(long keyResultId, Note note, User user); @Transactional void updateSequence(Long objectiveId, Collection<Long> sequenceList, User user);  }### Answer:
@Test(expected = Exception.class) public void updateSequence_NonEqualSizes_expectException() throws Exception { Objective objective = new Objective(); objective.setId(42L); objective.setKeyResults(new ArrayList<>()); Collection<Long> sequenceList = Collections.singletonList(1L); keyResultService.updateSequence(objective.getId(), sequenceList, user); }
@Test(expected = Exception.class) public void updateSequence_WrongObjectiveIdsInSequence_expectException() throws Exception { Objective objective = new Objective(); objective.setId(40L); KeyResult keyResult0 = new KeyResult(); keyResult0.setSequence(0); keyResult0.setId(10L); KeyResult keyResult1 = new KeyResult(); keyResult1.setSequence(1); keyResult1.setId(20L); KeyResult keyResult2 = new KeyResult(); keyResult2.setSequence(2); keyResult2.setId(30L); objective.setKeyResults(Arrays.asList(keyResult0, keyResult1, keyResult2)); Collection<Long> sequenceList = Arrays.asList(30L, 20L, 40L); keyResultService.updateSequence(objective.getId(), sequenceList, user); }