View Javadoc
1   package de.aikiit.bilanzanalyser.reader;
2   
3   import de.aikiit.bilanzanalyser.entity.BilanzRow;
4   import org.junit.jupiter.api.Test;
5   
6   import java.util.List;
7   
8   import static org.junit.jupiter.api.Assertions.assertEquals;
9   import static org.junit.jupiter.api.Assertions.assertNotNull;
10  import static org.junit.jupiter.api.Assertions.assertThrows;
11  import static org.junit.jupiter.api.Assertions.assertTrue;
12  import static org.mockito.Mockito.mock;
13  
14  class BilanzRowParserResultTest {
15  
16      @Test
17      void constructor_shouldHandleNullRowsAsEmptyList() {
18          BilanzRowParserResult result = new BilanzRowParserResult(1, 2, null);
19  
20          assertNotNull(result.rows());
21          assertTrue(result.rows().isEmpty());
22      }
23  
24      @Test
25      void empty_shouldReturnZeroCountsAndEmptyList() {
26          BilanzRowParserResult result = BilanzRowParserResult.empty();
27  
28          assertEquals(0, result.errorCount());
29          assertEquals(0, result.rowCount());
30          assertNotNull(result.rows());
31          assertTrue(result.rows().isEmpty());
32      }
33  
34      @Test
35      void withError_shouldIncrementErrorCountOnly() {
36          BilanzRowParserResult original = new BilanzRowParserResult(1, 2, List.of());
37  
38          BilanzRowParserResult updated = original.withError();
39  
40          assertEquals(2, updated.errorCount());
41          assertEquals(2, updated.rowCount());
42          assertEquals(original.rows(), updated.rows());
43      }
44  
45      @Test
46      void withRow_shouldIncrementRowCountOnly() {
47          BilanzRowParserResult original = new BilanzRowParserResult(1, 2, List.of());
48  
49          BilanzRowParserResult updated = original.withRow();
50  
51          assertEquals(1, updated.errorCount());
52          assertEquals(3, updated.rowCount());
53          assertEquals(original.rows(), updated.rows());
54      }
55  
56      @Test
57      void withRows_shouldReplaceRows() {
58          BilanzRow row1 = mock(BilanzRow.class);
59          BilanzRow row2 = mock(BilanzRow.class);
60  
61          BilanzRowParserResult original = new BilanzRowParserResult(0, 0, List.of());
62  
63          BilanzRowParserResult updated = original.withRows(List.of(row1, row2));
64  
65          assertEquals(2, updated.rows().size());
66          assertTrue(updated.rows().containsAll(List.of(row1, row2)));
67      }
68  
69      @Test
70      void addRow_shouldAppendRow() {
71          BilanzRow row1 = mock(BilanzRow.class);
72          BilanzRow row2 = mock(BilanzRow.class);
73  
74          BilanzRowParserResult original = new BilanzRowParserResult(0, 0, List.of(row1));
75  
76          BilanzRowParserResult updated = original.addRow(row2);
77  
78          assertEquals(2, updated.rows().size());
79          assertEquals(row1, updated.rows().get(0));
80          assertEquals(row2, updated.rows().get(1));
81      }
82  
83      @Test
84      void rows_shouldBeImmutable() {
85          BilanzRow row = mock(BilanzRow.class);
86  
87          BilanzRowParserResult result = new BilanzRowParserResult(0, 0, List.of(row));
88  
89          assertThrows(UnsupportedOperationException.class, () -> result.rows().add(mock(BilanzRow.class)));
90      }
91  
92      @Test
93      void addRow_shouldNotMutateOriginalInstance() {
94          BilanzRow row1 = mock(BilanzRow.class);
95          BilanzRow row2 = mock(BilanzRow.class);
96  
97          BilanzRowParserResult original = new BilanzRowParserResult(0, 0, List.of(row1));
98  
99          BilanzRowParserResult updated = original.addRow(row2);
100 
101         assertEquals(1, original.rows().size());
102         assertEquals(2, updated.rows().size());
103     }
104 }