### Question:
MultiplicationServiceImpl implements MultiplicationService { @Transactional @Override public boolean checkAttempt(final MultiplicationResultAttempt attempt) { Optional<User> user = userRepository.findByAlias(attempt.getUser().getAlias()); Assert.isTrue(!attempt.isCorrect(), "You can't send an attempt marked as correct!!"); boolean isCorrect = attempt.getResultAttempt() == attempt.getMultiplication().getFactorA() * attempt.getMultiplication().getFactorB(); MultiplicationResultAttempt checkedAttempt = new MultiplicationResultAttempt( user.orElse(attempt.getUser()), attempt.getMultiplication(), attempt.getResultAttempt(), isCorrect ); attemptRepository.save(checkedAttempt); return isCorrect; } @Autowired  MultiplicationServiceImpl(final RandomGeneratorService randomGeneratorService,
                                     final MultiplicationResultAttemptRepository attemptRepository,
                                     final UserRepository userRepository); @Override Multiplication createRandomMultiplication(); @Transactional @Override boolean checkAttempt(final MultiplicationResultAttempt attempt); @Override List<MultiplicationResultAttempt> getStatsForUser(String userAlias);  }### Answer:
@Test public void checkCorrectAttemptTest() { Multiplication multiplication = new Multiplication(50, 60); User user = new User("john_doe"); MultiplicationResultAttempt attempt = new MultiplicationResultAttempt( user, multiplication, 3000, false); MultiplicationResultAttempt verifiedAttempt = new MultiplicationResultAttempt( user, multiplication, 3000, true); given(userRepository.findByAlias("john_doe")).willReturn(Optional.empty()); boolean attemptResult = multiplicationServiceImpl.checkAttempt(attempt); assertThat(attemptResult).isTrue(); verify(attemptRepository).save(verifiedAttempt); }
@Test public void checkWrongAttemptTest() { Multiplication multiplication = new Multiplication(50, 60); User user = new User("john_doe"); MultiplicationResultAttempt attempt = new MultiplicationResultAttempt( user, multiplication, 3010, false); given(userRepository.findByAlias("john_doe")).willReturn(Optional.empty()); boolean attemptResult = multiplicationServiceImpl.checkAttempt(attempt); assertThat(attemptResult).isFalse(); verify(attemptRepository).save(attempt); }