Fixing wrong json imports

This commit is contained in:
Marcin Grzejszczak
2019-06-28 09:36:43 +02:00
parent 972a50265f
commit e792670c7b
6 changed files with 3 additions and 95 deletions

View File

@@ -43,7 +43,7 @@ class ImportsBuilder {
}
ImportsBuilder json() {
this.parentBuilder.imports(new JsonImports(builder, metaData),
this.parentBuilder.imports(
new JsonPathImports(builder, metaData));
this.parentBuilder.staticImports(new DefaultJsonStaticImports(builder, metaData));
return this;

View File

@@ -1,52 +0,0 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.builder;
import java.util.Arrays;
import org.springframework.cloud.contract.verifier.file.SingleContractMetadata;
class JsonImports implements Imports {
private final BlockBuilder blockBuilder;
private final GeneratedClassMetaData generatedClassMetaData;
private static final String[] IMPORTS = { "org.junit.FixMethodOrder",
"org.junit.runners.MethodSorters" };
JsonImports(BlockBuilder blockBuilder,
GeneratedClassMetaData generatedClassMetaData) {
this.blockBuilder = blockBuilder;
this.generatedClassMetaData = generatedClassMetaData;
}
@Override
public Imports call() {
Arrays.stream(IMPORTS)
.forEach(s -> this.blockBuilder.addLineWithEnding("import " + s));
return this;
}
@Override
public boolean accept() {
return this.generatedClassMetaData.listOfFiles.stream()
.anyMatch(metadata -> metadata.getConvertedContractWithMetadata().stream()
.anyMatch(SingleContractMetadata::isJson));
}
}

View File

@@ -408,8 +408,8 @@ class JsonToJsonPathsConverter {
addArraySizeCheck(key, value, closure)
}
else {
if (log.isDebugEnabled()) {
log.debug("Turning off the incubating feature of JSON array check. "
if (log.isTraceEnabled()) {
log.trace("Turning off the incubating feature of JSON array check. "
+
"System property [$systemPropValue]. Config property [$configPropValue]")
}

View File

@@ -356,8 +356,6 @@ class ContractHttpDocsSpec extends Specification {
"""\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification

View File

@@ -51,8 +51,6 @@ public class GeneratedTestClassTests {
String expectedTest = "package test;\n"
+ "\n"
+ "import BazBar;\n"
+ "import org.junit.FixMethodOrder;\n"
+ "import org.junit.runners.MethodSorters;\n"
+ "import com.jayway.jsonpath.DocumentContext;\n"
+ "import com.jayway.jsonpath.JsonPath;\n"
+ "import org.junit.Test;\n"

View File

@@ -102,8 +102,6 @@ class MessagingMethodBodyBuilderSpec extends Specification {
'''\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -175,8 +173,6 @@ class FooSpec extends Specification {
'''\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -258,8 +254,6 @@ public class FooTest {
"""\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -343,8 +337,6 @@ class FooSpec extends Specification {
'''\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -423,8 +415,6 @@ public class FooTest {
"""\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -491,8 +481,6 @@ class FooSpec extends Specification {
"""\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -563,8 +551,6 @@ public class FooTest {
"""\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -639,8 +625,6 @@ public class FooTest {
"""\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -722,8 +706,6 @@ class FooSpec extends Specification {
'''
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -800,8 +782,6 @@ public class FooTest {
"""\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -1010,8 +990,6 @@ public class FooTest {
"""\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -1082,8 +1060,6 @@ class FooSpec extends Specification {
"""\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -1154,8 +1130,6 @@ class FooSpec extends Specification {
"""\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -1227,8 +1201,6 @@ class FooSpec extends Specification {
"""\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -1307,8 +1279,6 @@ public class FooTest {
"spock" | { properties.testFramework = TestFramework.SPOCK } | """\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -1349,8 +1319,6 @@ class FooSpec extends Specification {
"junit" | { properties.testFramework = TestFramework.JUNIT } | """\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
@@ -1556,8 +1524,6 @@ public class FooTest {
"spock" | { properties.testFramework = TestFramework.SPOCK } | """\
package com.example
import org.junit.FixMethodOrder
import org.junit.runners.MethodSorters
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Specification
@@ -1611,8 +1577,6 @@ class FooSpec extends Specification {
"junit" | { properties.testFramework = TestFramework.JUNIT } | """\
package com.example;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;