From b892d40b014f2dbaef245101c33f77db6499b6c1 Mon Sep 17 00:00:00 2001 From: Paul Sterl Date: Fri, 15 Dec 2023 11:36:49 +0100 Subject: [PATCH] extended tests --- .../org/sterl/svg2png/MainConfigTest.java | 107 ++++++++++++++++++ src/test/java/org/sterl/svg2png/MainTest.java | 38 ------- .../svg2png/config/TestFileConfigParsing.java | 57 ---------- 3 files changed, 107 insertions(+), 95 deletions(-) create mode 100644 src/test/java/org/sterl/svg2png/MainConfigTest.java delete mode 100644 src/test/java/org/sterl/svg2png/MainTest.java diff --git a/src/test/java/org/sterl/svg2png/MainConfigTest.java b/src/test/java/org/sterl/svg2png/MainConfigTest.java new file mode 100644 index 0000000..16a575e --- /dev/null +++ b/src/test/java/org/sterl/svg2png/MainConfigTest.java @@ -0,0 +1,107 @@ +package org.sterl.svg2png; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.sterl.svg2png.TestUtil.svgPath; + +import java.net.URISyntaxException; + +import org.apache.commons.cli.ParseException; +import org.junit.jupiter.api.Test; +import org.sterl.svg2png.config.FileOutput; +import org.sterl.svg2png.config.OutputConfig; + +class MainConfigTest extends AbstractFileTest { + + /** + * https://github.com/sterlp/svg2png/issues/21 + */ + @Test + void testBug21() throws Exception { + // WHEN + final OutputConfig config = buildOutputConfigForJson("/Bug21-config.json"); + + // THEN + for (FileOutput f : config.getFiles()) { + assertNotEquals(f.getWidth(), -1); + assertNotEquals(f.getHeight(), -1); + } + assertEquals(config.getFiles().get(0).getWidth(), 16); + assertEquals(config.getFiles().get(0).getHeight(), 16); + + assertEquals(config.getFiles().get(1).getWidth(), 38); + assertEquals(config.getFiles().get(1).getHeight(), 32); + } + + @Test + void testWidthAndHightOverrides() throws Exception { + // WHEN + OutputConfig config = Main.buildOutputConfig(new String[] { + "-f", svgPath("sample.svg"), + "-c", getClass().getResource("/Bug21-config.json").toURI().toString(), + "-w", "128", + "-h", "128", + "-o", "./" }); + + // THEN + for (FileOutput f : config.getFiles()) { + assertEquals(f.getWidth(), 128); + assertEquals(f.getHeight(), 128); + } + } + + @Test + void testAndroid() throws Exception { + // WHEN + final OutputConfig config = buildOutputConfigForJson("/android.json"); + assertEquals(5, config.getFiles().size()); + assertEquals(192, config.getFiles().get(0).getHeight()); + assertEquals(192, config.getFiles().get(0).getWidth()); + assertEquals("drawable-xxxhdpi", config.getFiles().get(0).getDirectory()); + } + + @Test + void testAndroidSmall() throws Exception { + // WHEN + final OutputConfig config = buildOutputConfigForJson("/android-small.json"); + assertEquals(5, config.getFiles().size()); + assertEquals(96, config.getFiles().get(0).getHeight()); + assertEquals(96, config.getFiles().get(0).getWidth()); + assertEquals("drawable-xxxhdpi", config.getFiles().get(0).getDirectory()); + } + + @Test + void testAndroidIcon() throws Exception { + // WHEN + final OutputConfig config = buildOutputConfigForJson("/android-icon.json"); + // THEN + + assertEquals(5, config.getFiles().size()); + assertEquals(192, config.getFiles().get(0).getHeight()); + assertEquals(192, config.getFiles().get(0).getWidth()); + assertEquals("drawable-xxxhdpi", config.getFiles().get(0).getDirectory()); + } + + @Test + void testIos() throws Exception { + // WHEN + final OutputConfig config = buildOutputConfigForJson("/ios.json"); + // THEN + + assertEquals(15, config.getFiles().size()); + assertEquals(20, config.getFiles().get(0).getHeight()); + assertEquals(20, config.getFiles().get(0).getWidth()); + assertEquals("ffffff", config.getNoAlpha()); + assertTrue(config.isContentsJson()); + assertNull(config.getFiles().get(0).getDirectory()); + } + + private OutputConfig buildOutputConfigForJson(String file) throws ParseException, URISyntaxException { + return Main.buildOutputConfig(new String[] { + "-f", svgPath("sample.svg"), + "-c", getClass().getResource(file).toURI().toString(), + "-o", "./" }); + } +} diff --git a/src/test/java/org/sterl/svg2png/MainTest.java b/src/test/java/org/sterl/svg2png/MainTest.java deleted file mode 100644 index f2d1ba2..0000000 --- a/src/test/java/org/sterl/svg2png/MainTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.sterl.svg2png; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.sterl.svg2png.TestUtil.svgPath; - -import org.junit.jupiter.api.Test; -import org.sterl.svg2png.config.FileOutput; -import org.sterl.svg2png.config.OutputConfig; - -class MainTest extends AbstractFileTest { - - /** - * https://github.com/sterlp/svg2png/issues/21 - */ - @Test - public void testBug21() throws Exception { - // WHEN - final OutputConfig config = Main.buildOutputConfig(new String[] { - "-f", - svgPath("sample.svg"), - "-c", - getClass().getResource("/Bug21-config.json").toURI().toString(), - "-o", "./" - }); - - // THEN - for (FileOutput f : config.getFiles()) { - assertNotEquals(f.getWidth(), -1); - assertNotEquals(f.getHeight(), -1); - } - assertEquals(config.getFiles().get(0).getWidth(), 16); - assertEquals(config.getFiles().get(0).getHeight(), 16); - - assertEquals(config.getFiles().get(1).getWidth(), 38); - assertEquals(config.getFiles().get(1).getHeight(), 32); - } -} diff --git a/src/test/java/org/sterl/svg2png/config/TestFileConfigParsing.java b/src/test/java/org/sterl/svg2png/config/TestFileConfigParsing.java index 32eceaf..50f7388 100644 --- a/src/test/java/org/sterl/svg2png/config/TestFileConfigParsing.java +++ b/src/test/java/org/sterl/svg2png/config/TestFileConfigParsing.java @@ -1,68 +1,11 @@ package org.sterl.svg2png.config; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.InputStream; import org.junit.jupiter.api.Test; -import com.fasterxml.jackson.databind.ObjectMapper; - public class TestFileConfigParsing { - private final ObjectMapper m = new ObjectMapper(); - - @Test - public void testAndroid() throws Exception { - System.err.println(getClass().getResourceAsStream("./android.json")); - try (InputStream is = getClass().getResourceAsStream("/android.json")) { - OutputConfig config = m.readerFor(OutputConfig.class).readValue(is); - assertEquals(5, config.getFiles().size()); - assertEquals(192, config.getFiles().get(0).getHeight()); - assertEquals(192, config.getFiles().get(0).getWidth()); - assertEquals("drawable-xxxhdpi", config.getFiles().get(0).getDirectory()); - } - } - - @Test - public void testAndroidSmall() throws Exception { - try (InputStream is = getClass().getResourceAsStream("/android-small.json")) { - OutputConfig config = m.readerFor(OutputConfig.class).readValue(is); - assertEquals(5, config.getFiles().size()); - assertEquals(96, config.getFiles().get(0).getHeight()); - assertEquals(96, config.getFiles().get(0).getWidth()); - assertEquals("drawable-xxxhdpi", config.getFiles().get(0).getDirectory()); - } - } - - @Test - public void testAndroidIcon() throws Exception { - try (InputStream is = getClass().getResourceAsStream("/android-icon.json")) { - OutputConfig config = m.readerFor(OutputConfig.class).readValue(is); - - assertEquals(5, config.getFiles().size()); - assertEquals(192, config.getFiles().get(0).getHeight()); - assertEquals(192, config.getFiles().get(0).getWidth()); - assertEquals("drawable-xxxhdpi", config.getFiles().get(0).getDirectory()); - } - } - - @Test - public void testIos() throws Exception { - try (InputStream is = getClass().getResourceAsStream("/ios.json")) { - OutputConfig config = m.readerFor(OutputConfig.class).readValue(is); - - assertEquals(15, config.getFiles().size()); - assertEquals(20, config.getFiles().get(0).getHeight()); - assertEquals(20, config.getFiles().get(0).getWidth()); - assertEquals("ffffff", config.getNoAlpha()); - assertTrue(config.isContentsJson()); - assertNull(config.getFiles().get(0).getDirectory()); - } - } - @Test public void testNameGeneration() { assertEquals("foo.png", FileOutput.buildName("foo", null, null, null));