Added checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-03 19:27:07 +01:00
parent 4d0acf120c
commit 60f1e21d03
249 changed files with 7450 additions and 5857 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-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,23 +35,22 @@ import org.springframework.context.annotation.Bean;
/**
* Spring Boot Application that has tasks enabled.
*/
@EnableTask
@SpringBootApplication
@EnableConfigurationProperties({ TimestampTaskProperties.class })
@EnableConfigurationProperties({TimestampTaskProperties.class})
public class TaskApplication {
private static final Log logger = LogFactory.getLog(TaskApplication.class);
public static void main(String[] args) {
SpringApplication.run(TaskApplication.class, args);
}
@Bean
public TimestampTask timeStampTask() {
return new TimestampTask();
}
public static void main(String[] args) {
SpringApplication.run(TaskApplication.class, args);
}
/**
* A commandline runner that prints a timestamp.
*/
@@ -62,7 +61,7 @@ public class TaskApplication {
@Override
public void run(String... strings) throws Exception {
DateFormat dateFormat = new SimpleDateFormat(config.getFormat());
DateFormat dateFormat = new SimpleDateFormat(this.config.getFormat());
logger.info(dateFormat.format(new Date()));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-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.
@@ -31,8 +31,8 @@ public class TimestampTaskProperties {
private String format = "yyyy-MM-dd HH:mm:ss.SSS";
public String getFormat() {
Assert.hasText(format, "format must not be empty nor null");
return format;
Assert.hasText(this.format, "format must not be empty nor null");
return this.format;
}
public void setFormat(String format) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-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.
@@ -25,8 +25,7 @@ import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.rule.OutputCapture;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Verifies that the Task Application outputs the correct task log entries.
@@ -44,19 +43,19 @@ public class TaskApplicationTests {
final String CREATE_TASK_MESSAGE = "Creating: TaskExecution{executionId=";
final String UPDATE_TASK_MESSAGE = "Updating: TaskExecution with executionId=";
final String EXIT_CODE_MESSAGE = "with the following {exitCode=0";
String[] args = { "--format=yyyy" + TEST_DATE_DOTS };
String[] args = {"--format=yyyy" + TEST_DATE_DOTS};
SpringApplication.run(TaskApplication.class, args);
String output = this.outputCapture.toString();
assertTrue("Unable to find the timestamp: " + output,
output.contains(TEST_DATE_DOTS));
assertTrue("Test results do not show create task message: " + output,
output.contains(CREATE_TASK_MESSAGE));
assertTrue("Test results do not show success message: " + output,
output.contains(UPDATE_TASK_MESSAGE));
assertTrue("Test results have incorrect exit code: " + output,
output.contains(EXIT_CODE_MESSAGE));
assertThat(output.contains(TEST_DATE_DOTS))
.as("Unable to find the timestamp: " + output).isTrue();
assertThat(output.contains(CREATE_TASK_MESSAGE))
.as("Test results do not show create task message: " + output).isTrue();
assertThat(output.contains(UPDATE_TASK_MESSAGE))
.as("Test results do not show success message: " + output).isTrue();
assertThat(output.contains(EXIT_CODE_MESSAGE))
.as("Test results have incorrect exit code: " + output).isTrue();
String taskTitle = "Demo Timestamp Task";
Pattern pattern = Pattern.compile(taskTitle);
@@ -65,6 +64,7 @@ public class TaskApplicationTests {
while (matcher.find()) {
count++;
}
assertEquals("The number of task titles did not match expected: ", 1, count);
assertThat(count).as("The number of task titles did not match expected: ")
.isEqualTo(1);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-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,14 +16,15 @@
package org.springframework.cloud.task.timestamp;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Glenn Renfro
*/
@@ -36,7 +37,8 @@ public class TimestampTaskPropertiesTests {
testPropertyValues.applyTo(context);
context.register(Conf.class);
context.refresh();
TimestampTaskProperties properties = context.getBean(TimestampTaskProperties.class);
TimestampTaskProperties properties = context
.getBean(TimestampTaskProperties.class);
properties.getFormat();
}
@@ -45,9 +47,10 @@ public class TimestampTaskPropertiesTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Conf.class);
context.refresh();
TimestampTaskProperties properties = context.getBean(TimestampTaskProperties.class);
assertEquals("result does not match default format.", "yyyy-MM-dd HH:mm:ss.SSS",
properties.getFormat());
TimestampTaskProperties properties = context
.getBean(TimestampTaskProperties.class);
assertThat(properties.getFormat()).as("result does not match default format.")
.isEqualTo("yyyy-MM-dd HH:mm:ss.SSS");
}
@Test
@@ -56,10 +59,11 @@ public class TimestampTaskPropertiesTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Conf.class);
context.refresh();
TimestampTaskProperties properties = context.getBean(TimestampTaskProperties.class);
TimestampTaskProperties properties = context
.getBean(TimestampTaskProperties.class);
properties.setFormat(FORMAT);
assertEquals("result does not match established format.", FORMAT,
properties.getFormat());
assertThat(properties.getFormat()).as("result does not match established format.")
.isEqualTo(FORMAT);
}
@Configuration

View File

@@ -1,5 +1,5 @@
#
# Copyright 2016 the original author or authors.
# Copyright 2015-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.
@@ -13,6 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
logging.level.org.springframework.cloud.task=DEBUG
spring.application.name=Demo Timestamp Task