Skip to content

Commit

Permalink
extended tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sterlp committed Dec 15, 2023
1 parent c4cd245 commit b892d40
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 95 deletions.
107 changes: 107 additions & 0 deletions src/test/java/org/sterl/svg2png/MainConfigTest.java
Original file line number Diff line number Diff line change
@@ -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", "./" });
}
}
38 changes: 0 additions & 38 deletions src/test/java/org/sterl/svg2png/MainTest.java

This file was deleted.

57 changes: 0 additions & 57 deletions src/test/java/org/sterl/svg2png/config/TestFileConfigParsing.java
Original file line number Diff line number Diff line change
@@ -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));
Expand Down

0 comments on commit b892d40

Please sign in to comment.