tests for golden png

This commit is contained in:
2026-06-13 08:58:51 +02:00
parent f85a68d9fc
commit e2798b26cf
41 changed files with 1127 additions and 1039 deletions

View File

@@ -17,6 +17,11 @@ public class Dot implements StateMachineExporter {
"blue", "green", "red", "purple", "orange", "brown", "darkgreen", "darkblue"
};
@Override
public String export(click.kamil.springstatemachineexporter.analysis.model.AnalysisResult result, ExportOptions options) {
return export(result.getName(), result.getTransitions(), result.getStartStates(), result.getEndStates(), options);
}
@Override
public String export(String name,
List<Transition> transitions,

View File

@@ -17,6 +17,11 @@ public class JsonExporter implements StateMachineExporter {
.enable(SerializationFeature.INDENT_OUTPUT);
}
@Override
public String export(click.kamil.springstatemachineexporter.analysis.model.AnalysisResult result, ExportOptions options) {
return export(result.getName(), result.getTransitions(), result.getStartStates(), result.getEndStates(), options);
}
@Override
public String export(String name, List<Transition> transitions, Set<String> startStates, Set<String> endStates, ExportOptions options) {
try {

View File

@@ -33,6 +33,23 @@ public class PlantUml implements StateMachineExporter {
}
}
@Override
public String export(click.kamil.springstatemachineexporter.analysis.model.AnalysisResult result, ExportOptions options) {
String baseContent = export(result.getName(), result.getTransitions(), result.getStartStates(), result.getEndStates(), options);
// Allow custom styling from metadata
String customStyle = result.getMetadata().getProperties().get("plantuml.style");
if (customStyle != null && !customStyle.isBlank()) {
// Insert custom style before @enduml
int endumlIndex = baseContent.lastIndexOf("@enduml");
if (endumlIndex >= 0) {
return baseContent.substring(0, endumlIndex) + "\n" + customStyle + "\n" + baseContent.substring(endumlIndex);
}
}
return baseContent;
}
@Override
public String export(String name,
List<Transition> transitions,
@@ -63,7 +80,7 @@ public class PlantUml implements StateMachineExporter {
}
sb.append("\n");
Set<String> statesWithChoice = new HashSet<>();
Set<String> statesWithChoice = new java.util.LinkedHashSet<>();
for (Transition t : transitions) {
if (t.getType() == TransitionType.CHOICE) {
for (State source : t.getSourceStates()) {
@@ -88,7 +105,7 @@ public class PlantUml implements StateMachineExporter {
.filter(t -> t.getType() == TransitionType.JUNCTION)
.flatMap(t -> t.getSourceStates().stream())
.map(s -> simplify(s.toString()))
.collect(Collectors.toSet());
.collect(Collectors.toCollection(java.util.LinkedHashSet::new));
for (String junction : junctionStates) {
if (options.isRenderChoicesAsDiamonds()) {
sb.append("state ").append(junction).append(" <<choice>>\n");
@@ -97,7 +114,7 @@ public class PlantUml implements StateMachineExporter {
sb.append("\n");
Set<String> usedEventStereotypes = new HashSet<>();
Set<String> usedEventStereotypes = new java.util.LinkedHashSet<>();
for (Transition t : transitions) {
if (t.getSourceStates() == null || t.getSourceStates().isEmpty())
continue;

View File

@@ -12,6 +12,11 @@ public class Scxml implements StateMachineExporter {
private static final String LAMBDA = "λ";
@Override
public String export(click.kamil.springstatemachineexporter.analysis.model.AnalysisResult result, ExportOptions options) {
return export(result.getName(), result.getTransitions(), result.getStartStates(), result.getEndStates(), options);
}
@Override
public String export(String name,
List<Transition> transitions,
@@ -24,7 +29,7 @@ public class Scxml implements StateMachineExporter {
sb.append(startStates.isEmpty() ? "" : simplify(startStates.iterator().next()));
sb.append("\">\n");
Set<String> allStates = new HashSet<>();
Set<String> allStates = new java.util.LinkedHashSet<>();
for (Transition t : transitions) {
t.getSourceStates().forEach(s -> allStates.add(s.toString()));
t.getTargetStates().forEach(s -> allStates.add(s.toString()));

View File

@@ -1,11 +1,16 @@
package click.kamil.springstatemachineexporter.exporter;
import click.kamil.springstatemachineexporter.analysis.model.AnalysisResult;
import click.kamil.springstatemachineexporter.model.Transition;
import java.util.List;
import java.util.Set;
public interface StateMachineExporter {
default String export(AnalysisResult result, ExportOptions options) {
return export(result.getName(), result.getTransitions(), result.getStartStates(), result.getEndStates(), options);
}
String export(String name,
List<Transition> transitions,
Set<String> startStates,

View File

@@ -152,7 +152,7 @@ public class ExportService {
if (!match) continue;
}
String content = output.export(result.getName(), result.getTransitions(), result.getStartStates(), result.getEndStates(), options);
String content = output.export(result, options);
String fileName = result.getName() + output.getFileExtension();
try (PrintWriter out = new PrintWriter(targetDir.resolve(fileName).toFile())) {