From d6e224f2efb2b999eb3090ece0215e60722dc8ec Mon Sep 17 00:00:00 2001 From: Glenn Renfro Date: Tue, 1 Nov 2016 17:31:42 -0400 Subject: [PATCH] Updated based on Code Review --- .../dao/MapTaskExecutionDaoTests.java | 2 +- .../listener/support/JobInstanceEvent.java | 2 +- .../batch/listener/JobInstanceEventTests.java | 2 +- .../TaskLaunchConfigurationExistingTests.java | 71 +++++++++++++++++++ .../TaskLaunchConfigurationTests.java | 5 +- .../task/launcher/TaskLaunchRequestTests.java | 4 +- 6 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java index b417c456..32fbf800 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDaoTests.java @@ -112,7 +112,7 @@ public class MapTaskExecutionDaoTests { @Test public void testJobQueries(){ - List expectedTaskExecutionList = new ArrayList(2); + List expectedTaskExecutionList = new ArrayList<>(2); expectedTaskExecutionList.add(TestVerifierUtils.createSampleTaskExecutionNoArg()); expectedTaskExecutionList.add(TestVerifierUtils.createSampleTaskExecutionNoArg()); diff --git a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/JobInstanceEvent.java b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/JobInstanceEvent.java index 8e47366d..eec45eff 100644 --- a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/JobInstanceEvent.java +++ b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/JobInstanceEvent.java @@ -31,7 +31,7 @@ public class JobInstanceEvent extends Entity { private String jobName; public JobInstanceEvent() { - + super(-1L); } public JobInstanceEvent(Long id, String jobName) { diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java index 8bd8c6a1..d371f176 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobInstanceEventTests.java @@ -44,7 +44,7 @@ public class JobInstanceEventTests { assertNull(jobInstanceEvent.getJobName()); } - @Test(expected = NullPointerException.class) + @Test public void testEmptyConstructorEmptyId() { JobInstanceEvent jobInstanceEvent = new JobInstanceEvent(); jobInstanceEvent.getInstanceId(); diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java new file mode 100644 index 00000000..6ae8c128 --- /dev/null +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationExistingTests.java @@ -0,0 +1,71 @@ +/* + * Copyright 2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.task.launcher; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.deployer.spi.local.LocalDeployerProperties; +import org.springframework.cloud.deployer.spi.local.LocalTaskLauncher; +import org.springframework.cloud.deployer.spi.task.TaskLauncher; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + + +/** + * Tests the TaskLauncherConfiguration in a case where a TaskLauncher is already + * present. + * + * @author Glenn Renfro + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = + {TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class, + TaskLauncherConfiguration.class}) +public class TaskLaunchConfigurationExistingTests { + + @Autowired + private ApplicationContext context; + + private static TaskLauncher testTaskLauncher; + + @Test + public void testTaskLauncher() { + LocalTaskLauncher taskLauncher = + context.getBean(LocalTaskLauncher.class); + assertNotNull(testTaskLauncher); + assertNotNull(taskLauncher); + assertEquals(testTaskLauncher, taskLauncher); + } + + @Configuration + protected static class TestTaskDeployerConfiguration { + @Bean + public TaskLauncher taskLauncher() { + testTaskLauncher = + new LocalTaskLauncher(new LocalDeployerProperties()); + return testTaskLauncher; + } + } +} diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationTests.java index 186c553e..bb18c004 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchConfigurationTests.java @@ -28,7 +28,10 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.junit.Assert.assertNotNull; /** - * @author Glenn Renfro + * Tests the TaskLauncherConfiguration in a case where a TaskLauncher is not + * present. + * + * @author Glenn Renfro */ @RunWith(SpringRunner.class) @SpringBootTest(classes = {TaskLauncherConfiguration.class}) diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java index 2196c9b8..dadfdd16 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLaunchRequestTests.java @@ -36,8 +36,8 @@ public class TaskLaunchRequestTests { @Test public void testEquals() { - List args = new ArrayList(); - Map map = new HashMap(); + List args = new ArrayList<>(); + Map map = new HashMap<>(); args.add("foo"); map.put("bar", "baz");