From b4503cb34307b67ccc0babc3f4b5594789ce4c9f Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Thu, 4 Apr 2024 01:11:55 +0200 Subject: [PATCH] Added test suite for TypedParser --- .../yagl/parsers/TypedParserTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 common/serializer/src/test/java/it/angrybear/yagl/parsers/TypedParserTest.java diff --git a/common/serializer/src/test/java/it/angrybear/yagl/parsers/TypedParserTest.java b/common/serializer/src/test/java/it/angrybear/yagl/parsers/TypedParserTest.java new file mode 100644 index 00000000..0faa9c08 --- /dev/null +++ b/common/serializer/src/test/java/it/angrybear/yagl/parsers/TypedParserTest.java @@ -0,0 +1,47 @@ +package it.angrybear.yagl.parsers; + +import it.fulminazzo.yamlparser.configuration.ConfigurationSection; +import it.fulminazzo.yamlparser.configuration.IConfiguration; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class TypedParserTest { + private MockClassParser parser; + private IConfiguration configuration; + + @BeforeEach + void setUp() { + this.parser = new MockClassParser(); + this.configuration = mock(IConfiguration.class); + ConfigurationSection section = new ConfigurationSection(this.configuration, "name"); + when(this.configuration.getConfigurationSection(anyString())).thenReturn(section); + when(this.configuration.getString(anyString())).thenReturn(null); + } + + @Test + void testLoadWithNoType() { + assertThrowsExactly(IllegalArgumentException.class, () -> this.parser.load(this.configuration, "path")); + } + + @Test + void testDumpNullObject() { + assertDoesNotThrow(() -> this.parser.dump(this.configuration, "path", null)); + } + + private static class MockClassParser extends TypedParser { + + public MockClassParser() { + super(MockClass.class); + } + } + + private static class MockClass { + + } +} \ No newline at end of file