Turned on checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-01 15:48:32 +01:00
parent 94e9b8f2f8
commit e4b08a083c
268 changed files with 5114 additions and 3993 deletions

View File

@@ -38,9 +38,9 @@ ext {
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
}
imports {
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
}
}
dependencies {

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.spring.sample</groupId>
@@ -19,7 +20,8 @@
<properties>
<java.version>1.8</java.version>
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT</spring-cloud-function.version>
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT
</spring-cloud-function.version>
<wrapper.version>1.0.17.RELEASE</wrapper.version>
</properties>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2012-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.
@@ -19,6 +19,8 @@ package com.example;
import java.util.function.Function;
import java.util.function.Supplier;
import reactor.core.publisher.Flux;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.function.compiler.FunctionCompiler;
@@ -26,11 +28,14 @@ import org.springframework.cloud.function.compiler.proxy.LambdaCompilingFunction
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ByteArrayResource;
import reactor.core.publisher.Flux;
// @checkstyle:off
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleApplication.class, args);
}
@Bean
public Function<String, String> uppercase() {
return value -> value.toUpperCase();
@@ -52,17 +57,21 @@ public class SampleApplication {
}
@Bean
public Function<String, String> compiledUppercase(FunctionCompiler<String, String> compiler) {
public Function<String, String> compiledUppercase(
FunctionCompiler<String, String> compiler) {
String lambda = "s -> s.toUpperCase()";
LambdaCompilingFunction<String, String> function = new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()), compiler);
LambdaCompilingFunction<String, String> function = new LambdaCompilingFunction<>(
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) {
public Function<Flux<String>, Flux<String>> compiledLowercase(
FunctionCompiler<Flux<String>, Flux<String>> compiler) {
String lambda = "f->f.map(o->o.toString().toLowerCase())";
return new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()), compiler);
return new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()),
compiler);
}
@Bean
@@ -70,7 +79,5 @@ public class SampleApplication {
return new FunctionCompiler<>();
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleApplication.class, args);
}
}
// @checkstyle:on

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2012-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.
@@ -27,4 +27,5 @@ public class CharCounter implements Function<String, Integer> {
public Integer apply(String word) {
return word.length();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2012-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.
@@ -27,6 +27,7 @@ public class Exclaimer implements Function<Flux<String>, Flux<String>> {
@Override
public Flux<String> apply(Flux<String> words) {
return words.map(word->word+"!!!");
return words.map(word -> word + "!!!");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2012-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.
@@ -27,4 +27,5 @@ public class Greeter implements Function<String, String> {
public String apply(String name) {
return "Hello " + name;
}
}

View File

@@ -1,5 +1,5 @@
boms.spring-cloud-dependencies: org.springframework.cloud:spring-cloud-dependencies:Edgware.SR3
dependencies.spring-cloud-function-stream: org.springframework.cloud:spring-cloud-function-stream
dependencies.spring-cloud-stream-rabbit: org.springframework.cloud:spring-cloud-starter-stream-rabbit
exclusions.spring-cloud-function-web: org.springframework.cloud:spring-cloud-starter-function-web
exclusions.http-client: com.rabbitmq:http-client
boms.spring-cloud-dependencies:org.springframework.cloud:spring-cloud-dependencies:Edgware.SR3
dependencies.spring-cloud-function-stream:org.springframework.cloud:spring-cloud-function-stream
dependencies.spring-cloud-stream-rabbit:org.springframework.cloud:spring-cloud-starter-stream-rabbit
exclusions.spring-cloud-function-web:org.springframework.cloud:spring-cloud-starter-function-web
exclusions.http-client:com.rabbitmq:http-client

View File

@@ -1,2 +1,2 @@
spring.cloud.function.stream.processor.name: uppercase
spring.cloud.function.scan.packages: com.example.functions
spring.cloud.function.stream.processor.name:uppercase
spring.cloud.function.scan.packages:com.example.functions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2012-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.
@@ -16,31 +16,29 @@
package com.example;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import com.example.functions.CharCounter;
import com.example.functions.Exclaimer;
import com.example.functions.Greeter;
import org.junit.Test;
import reactor.core.publisher.Flux;
import static org.junit.Assert.assertEquals;
public class FunctionTests {
private final SampleApplication functions = new SampleApplication();
@Test
public void testUppercase() {
String output = functions.uppercase().apply("foobar");
String output = this.functions.uppercase().apply("foobar");
assertEquals("FOOBAR", output);
}
@Test
public void testLowercase() {
Flux<String> output = functions.lowercase().apply(Flux.just("FOO", "BAR"));
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));
@@ -49,13 +47,13 @@ public class FunctionTests {
@Test
public void testHello() {
String output = functions.hello().get();
assertEquals("hello", output);
String output = this.functions.hello().get();
assertEquals("hello", output);
}
@Test
public void testWords() {
Flux<String> output = functions.words().get();
Flux<String> output = this.functions.words().get();
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo", results.get(0));
@@ -81,4 +79,5 @@ public class FunctionTests {
public void testCharCounter() {
assertEquals((Integer) 21, new CharCounter().apply("this is 21 chars long"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2012-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.
@@ -40,7 +40,7 @@ public class SampleApplicationMvcTests {
@Test
@Ignore("FIXME")
public void words() throws Exception {
mockMvc.perform(get("/words")).andExpect(content().string("[\"foo\",\"bar\"]"));
this.mockMvc.perform(get("/words")).andExpect(content().string("[\"foo\",\"bar\"]"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2012-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.
@@ -16,61 +16,69 @@
package com.example;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import org.junit.Test;
import org.junit.runner.RunWith;
import reactor.core.publisher.Flux;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Flux;
import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SampleApplicationTests {
@Autowired
private Function<String, String> uppercase;
@Autowired
private Function<Flux<String>, Flux<String>> lowercase;
@Autowired
private Supplier<String> hello;
@Autowired
private Supplier<Flux<String>> words;
@Autowired
private Function<String, String> compiledUppercase;
@Autowired
private Function<Flux<String>, Flux<String>> compiledLowercase;
@Autowired
private Function<String, String> greeter;
@Autowired
private Function<Flux<String>, Flux<String>> exclaimer;
@Autowired
private Function<String, Integer> charCounter;
@Test
public void contextLoads() {
}
@Autowired
private Function<String, String> uppercase;
@Test
public void testUppercase() {
String output = this.uppercase.apply("foobar");
assertEquals("FOOBAR", output);
}
@Autowired
private Function<Flux<String>, Flux<String>> lowercase;
@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));
assertEquals("bar", results.get(1));
}
@Autowired
private Supplier<String> hello;
@Test
public void testHello() {
String output = this.hello.get();
assertEquals("hello", output);
assertEquals("hello", output);
}
@Autowired
private Supplier<Flux<String>> words;
// the following are contributed via @FunctionScan:
@Test
public void testWords() {
@@ -78,21 +86,15 @@ public class SampleApplicationTests {
List<String> results = output.collectList().block();
assertEquals(2, results.size());
assertEquals("foo", results.get(0));
assertEquals("bar", results.get(1));
assertEquals("bar", results.get(1));
}
@Autowired
private Function<String, String> compiledUppercase;
@Test
public void testCompiledUppercase() {
String output = this.compiledUppercase.apply("foobar");
assertEquals("FOOBAR", output);
}
@Autowired
private Function<Flux<String>, Flux<String>> compiledLowercase;
@Test
public void testCompiledLowercase() {
Flux<String> input = Flux.just("FOO", "BAR");
@@ -103,20 +105,12 @@ public class SampleApplicationTests {
assertEquals("bar", results.get(1));
}
// the following are contributed via @FunctionScan:
@Autowired
private Function<String, String> greeter;
@Test
public void testGreeter() {
String greeting = this.greeter.apply("World");
assertEquals("Hello World", greeting);
}
@Autowired
private Function<Flux<String>, Flux<String>> exclaimer;
@Test
public void testExclaimer() {
Flux<String> input = Flux.just("foo", "bar");
@@ -127,12 +121,10 @@ public class SampleApplicationTests {
assertEquals("bar!!!", results.get(1));
}
@Autowired
private Function<String, Integer> charCounter;
@Test
public void testCharCounter() {
Integer length = this.charCounter.apply("the quick brown fox");
assertEquals(new Integer(19), length);
}
}
}