1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-10-03 09:19:06 +00:00

Merge pull request #733 from matthew16550/more-PlantUmlTestUtils

Add more to PlantUmlTestUtils
This commit is contained in:
arnaudroques 2021-10-29 09:52:42 +02:00 committed by GitHub
commit 81cd784421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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