Skip to content

Commit a3fbd54

Browse files
committed
Optimized tests for loading null or empty values
1 parent b34bb2c commit a3fbd54

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

wrappers/serializer/src/test/java/it/angrybear/yagl/wrappers/WrapperParserTest.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,36 @@
1010
import org.jetbrains.annotations.NotNull;
1111
import org.jetbrains.annotations.Nullable;
1212
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.params.ParameterizedTest;
14+
import org.junit.jupiter.params.provider.MethodSource;
1315

1416
import java.io.File;
1517
import java.io.IOException;
1618
import java.lang.reflect.Field;
1719
import java.util.List;
1820

1921
import static org.junit.jupiter.api.Assertions.*;
22+
import static org.mockito.ArgumentMatchers.any;
2023
import static org.mockito.Mockito.mock;
24+
import static org.mockito.Mockito.when;
2125

2226
class WrapperParserTest {
2327

24-
@Test
25-
void testLoadNull() throws IOException {
26-
List<Wrapper> actual = load(getFile("wrapper"), "wrapper", Wrapper.class);
27-
assertNotNull(actual);
28-
for (Wrapper w : actual) assertNull(w);
28+
private static Object[] invalidSaves() {
29+
return new Object[]{null, "", " "};
30+
}
31+
32+
@ParameterizedTest
33+
@MethodSource("invalidSaves")
34+
void testLoadNull(String save) throws Exception {
35+
IConfiguration configuration = mock(IConfiguration.class);
36+
when(configuration.getString(any())).thenReturn(save);
37+
assertNull(new WrapperParser<>(Enchantment.class).getLoader().apply(configuration, "path"));
2938
}
3039

31-
@SuppressWarnings({"rawtypes", "unchecked"})
3240
@Test
3341
void testSaveNull() {
34-
assertDoesNotThrow(() -> new WrapperParser(Enchantment.class).getDumper()
42+
assertDoesNotThrow(() -> new WrapperParser<>(Enchantment.class).getDumper()
3543
.accept(mock(IConfiguration.class), "enchantment", null));
3644
}
3745

0 commit comments

Comments
 (0)