@Test public void thatImportedDartsContainNoClones() { when(dartsService.getDartsTable()).thenReturn(HashBasedTable.<String, String, Dart>create()); when(dartsExtractor.extract(inputStream)).thenReturn(createExpectedDartsWithClones()); defaultDartsImporter.importDarts(inputStream); verify(dartsService).saveAll(createExpectedDarts()); }
@Test public void importedSameDartsWithSameVersionMakeNoChanges() { when(dartsExtractor.extract(inputStream)).thenReturn(dartsWithSameVersionWithSameQuantity()); when(dartsService.getDartsTable()).thenReturn(dartsToTable(existingDarts())); defaultDartsImporter.importDarts(inputStream); verify(dartsService).update(getEmptyDarts()); verify(dartsService).saveAll(getEmptyDarts()); }
@Test public void ifCompletelyNewDartsIsImportedNoExistingWereDeleted() { List<Dart> completelyNewDarts = completelyNewDarts(); when(dartsExtractor.extract(inputStream)).thenReturn(completelyNewDarts); when(dartsService.getDartsTable()).thenReturn(dartsToTable(createExpectedDarts())); defaultDartsImporter.importDarts(inputStream); verify(dartsService).saveAll(completelyNewDarts); verify(dartsService).update(getEmptyDarts()); }
@Test public void quantityIsRecountedCorrectlyWhenDartsWithNewVersionImported() { when(dartsExtractor.extract(inputStream)) .thenReturn(dartsWithNewVersionWithDifferentQuantity()); when(dartsService.getDartsTable()).thenReturn(dartsToTable(existingDarts())); defaultDartsImporter.importDarts(inputStream); List<Dart> existingDarts = existingDarts(); List<Dart> importedDarts = dartsWithNewVersionWithDifferentQuantity(); Dart firstDart = importedDarts.get(0); Dart existingFirstDart = existingDarts.get(0); int recountedQuantity = existingFirstDart.getQuantity() + (firstDart.getQuantityInitial() - existingFirstDart.getQuantityInitial()); firstDart.setQuantity(recountedQuantity); verify(dartsService).update(importedDarts); verify(dartsService).saveAll(getEmptyDarts()); }