mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-20 04:00:53 +00:00
Merge pull request #733 from matthew16550/more-PlantUmlTestUtils
Add more to PlantUmlTestUtils
This commit is contained in:
commit
81cd784421
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user