@Test public void nextConnote_Goodcase() throws Exception { Long uniqueConnote = 1L; Connote connoteToBeSaved = new Connote(uniqueConnote); connoteToBeSaved.setCreated(new LocalDateTime(2017, 01, 02, 12, 03, 10)); when(randomConnoteGeneratorMock.randomNumber()).thenReturn(342L, uniqueConnote); when(connoteRepositoryMock.findOne(342L)).thenReturn(new Connote(342L)); when(connoteRepositoryMock.findOne(uniqueConnote)).thenReturn(null); when(connoteRepositoryMock.save(any(Connote.class))).thenReturn(connoteToBeSaved); ConnoteDTO connote = connoteService.createConnote(); assertThat(connote.getConnote(), is(1L)); verify(randomConnoteGeneratorMock, times(2)).randomNumber(); }
public ConnoteDTO createConnote() { Long nextConnote; do { nextConnote = connoteGenerator.randomNumber(); } while (!isUnique(nextConnote)); Connote connoteSaved = createConnote(nextConnote); ConnoteDTO connoteDTO = new ConnoteDTO(); connoteDTO.setConnote(connoteSaved.getConnote()); return connoteDTO; }
ConnoteService { public ConnoteDTO createConnote() { Long nextConnote; do { nextConnote = connoteGenerator.randomNumber(); } while (!isUnique(nextConnote)); Connote connoteSaved = createConnote(nextConnote); ConnoteDTO connoteDTO = new ConnoteDTO(); connoteDTO.setConnote(connoteSaved.getConnote()); return connoteDTO; } }
ConnoteService { public ConnoteDTO createConnote() { Long nextConnote; do { nextConnote = connoteGenerator.randomNumber(); } while (!isUnique(nextConnote)); Connote connoteSaved = createConnote(nextConnote); ConnoteDTO connoteDTO = new ConnoteDTO(); connoteDTO.setConnote(connoteSaved.getConnote()); return connoteDTO; } @Autowired  ConnoteService(ConnoteRepository connoteRepository, RandomConnoteGenerator connoteGenerator); }
ConnoteService { public ConnoteDTO createConnote() { Long nextConnote; do { nextConnote = connoteGenerator.randomNumber(); } while (!isUnique(nextConnote)); Connote connoteSaved = createConnote(nextConnote); ConnoteDTO connoteDTO = new ConnoteDTO(); connoteDTO.setConnote(connoteSaved.getConnote()); return connoteDTO; } @Autowired  ConnoteService(ConnoteRepository connoteRepository, RandomConnoteGenerator connoteGenerator); ConnoteDTO createConnote(); }
ConnoteService { public ConnoteDTO createConnote() { Long nextConnote; do { nextConnote = connoteGenerator.randomNumber(); } while (!isUnique(nextConnote)); Connote connoteSaved = createConnote(nextConnote); ConnoteDTO connoteDTO = new ConnoteDTO(); connoteDTO.setConnote(connoteSaved.getConnote()); return connoteDTO; } @Autowired  ConnoteService(ConnoteRepository connoteRepository, RandomConnoteGenerator connoteGenerator); ConnoteDTO createConnote();  }