Skip to content

Commit f2341ce

Browse files
committed
add tests
1 parent 2c4d161 commit f2341ce

3 files changed

Lines changed: 50 additions & 8 deletions

File tree

src/test/java/org/spacious_team/table_wrapper/api/StringPrefixPredicateTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static Object[][] prefixAndMatchingString() {
4848

4949
static Object[][] prefixAndNotMatchingSting() {
5050
return new Object[][]{
51+
{"First", " \n\r\n\t"},
5152
{"First", "One two"},
5253
{"first", "fir st two"},
5354
{"first", "zero first"},

src/test/java/org/spacious_team/table_wrapper/api/TableCellTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.math.BigDecimal;
2828
import java.time.Instant;
2929
import java.time.LocalDateTime;
30+
import java.time.ZoneOffset;
3031

3132
import static org.junit.jupiter.api.Assertions.assertEquals;
3233
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -49,7 +50,8 @@ void getValueOrDefaultExceptionally() {
4950
Object expectedDefault = new Object();
5051
doThrow(RuntimeException.class).when(cell).getValue();
5152

52-
@Nullable Object result = cell.getValueOrDefault(expectedDefault);
53+
@SuppressWarnings("DataFlowIssue") @Nullable
54+
Object result = cell.getValueOrDefault(expectedDefault);
5355

5456
assertSame(expectedDefault, result);
5557
verify(cell).getValue();
@@ -203,4 +205,28 @@ void getLocalDateTimeValueOrDefaultExceptionally() {
203205
assertSame(expectedDefault, result);
204206
verify(cell).getLocalDateTimeValue();
205207
}
208+
209+
@Test
210+
void getLocalDateTimeValueOnZoneIdOrDefault() {
211+
ZoneOffset expectedZone = ZoneOffset.UTC;
212+
LocalDateTime expected = LocalDateTime.now();
213+
doReturn(expected).when(cell).getLocalDateTimeValue(any());
214+
215+
LocalDateTime result = cell.getLocalDateTimeValueOrDefault(expectedZone, LocalDateTime.MIN);
216+
217+
assertEquals(expected, result);
218+
verify(cell).getLocalDateTimeValue(expectedZone);
219+
}
220+
221+
@Test
222+
void getZoneIdLocalDateTimeValueOnZoneIdOrDefaultExceptionally() {
223+
ZoneOffset expectedZone = ZoneOffset.UTC;
224+
LocalDateTime expectedDefault = LocalDateTime.now();
225+
doThrow(RuntimeException.class).when(cell).getLocalDateTimeValue(any());
226+
227+
LocalDateTime result = cell.getLocalDateTimeValueOrDefault(expectedZone, expectedDefault);
228+
229+
assertSame(expectedDefault, result);
230+
verify(cell).getLocalDateTimeValue(expectedZone);
231+
}
206232
}

src/test/java/org/spacious_team/table_wrapper/api/TableRowTest.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.math.BigDecimal;
2828
import java.time.Instant;
2929
import java.time.LocalDateTime;
30+
import java.time.ZoneOffset;
3031

3132
import static org.junit.jupiter.api.Assertions.assertEquals;
3233
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -124,28 +125,42 @@ void getStringCellValueOrDefaultThrowable() {
124125
@Test
125126
void getInstantCellValueOrDefault() {
126127
Instant expectedInstant = Instant.now();
127-
when(row.getInstantCellValue(any())).thenThrow(RuntimeException.class);
128-
assertSame(expectedInstant, row.getInstantCellValueOrDefault(column, expectedInstant));
128+
when(row.getInstantCellValue(any())).thenReturn(expectedInstant);
129+
assertSame(expectedInstant, row.getInstantCellValueOrDefault(column, Instant.MIN));
129130
}
130131

131132
@Test
132133
void getInstantCellValueOrDefaultThrowable() {
133134
Instant expectedInstant = Instant.now();
134-
when(row.getInstantCellValue(any())).thenReturn(expectedInstant);
135-
assertSame(expectedInstant, row.getInstantCellValueOrDefault(column, Instant.MIN));
135+
when(row.getInstantCellValue(any())).thenThrow(RuntimeException.class);
136+
assertSame(expectedInstant, row.getInstantCellValueOrDefault(column, expectedInstant));
136137
}
137138

138139
@Test
139140
void getLocalDateTimeCellValueOrDefault() {
141+
LocalDateTime expectedLocalDateTime = LocalDateTime.now();
142+
when(row.getLocalDateTimeCellValue(any())).thenReturn(expectedLocalDateTime);
143+
assertSame(expectedLocalDateTime, row.getLocalDateTimeCellValueOrDefault(column, LocalDateTime.MIN));
144+
}
145+
146+
@Test
147+
void getLocalDateTimeCellValueOrDefaultThrowable() {
140148
LocalDateTime expectedLocalDateTime = LocalDateTime.now();
141149
when(row.getLocalDateTimeCellValue(any())).thenThrow(RuntimeException.class);
142150
assertSame(expectedLocalDateTime, row.getLocalDateTimeCellValueOrDefault(column, expectedLocalDateTime));
143151
}
144152

145153
@Test
146-
void getLocalDateTimeCellValueOrDefaultThrowable() {
154+
void getLocalDateTimeCellValueOnZoneIdOrDefault() {
147155
LocalDateTime expectedLocalDateTime = LocalDateTime.now();
148-
when(row.getLocalDateTimeCellValue(any())).thenReturn(expectedLocalDateTime);
149-
assertSame(expectedLocalDateTime, row.getLocalDateTimeCellValueOrDefault(column, LocalDateTime.MIN));
156+
when(row.getLocalDateTimeCellValue(any(), any())).thenReturn(expectedLocalDateTime);
157+
assertSame(expectedLocalDateTime, row.getLocalDateTimeCellValueOrDefault(column, ZoneOffset.UTC, LocalDateTime.MIN));
158+
}
159+
160+
@Test
161+
void getLocalDateTimeCellValueOnZoneIdOrDefaultThrowable() {
162+
LocalDateTime expectedLocalDateTime = LocalDateTime.now();
163+
when(row.getLocalDateTimeCellValue(any(), any())).thenThrow(RuntimeException.class);
164+
assertSame(expectedLocalDateTime, row.getLocalDateTimeCellValueOrDefault(column, ZoneOffset.UTC, expectedLocalDateTime));
150165
}
151166
}

0 commit comments

Comments
 (0)