1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 23:50:49 +00:00

Add more to PlantUmlTestUtils

This commit is contained in:
matthew16550 2021-10-29 15:36:37 +11:00
parent 7141113050
commit a01da1a773

View File

@ -1,11 +1,14 @@
package net.sourceforge.plantuml.test;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import net.sourceforge.plantuml.BlockUml;
@ -28,6 +31,7 @@ public class PlantUmlTestUtils {
return new ExportDiagram(diagram);
}
@SuppressWarnings("unused")
public static class ExportDiagram {
private final Diagram diagram;
private boolean metadata;
@ -36,6 +40,12 @@ public class PlantUmlTestUtils {
this.diagram = diagram;
}
public ExportDiagram assertDiagramType(Class<? extends Diagram> klass) {
assertNoError();
assertThat(diagram).isInstanceOf(klass);
return this;
}
public ExportDiagram assertNoError() {
if (diagram instanceof PSystemError) {
final PSystemError error = (PSystemError) this.diagram;
@ -51,7 +61,11 @@ public class PlantUmlTestUtils {
}
public BufferedImage asImage() throws IOException {
return SImageIO.read(asByteArray(FileFormat.PNG));
return asImage(FileFormat.PNG);
}
public BufferedImage asImage(FileFormat fileFormat) throws IOException {
return SImageIO.read(asByteArray(fileFormat));
}
public String asString() throws IOException {
@ -68,6 +82,12 @@ public class PlantUmlTestUtils {
return this;
}
public ExportDiagram toFile(Path path, FileFormat fileFormat) throws IOException {
try (OutputStream os = Files.newOutputStream(path)) {
return stream(os, fileFormat);
}
}
public ExportDiagram withMetadata(boolean metadata) {
this.metadata = metadata;
return this;