Added checkstyle for tests

This commit is contained in:
Marcin Grzejszczak
2019-02-03 15:34:10 +01:00
parent e4b08a083c
commit c6ddfe1af4
61 changed files with 273 additions and 228 deletions

View File

@@ -35,10 +35,6 @@ public final class HeaderUtils {
private static HttpHeaders REQUEST_ONLY = new HttpHeaders();
private HeaderUtils() {
throw new IllegalStateException("Can't instantiate a utility class");
}
static {
IGNORED.add(MessageHeaders.ID, "");
IGNORED.add(HttpHeaders.CONTENT_LENGTH, "0");
@@ -49,6 +45,10 @@ public final class HeaderUtils {
REQUEST_ONLY.add(HttpHeaders.HOST, "");
}
private HeaderUtils() {
throw new IllegalStateException("Can't instantiate a utility class");
}
public static HttpHeaders fromMessage(MessageHeaders headers) {
HttpHeaders result = new HttpHeaders();
for (String name : headers.keySet()) {

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.flux;
import java.net.URI;
@@ -62,7 +63,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*
*/
@RunWith(SpringRunner.class)
// @checkstyle:off
@SpringBootTest(classes = TestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=reactive")
// @checkstyle:on
public class FluxRestApplicationTests {
private static final MediaType EVENT_STREAM = MediaType.valueOf("text/event-stream");

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.mvc;
import java.net.URI;
@@ -60,7 +61,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer
*
*/
// @checkstyle:off
@SpringBootTest(classes = TestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=servlet")
// @checkstyle:on
@RunWith(SpringRunner.class)
public class MvcRestApplicationTests {

View File

@@ -31,7 +31,7 @@ import org.springframework.cloud.function.context.test.FunctionalSpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
@@ -52,9 +52,9 @@ public class FunctionalWithInputSetTests {
String.class)
.exchange().expectStatus().isOk().expectBody(String.class).returnResult()
.getResponseBody();
assertTrue(reply.contains("FOO"));
assertTrue(reply.contains("BAR"));
assertTrue(reply.contains("{\"value\":\""));
assertThat(reply.contains("FOO")).isTrue();
assertThat(reply.contains("BAR")).isTrue();
assertThat(reply.contains("{\"value\":\"")).isTrue();
}
@SpringBootConfiguration

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.test;
import java.util.function.Function;

View File

@@ -74,10 +74,10 @@ class Foo {
private String value;
public Foo() {
Foo() {
}
public Foo(String value) {
Foo(String value) {
this.value = value;
}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.web.flux;
import java.net.URI;
@@ -37,8 +38,7 @@ import org.springframework.messaging.support.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
@@ -62,20 +62,20 @@ public class HeadersToMessageTests {
.exchange(RequestEntity.post(new URI("/functions/employee"))
.contentType(MediaType.APPLICATION_JSON)
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
assertEquals("application/xml",
postForEntity.getHeaders().get("x-content-type").get(0));
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
assertThat(postForEntity.getHeaders().containsKey("x-content-type")).isTrue();
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
.isEqualTo("application/xml");
assertThat(postForEntity.getHeaders().get("foo").get(0)).isEqualTo("bar");
// test simple type payload
postForEntity = this.rest.postForEntity(new URI("/functions/string"),
"{\"name\":\"Bob\",\"age\":25}", String.class);
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
assertEquals("application/xml",
postForEntity.getHeaders().get("x-content-type").get(0));
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
assertThat(postForEntity.getHeaders().containsKey("x-content-type")).isTrue();
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
.isEqualTo("application/xml");
assertThat(postForEntity.getHeaders().get("foo").get(0)).isEqualTo("bar");
}
@EnableAutoConfiguration

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.web.flux;
import java.net.URI;

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.web.flux;
import java.net.URI;

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.web.mvc;
import java.net.URI;
@@ -39,8 +40,7 @@ import org.springframework.messaging.support.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Oleg Zhurakousky
@@ -62,11 +62,11 @@ public class HeadersToMessageTests {
.exchange(RequestEntity.post(new URI("/functions/employee"))
.contentType(MediaType.APPLICATION_JSON)
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
assertEquals("application/xml",
postForEntity.getHeaders().get("x-content-type").get(0));
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
assertThat(postForEntity.getHeaders().containsKey("x-content-type")).isTrue();
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
.isEqualTo("application/xml");
assertThat(postForEntity.getHeaders().get("foo").get(0)).isEqualTo("bar");
}
@Test
@@ -76,10 +76,11 @@ public class HeadersToMessageTests {
.contentType(MediaType.APPLICATION_JSON)
.header("x-context-type", "rubbish")
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
assertEquals("{\"name\":\"Bob\",\"age\":25,\"foo\":\"bar\"}",
postForEntity.getBody());
assertTrue(postForEntity.getHeaders().containsKey("x-context-type"));
assertEquals("rubbish", postForEntity.getHeaders().get("x-context-type").get(0));
assertThat(postForEntity.getBody())
.isEqualTo("{\"name\":\"Bob\",\"age\":25,\"foo\":\"bar\"}");
assertThat(postForEntity.getHeaders().containsKey("x-context-type")).isTrue();
assertThat(postForEntity.getHeaders().get("x-context-type").get(0))
.isEqualTo("rubbish");
}
@EnableAutoConfiguration

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.web.mvc;
import java.net.URI;

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.web.mvc;
import java.net.URI;