예제 #1
0
  @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());
  }
예제 #2
0
  @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());
  }
예제 #3
0
  @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());
  }
예제 #4
0
  @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());
  }