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

@@ -53,25 +53,25 @@ public class SampleApplication {
@Bean
public Supplier<Flux<String>> words() {
return () -> Flux.fromArray(new String[] { "foo", "bar" });
return () -> Flux.fromArray(new String[] {"foo", "bar"});
}
@Bean
public Function<String, String> compiledUppercase(
FunctionCompiler<String, String> compiler) {
FunctionCompiler<String, String> compiler) {
String lambda = "s -> s.toUpperCase()";
LambdaCompilingFunction<String, String> function = new LambdaCompilingFunction<>(
new ByteArrayResource(lambda.getBytes()), compiler);
new ByteArrayResource(lambda.getBytes()), compiler);
function.setTypeParameterizations("String", "String");
return function;
}
@Bean
public Function<Flux<String>, Flux<String>> compiledLowercase(
FunctionCompiler<Flux<String>, Flux<String>> compiler) {
FunctionCompiler<Flux<String>, Flux<String>> compiler) {
String lambda = "f->f.map(o->o.toString().toLowerCase())";
return new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()),
compiler);
compiler);
}
@Bean

View File

@@ -24,7 +24,7 @@ import com.example.functions.Greeter;
import org.junit.Test;
import reactor.core.publisher.Flux;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
public class FunctionTests {
@@ -33,36 +33,36 @@ public class FunctionTests {
@Test
public void testUppercase() {
String output = this.functions.uppercase().apply("foobar");
assertEquals("FOOBAR", output);
assertThat(output).isEqualTo("FOOBAR");
}
@Test
public void testLowercase() {
Flux<String> output = this.functions.lowercase().apply(Flux.just("FOO", "BAR"));
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo", results.get(0));
assertEquals("bar", results.get(1));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0)).isEqualTo("foo");
assertThat(results.get(1)).isEqualTo("bar");
}
@Test
public void testHello() {
String output = this.functions.hello().get();
assertEquals("hello", output);
assertThat(output).isEqualTo("hello");
}
@Test
public void testWords() {
Flux<String> output = this.functions.words().get();
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo", results.get(0));
assertEquals("bar", results.get(1));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0)).isEqualTo("foo");
assertThat(results.get(1)).isEqualTo("bar");
}
@Test
public void testGreeter() {
assertEquals("Hello World", new Greeter().apply("World"));
assertThat(new Greeter().apply("World")).isEqualTo("Hello World");
}
@Test
@@ -70,14 +70,15 @@ public class FunctionTests {
Flux<String> input = Flux.just("foo", "bar");
Flux<String> output = new Exclaimer().apply(input);
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo!!!", results.get(0));
assertEquals("bar!!!", results.get(1));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0)).isEqualTo("foo!!!");
assertThat(results.get(1)).isEqualTo("bar!!!");
}
@Test
public void testCharCounter() {
assertEquals((Integer) 21, new CharCounter().apply("this is 21 chars long"));
assertThat(new CharCounter().apply("this is 21 chars long"))
.isEqualTo((Integer) 21);
}
}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
import org.junit.Ignore;
@@ -40,7 +41,8 @@ public class SampleApplicationMvcTests {
@Test
@Ignore("FIXME")
public void words() throws Exception {
this.mockMvc.perform(get("/words")).andExpect(content().string("[\"foo\",\"bar\"]"));
this.mockMvc.perform(get("/words"))
.andExpect(content().string("[\"foo\",\"bar\"]"));
}
}

View File

@@ -28,7 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest
@@ -60,22 +60,22 @@ public class SampleApplicationTests {
@Test
public void testUppercase() {
String output = this.uppercase.apply("foobar");
assertEquals("FOOBAR", output);
assertThat(output).isEqualTo("FOOBAR");
}
@Test
public void testLowercase() {
Flux<String> output = this.lowercase.apply(Flux.just("FOO", "BAR"));
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo", results.get(0));
assertEquals("bar", results.get(1));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0)).isEqualTo("foo");
assertThat(results.get(1)).isEqualTo("bar");
}
@Test
public void testHello() {
String output = this.hello.get();
assertEquals("hello", output);
assertThat(output).isEqualTo("hello");
}
// the following are contributed via @FunctionScan:
@@ -84,15 +84,15 @@ public class SampleApplicationTests {
public void testWords() {
Flux<String> output = this.words.get();
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo", results.get(0));
assertEquals("bar", results.get(1));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0)).isEqualTo("foo");
assertThat(results.get(1)).isEqualTo("bar");
}
@Test
public void testCompiledUppercase() {
String output = this.compiledUppercase.apply("foobar");
assertEquals("FOOBAR", output);
assertThat(output).isEqualTo("FOOBAR");
}
@Test
@@ -100,15 +100,15 @@ public class SampleApplicationTests {
Flux<String> input = Flux.just("FOO", "BAR");
Flux<String> output = this.compiledLowercase.apply(input);
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo", results.get(0));
assertEquals("bar", results.get(1));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0)).isEqualTo("foo");
assertThat(results.get(1)).isEqualTo("bar");
}
@Test
public void testGreeter() {
String greeting = this.greeter.apply("World");
assertEquals("Hello World", greeting);
assertThat(greeting).isEqualTo("Hello World");
}
@Test
@@ -116,15 +116,15 @@ public class SampleApplicationTests {
Flux<String> input = Flux.just("foo", "bar");
Flux<String> output = this.exclaimer.apply(input);
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo!!!", results.get(0));
assertEquals("bar!!!", results.get(1));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0)).isEqualTo("foo!!!");
assertThat(results.get(1)).isEqualTo("bar!!!");
}
@Test
public void testCharCounter() {
Integer length = this.charCounter.apply("the quick brown fox");
assertEquals(new Integer(19), length);
assertThat(length).isEqualTo(new Integer(19));
}
}