test: create `JunitUtils` to help test with Junit

- [x]  create `JunitUtils`to help test with Junit
  - create `StringJsonConverter` class to use with `@ConvertWith`
This commit is contained in:
The-Lum 2023-09-15 20:54:33 +00:00
parent 6781e85680
commit 3090643256
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package net.sourceforge.plantuml.test;
import org.junit.jupiter.params.converter.ArgumentConversionException;
import org.junit.jupiter.params.converter.SimpleArgumentConverter;
import net.sourceforge.plantuml.json.Json;
import net.sourceforge.plantuml.json.JsonValue;
/**
* Class to help test with `Junit`.
*/
public class JunitUtils {
/**
* `StringJsonConverter` class to use with `@ConvertWith`.
*/
public static class StringJsonConverter extends SimpleArgumentConverter {
@Override
protected Object convert(Object source, Class<?> targetType) throws ArgumentConversionException {
if (source instanceof String)
return (JsonValue) Json.parse((String) source);
else
throw new IllegalArgumentException("Conversion from " + source.getClass() + " to "
+ targetType + " not supported.");
}
}
}