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

@@ -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.

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.
@@ -52,4 +52,5 @@ public class ApplicationRunnerTests {
assertThat(runner.getBeanNames(FunctionRegistration.class.getName())).hasSize(2);
runner.close();
}
}

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.
@@ -37,4 +37,5 @@ public class ContextRunnerTests {
assertThat(runner.getContext()).isNotNull();
runner.close();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2012-2019-2018 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.
@@ -22,6 +22,8 @@ import java.util.function.Supplier;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -35,9 +37,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { FunctionDeployerConfiguration.class })
@DirtiesContext
@@ -53,10 +52,11 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testDouble() {
Function<Flux<Integer>, Flux<Integer>> function = catalog
Function<Flux<Integer>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo(4);
}
}
@EnableAutoConfiguration
@@ -68,10 +68,11 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testDouble() {
Function<Flux<Integer>, Flux<Integer>> function = catalog
Function<Flux<Integer>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo(4);
}
}
@EnableAutoConfiguration
@@ -84,10 +85,11 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testDouble() {
Function<Flux<Integer>, Flux<Integer>> function = catalog
Function<Flux<Integer>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo(4);
}
}
@EnableAutoConfiguration
@@ -100,7 +102,7 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testDouble() {
Function<Flux<Integer>, Flux<Integer>> function = catalog
Function<Flux<Integer>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo(4);
}
@@ -117,10 +119,11 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testFrenchize() {
Function<Flux<Integer>, Flux<String>> function = catalog
Function<Flux<Integer>, Flux<String>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo("deux");
}
}
@EnableAutoConfiguration
@@ -133,10 +136,11 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testDouble() {
Function<Flux<Integer>, Flux<Integer>> function = catalog
Function<Flux<Integer>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo(4);
}
}
@EnableAutoConfiguration
@@ -147,10 +151,11 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testDouble() {
Function<Flux<Integer>, Flux<Integer>> function = catalog
Function<Flux<Integer>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo(4);
}
}
@EnableAutoConfiguration
@@ -162,13 +167,13 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testSupplier() {
Supplier<Integer> function = catalog.lookup(Supplier.class, "function0");
Supplier<Integer> function = this.catalog.lookup(Supplier.class, "function0");
assertThat(function).isNull();
}
@Test
public void testFunction() {
Supplier<Flux<String>> function = catalog.lookup(Supplier.class,
Supplier<Flux<String>> function = this.catalog.lookup(Supplier.class,
"function0|function1");
assertThat(function.get().blockFirst()).isEqualTo("un");
}
@@ -184,17 +189,18 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testFunction() {
Function<Flux<Integer>, Flux<String>> function = catalog
Function<Flux<Integer>, Flux<String>> function = this.catalog
.lookup(Function.class, "function0|function1");
assertThat(function.apply(Flux.just(2)).blockFirst()).isEqualTo("quatre");
}
@Test
public void testThen() {
Function<Integer, String> function = catalog.lookup(Function.class,
Function<Integer, String> function = this.catalog.lookup(Function.class,
"function1");
assertThat(function).isNull();
}
}
@EnableAutoConfiguration
@@ -209,10 +215,12 @@ public abstract class FunctionCreatorConfigurationTests {
@Test
public void testConsumer() {
Function<Flux<Integer>, Mono<Void>> function = catalog.lookup(Function.class,
"function0|function1");
Function<Flux<Integer>, Mono<Void>> function = this.catalog
.lookup(Function.class, "function0|function1");
function.apply(Flux.just(2)).block();
capture.expect(containsString("Seen deux"));
this.capture.expect(containsString("Seen deux"));
}
}
}

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.
@@ -34,33 +34,33 @@ public class SingleEntryFunctionRegistryTests {
@Test
public void named() {
delegate.register(new FunctionRegistration<Foos>(new Foos(), "foo"));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(delegate,
"foo");
this.delegate.register(new FunctionRegistration<Foos>(new Foos(), "foo"));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(
this.delegate, "foo");
assertThat((Foos) registry.lookup("foo")).isInstanceOf(Function.class);
}
@Test
public void other() {
delegate.register(new FunctionRegistration<Foos>(new Foos(), "foo"));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(delegate,
"foo");
this.delegate.register(new FunctionRegistration<Foos>(new Foos(), "foo"));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(
this.delegate, "foo");
assertThat((Foos) registry.lookup("bar")).isNull();
}
@Test
public void empty() {
delegate.register(new FunctionRegistration<Foos>(new Foos(), ""));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(delegate,
"");
this.delegate.register(new FunctionRegistration<Foos>(new Foos(), ""));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(
this.delegate, "");
assertThat((Foos) registry.lookup("")).isInstanceOf(Function.class);
}
@Test
public void anonymous() {
delegate.register(new FunctionRegistration<Foos>(new Foos(), "bar"));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(delegate,
"foo");
this.delegate.register(new FunctionRegistration<Foos>(new Foos(), "bar"));
SingleEntryFunctionRegistry registry = new SingleEntryFunctionRegistry(
this.delegate, "foo");
assertThat((Foos) registry.lookup("")).isInstanceOf(Function.class);
}

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.
@@ -22,6 +22,8 @@ import java.util.function.Supplier;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -34,9 +36,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = FunctionDeployerConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@TestPropertySource(properties = {
@@ -53,7 +52,8 @@ public abstract class SpringFunctionAppConfigurationTests {
@Test
public void test() throws Exception {
Supplier<Flux<String>> function = catalog.lookup(Supplier.class, "function0");
Supplier<Flux<String>> function = this.catalog.lookup(Supplier.class,
"function0");
assertThat(function.get().blockFirst()).isEqualTo("one");
}
@@ -65,7 +65,7 @@ public abstract class SpringFunctionAppConfigurationTests {
@Test
public void test() throws Exception {
Supplier<Flux<Integer>> function = catalog.lookup(Supplier.class,
Supplier<Flux<Integer>> function = this.catalog.lookup(Supplier.class,
"function0|function1");
assertThat(function.get().blockFirst()).isEqualTo(3);
}
@@ -78,7 +78,7 @@ public abstract class SpringFunctionAppConfigurationTests {
@Test
public void test() throws Exception {
Function<Flux<String>, Flux<Integer>> function = catalog
Function<Flux<String>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just("spam")).blockFirst()).isEqualTo(4);
}
@@ -95,12 +95,12 @@ public abstract class SpringFunctionAppConfigurationTests {
@Test
public void test() throws Exception {
// Can't assert side effects.
Function<Flux<Integer>, Mono<Void>> function = catalog.lookup(Function.class,
"function0");
Function<Flux<Integer>, Mono<Void>> function = this.catalog
.lookup(Function.class, "function0");
function.apply(Flux.just(5)).block();
capture.expect(containsString(String.format("10%n")));
this.capture.expect(containsString(String.format("10%n")));
}
}
}
}

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.
@@ -22,6 +22,8 @@ import java.util.function.Supplier;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -34,9 +36,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = FunctionDeployerConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@TestPropertySource(properties = {
@@ -53,7 +52,8 @@ public abstract class SpringFunctionAppExplodedConfigurationTests {
@Test
public void test() throws Exception {
Supplier<Flux<String>> function = catalog.lookup(Supplier.class, "function0");
Supplier<Flux<String>> function = this.catalog.lookup(Supplier.class,
"function0");
assertThat(function.get().blockFirst()).isEqualTo("one");
}
@@ -61,11 +61,12 @@ public abstract class SpringFunctionAppExplodedConfigurationTests {
@EnableAutoConfiguration
@TestPropertySource(properties = { "function.bean=myEmitter,myCounter" })
public static class CompositeTests extends SpringFunctionAppExplodedConfigurationTests {
public static class CompositeTests
extends SpringFunctionAppExplodedConfigurationTests {
@Test
public void test() throws Exception {
Supplier<Flux<Integer>> function = catalog.lookup(Supplier.class,
Supplier<Flux<Integer>> function = this.catalog.lookup(Supplier.class,
"function0|function1");
assertThat(function.get().blockFirst()).isEqualTo(3);
}
@@ -74,11 +75,12 @@ public abstract class SpringFunctionAppExplodedConfigurationTests {
@EnableAutoConfiguration
@TestPropertySource(properties = { "function.bean=myCounter" })
public static class ProcessorTests extends SpringFunctionAppExplodedConfigurationTests {
public static class ProcessorTests
extends SpringFunctionAppExplodedConfigurationTests {
@Test
public void test() throws Exception {
Function<Flux<String>, Flux<Integer>> function = catalog
Function<Flux<String>, Flux<Integer>> function = this.catalog
.lookup(Function.class, "function0");
assertThat(function.apply(Flux.just("spam")).blockFirst()).isEqualTo(4);
}
@@ -95,12 +97,12 @@ public abstract class SpringFunctionAppExplodedConfigurationTests {
@Test
public void test() throws Exception {
// Can't assert side effects.
Function<Flux<Integer>, Mono<Void>> function = catalog.lookup(Function.class,
"function0");
Function<Flux<Integer>, Mono<Void>> function = this.catalog
.lookup(Function.class, "function0");
function.apply(Flux.just(5)).block();
capture.expect(containsString(String.format("10%n")));
this.capture.expect(containsString(String.format("10%n")));
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 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.
@@ -44,39 +44,42 @@ public class SpringFunctionFluxConfigurationTests {
@Before
public void run() {
if (bootstrap == null) {
bootstrap = new ApplicationBootstrap();
bootstrap.run(SpringFunctionFluxConfigurationTests.class,
if (this.bootstrap == null) {
this.bootstrap = new ApplicationBootstrap();
this.bootstrap.run(SpringFunctionFluxConfigurationTests.class,
"--function.location=file:target/it/flux/target/dependency",
"--function.bean=foos",
"--function.main=com.example.functions.FunctionApp");
catalog = bootstrap.getRunner().getBean(FunctionCatalog.class.getName());
inspector = bootstrap.getRunner().getBean(FunctionInspector.class.getName());
this.catalog = this.bootstrap.getRunner()
.getBean(FunctionCatalog.class.getName());
this.inspector = this.bootstrap.getRunner()
.getBean(FunctionInspector.class.getName());
}
}
@After
public void close() {
if (bootstrap != null) {
bootstrap.close();
if (this.bootstrap != null) {
this.bootstrap.close();
}
}
@Test
public void test() throws Exception {
@SuppressWarnings("unchecked")
Function<Object, Object> function = (Function<Object, Object>) bootstrap
Function<Object, Object> function = (Function<Object, Object>) this.bootstrap
.getRunner()
.evaluate("lookup(T(java.util.function.Function), 'function0')", catalog);
.evaluate("lookup(T(java.util.function.Function), 'function0')",
this.catalog);
assertThat(function).isNotNull();
Class<?> inputType = (Class<?>) bootstrap.getRunner()
.evaluate("getInputType(#function)", inspector, "function", function);
Class<?> inputType = (Class<?>) this.bootstrap.getRunner().evaluate(
"getInputType(#function)", this.inspector, "function", function);
assertThat(inputType.getName()).isEqualTo("com.example.functions.Foo");
Object foo = create(inputType);
Class<?> outputType = (Class<?>) bootstrap.getRunner()
.evaluate("getOutputType(#function)", inspector, "function", function);
Class<?> outputType = (Class<?>) this.bootstrap.getRunner().evaluate(
"getOutputType(#function)", this.inspector, "function", function);
assertThat(outputType.getName()).isEqualTo("com.example.functions.Foo");
String value = (String) bootstrap.getRunner().evaluate(
String value = (String) this.bootstrap.getRunner().evaluate(
"apply(T(reactor.core.publisher.Flux).just(#foo)).blockFirst().getValue()",
function, "foo", foo);
assertThat(value).isEqualTo("FOO");
@@ -115,4 +118,4 @@ class Foo {
return "Foo [value=" + this.value + "]";
}
}
}

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.
@@ -19,8 +19,10 @@ package org.springframework.cloud.function.test;
import java.util.function.Function;
public class Doubler implements Function<Integer, Integer> {
@Override
public Integer apply(Integer integer) {
return 2 * integer;
}
}

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,10 +27,10 @@ public class Frenchizer implements Function<Integer, String> {
@PostConstruct
public void init() {
this.numbers = new String[4];
numbers[0] = "un";
numbers[1] = "deux";
numbers[2] = "trois";
numbers[3] = "quatre";
this.numbers[0] = "un";
this.numbers[1] = "deux";
this.numbers[2] = "trois";
this.numbers[3] = "quatre";
}
@Override
@@ -40,4 +40,5 @@ public class Frenchizer implements Function<Integer, String> {
}
throw new RuntimeException();
}
}

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.
@@ -26,6 +26,10 @@ import org.springframework.context.annotation.Bean;
@SpringBootConfiguration
public class FunctionApp {
public static void main(String[] args) throws Exception {
SpringApplication.run(FunctionApp.class, args);
}
@Bean
public Doubler myDoubler() {
return new Doubler();
@@ -36,7 +40,4 @@ public class FunctionApp {
return new Frenchizer();
}
public static void main(String[] args) throws Exception {
SpringApplication.run(FunctionApp.class, args);
}
}

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.
@@ -28,6 +28,12 @@ import org.springframework.context.support.GenericApplicationContext;
public class FunctionInitializer
implements ApplicationContextInitializer<GenericApplicationContext> {
public static void main(String[] args) throws Exception {
SpringApplication application = new FunctionalSpringApplication(
FunctionInitializer.class);
application.run(args);
}
@Bean
public Doubler myDoubler() {
return new Doubler();
@@ -38,16 +44,11 @@ public class FunctionInitializer
return new Frenchizer();
}
public static void main(String[] args) throws Exception {
SpringApplication application = new FunctionalSpringApplication(
FunctionInitializer.class);
application.run(args);
}
@Override
public void initialize(GenericApplicationContext context) {
// TODO: support for FunctionRegistration
context.registerBean("myDoubler", Doubler.class, () -> myDoubler());
context.registerBean("myFrenchizer", Frenchizer.class, () -> myFrenchizer());
}
}

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.
@@ -30,6 +30,12 @@ import org.springframework.context.support.GenericApplicationContext;
public class FunctionRegistrar
implements ApplicationContextInitializer<GenericApplicationContext> {
public static void main(String[] args) throws Exception {
SpringApplication application = new FunctionalSpringApplication(
FunctionRegistrar.class);
application.run(args);
}
@Bean
public Doubler myDoubler() {
return new Doubler();
@@ -40,12 +46,6 @@ public class FunctionRegistrar
return new Frenchizer();
}
public static void main(String[] args) throws Exception {
SpringApplication application = new FunctionalSpringApplication(
FunctionRegistrar.class);
application.run(args);
}
@Override
public void initialize(GenericApplicationContext context) {
context.registerBean("theDoubler", FunctionRegistration.class,
@@ -58,4 +58,5 @@ public class FunctionRegistrar
.type(FunctionType.of((Frenchizer.class)));
});
}
}

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.
@@ -19,8 +19,10 @@ package org.springframework.cloud.function.test;
import java.util.function.Supplier;
public class NumberEmitter implements Supplier<Integer> {
@Override
public Integer get() {
return 1;
}
}

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.
@@ -24,4 +24,5 @@ public class Printer implements Consumer<Object> {
public void accept(Object o) {
System.err.println("Seen " + o);
}
}

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.
@@ -35,15 +35,16 @@ public class SpringDoubler implements Function<Integer, Integer> {
@PostConstruct
public void init() {
if (this.context == null) {
context = new SpringApplicationBuilder(FunctionApp.class).bannerMode(Mode.OFF).registerShutdownHook(false)
this.context = new SpringApplicationBuilder(FunctionApp.class)
.bannerMode(Mode.OFF).registerShutdownHook(false)
.web(WebApplicationType.NONE).run();
}
}
@PreDestroy
public void close() {
if (context != null) {
context.close();
if (this.context != null) {
this.context.close();
}
}
@@ -51,4 +52,5 @@ public class SpringDoubler implements Function<Integer, Integer> {
public Integer apply(Integer integer) {
return 2 * integer;
}
}