Terms of Service | Privacy Policy | Cookie Policy

Commit d5f7ffa0 authored by Uwe Plonus's avatar Uwe Plonus

Added further tests for FileCodeData

parent 7d9593dd
Pipeline #426 canceled with stages
in 14 minutes and 52 seconds
......@@ -20,8 +20,10 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import org.sw4j.tool.barcode.random.config.CodeConfig;
import org.sw4j.tool.barcode.random.config.CodeType;
import org.sw4j.tool.barcode.random.config.Config;
import org.sw4j.tool.barcode.random.config.FileConfig;
import org.sw4j.tool.barcode.random.config.OutputConfig;
......@@ -39,6 +41,9 @@ import org.testng.annotations.Test;
*/
public class FileCodeDataNGTest {
private File outputFolder;
@BeforeClass
public static void setUpClass() throws Exception {
}
......@@ -49,10 +54,12 @@ public class FileCodeDataNGTest {
@BeforeMethod
public void setUpMethod() throws Exception {
outputFolder = new File("target/output");
}
@AfterMethod
public void tearDownMethod() throws Exception {
outputFolder.delete();
}
@Test
......@@ -93,7 +100,7 @@ public class FileCodeDataNGTest {
.build())
.build();
FileCodeData codeData = new FileCodeData(config);
InputStream is = codeData.getInput();
codeData.getInput();
fail("Expected a FileNotFoundException to be thrown.");
}
......@@ -115,9 +122,76 @@ public class FileCodeDataNGTest {
.build();
FileCodeData codeData = new FileCodeData(config);
codeData.getOutput();
File outputFolder = new File("target/output");
assertTrue(outputFolder.exists(), "OutputFolder should exist.");
assertTrue(outputFolder.isDirectory(), "OutputFolder should be folder.");
}
@Test
public void getOutputCreatesFile() throws IOException {
Config config = Config.builder()
.setInput(FileConfig.builder().setName("src/test/data/testdata.csv").build())
.setOutput(OutputConfig.builder()
.setFolder("target/output")
.setFile(FileConfig.builder().setName("output.csv").build()).build())
.setRandom(RandomConfig.builder()
.setSize(128)
.setCodes(Arrays.asList(CodeConfig.builder()
.setType("qrcode")
.setEncoding("hex")
.build()
))
.build())
.build();
FileCodeData codeData = new FileCodeData(config);
OutputStream os = codeData.getOutput();
assertNotNull(os, "Expected an OutputStream to be created.");
File outputFile = new File(outputFolder, "output.csv");
assertTrue(outputFile.exists(), "Expected an output file to be created.");
}
@Test
public void getOutputForIdentCreatesFolder() throws IOException {
Config config = Config.builder()
.setInput(FileConfig.builder().setName("src/test/data/testdata.csv").build())
.setOutput(OutputConfig.builder()
.setFolder("target/output")
.setFile(FileConfig.builder().setName("output.csv").build()).build())
.setRandom(RandomConfig.builder()
.setSize(128)
.setCodes(Arrays.asList(CodeConfig.builder()
.setType("qrcode")
.setEncoding("hex")
.build()
))
.build())
.build();
FileCodeData codeData = new FileCodeData(config);
codeData.getOutputForIdent(CodeType.QRCODE, "hex", "0000", "png");
assertTrue(outputFolder.exists(), "OutputFolder should exist.");
assertTrue(outputFolder.isDirectory(), "OutputFolder should be folder.");
}
@Test
public void getOutputForIdentCreatesFile() throws IOException {
Config config = Config.builder()
.setInput(FileConfig.builder().setName("src/test/data/testdata.csv").build())
.setOutput(OutputConfig.builder()
.setFolder("target/output")
.setFile(FileConfig.builder().setName("output.csv").build()).build())
.setRandom(RandomConfig.builder()
.setSize(128)
.setCodes(Arrays.asList(CodeConfig.builder()
.setType("qrcode")
.setEncoding("hex")
.build()
))
.build())
.build();
FileCodeData codeData = new FileCodeData(config);
OutputStream os = codeData.getOutputForIdent(CodeType.QRCODE, "hex", "0000", "png");
assertNotNull(os, "Expected an OutputStream to be created.");
File outputFile = new File(outputFolder, "qrcode-hex-0000.png");
assertTrue(outputFile.exists(), "Expected an output file to be created.");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment