mirror of
https://gitee.com/BDWare/MockJava
synced 2025-01-10 01:44:06 +00:00
build: config spotless plugin and reformat code
This commit is contained in:
parent
7447d5a079
commit
97ddefab68
@ -5,6 +5,8 @@ plugins {
|
||||
id 'signing'
|
||||
}
|
||||
|
||||
apply from: '../spotless.gradle'
|
||||
|
||||
group 'org.bdware.mockjava'
|
||||
version '0.5.0'
|
||||
|
||||
|
@ -14,22 +14,26 @@ public class MockGenerator extends JsonVisitor {
|
||||
public static MockGenerator instance = new MockGenerator();
|
||||
Map<String, ValueGenerator> prefixToGenerator;
|
||||
JsonElement result;
|
||||
|
||||
public JsonElement get() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public MockGenerator(Class... clzs) {
|
||||
prefixToGenerator = new HashMap<>();
|
||||
for (Class clz : clzs) {
|
||||
Generator generator = (Generator) clz.getAnnotation(Generator.class);
|
||||
if (generator != null) {
|
||||
try {
|
||||
prefixToGenerator.put(generator.tag(),(ValueGenerator)clz.getConstructor().newInstance());
|
||||
prefixToGenerator.put(generator.tag(),
|
||||
(ValueGenerator) clz.getConstructor().newInstance());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonVisitor visitObject(JsonObject jsonObject) {
|
||||
JsonObject jo = new JsonObject();
|
||||
@ -59,7 +63,8 @@ public class MockGenerator extends JsonVisitor {
|
||||
|
||||
@Override
|
||||
public JsonVisitor visitPrimitive(JsonPrimitive primitive) {
|
||||
if (!primitive.isString()) result = primitive.deepCopy();
|
||||
if (!primitive.isString())
|
||||
result = primitive.deepCopy();
|
||||
ValueGenerator generator = lookupGenerator(primitive.getAsString());
|
||||
result = generator.generate(primitive);
|
||||
return this;
|
||||
|
@ -18,8 +18,7 @@ public class MockUtil {
|
||||
static {
|
||||
MOCK_JS_ENGINE = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
// System.out.println(MOCK_JS_ENGINE);
|
||||
try (InputStream mockJs =
|
||||
MockUtil.class.getClassLoader().getResourceAsStream(MOCK_JS_PATH);
|
||||
try (InputStream mockJs = MockUtil.class.getClassLoader().getResourceAsStream(MOCK_JS_PATH);
|
||||
InputStreamReader reader = new InputStreamReader(mockJs)) {
|
||||
MOCK_JS_ENGINE.eval(reader);
|
||||
} catch (ScriptException | IOException e) {
|
||||
@ -58,7 +57,8 @@ public class MockUtil {
|
||||
}
|
||||
|
||||
public static JsonElement parseJsonSchema(JsonElement ele) {
|
||||
if (ele == null) return null;
|
||||
if (ele == null)
|
||||
return null;
|
||||
if (ele.isJsonPrimitive()) {
|
||||
JsonPrimitive primitive = ele.getAsJsonPrimitive();
|
||||
if (primitive.isBoolean()) {
|
||||
|
@ -10,7 +10,9 @@ import java.util.Random;
|
||||
@Generator(tag = "@integer")
|
||||
public class IntegerGenerator extends ValueGenerator {
|
||||
public IntegerGenerator() {}
|
||||
|
||||
static Random secureRandom = new SecureRandom();
|
||||
|
||||
@Override
|
||||
public JsonElement generate(JsonElement previous) {
|
||||
// TODO parse value here
|
||||
|
Loading…
Reference in New Issue
Block a user