[BAEL-3913] Fixed broken lines format and reduced the test method names length
This commit is contained in:
parent
f1f9e87468
commit
adf1ee9b0d
|
@ -7,10 +7,11 @@ import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Profile("!test")
|
@Profile("!test")
|
||||||
@ConditionalOnProperty(prefix = "application.runner",
|
@ConditionalOnProperty(
|
||||||
value = "enabled",
|
prefix = "application.runner",
|
||||||
havingValue = "true",
|
value = "enabled",
|
||||||
matchIfMissing = true)
|
havingValue = "true",
|
||||||
|
matchIfMissing = true)
|
||||||
@Component
|
@Component
|
||||||
public class ApplicationRunnerTaskExecutor implements ApplicationRunner {
|
public class ApplicationRunnerTaskExecutor implements ApplicationRunner {
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
|
|
|
@ -6,10 +6,11 @@ import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Profile("!test")
|
@Profile("!test")
|
||||||
@ConditionalOnProperty(prefix = "command.line.runner",
|
@ConditionalOnProperty(
|
||||||
value = "enabled",
|
prefix = "command.line.runner",
|
||||||
havingValue = "true",
|
value = "enabled",
|
||||||
matchIfMissing = true)
|
havingValue = "true",
|
||||||
|
matchIfMissing = true)
|
||||||
@Component
|
@Component
|
||||||
public class CommandLineTaskExecutor implements CommandLineRunner {
|
public class CommandLineTaskExecutor implements CommandLineRunner {
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
|
|
|
@ -18,8 +18,8 @@ import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = {ApplicationCommandLineRunnerApp.class},
|
@ContextConfiguration(classes = { ApplicationCommandLineRunnerApp.class },
|
||||||
initializers = ConfigFileApplicationContextInitializer.class)
|
initializers = ConfigFileApplicationContextInitializer.class)
|
||||||
public class LoadSpringContextIntegrationTest {
|
public class LoadSpringContextIntegrationTest {
|
||||||
@SpyBean
|
@SpyBean
|
||||||
TaskService taskService;
|
TaskService taskService;
|
||||||
|
@ -31,8 +31,7 @@ public class LoadSpringContextIntegrationTest {
|
||||||
ApplicationRunner applicationRunner;
|
ApplicationRunner applicationRunner;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenContextLoads_thenAllBeansAreLoadedButCommandLineAndApplicationRunnerAreNotExecuted()
|
void whenContextLoads_thenRunnersDoNotRun() throws Exception {
|
||||||
throws Exception {
|
|
||||||
assertNotNull(taskService);
|
assertNotNull(taskService);
|
||||||
assertNotNull(commandLineRunner);
|
assertNotNull(commandLineRunner);
|
||||||
assertNotNull(applicationRunner);
|
assertNotNull(applicationRunner);
|
||||||
|
|
|
@ -19,7 +19,7 @@ class RunApplicationIntegrationTest {
|
||||||
CommandLineTaskExecutor commandLineTaskExecutor;
|
CommandLineTaskExecutor commandLineTaskExecutor;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenContextLoads_thenTheCommandLineAndApplicationRunnerAreExecuted() throws Exception {
|
void whenContextLoads_thenRunnersRun() throws Exception {
|
||||||
verify(applicationRunnerTaskExecutor, times(1)).run(any());
|
verify(applicationRunnerTaskExecutor, times(1)).run(any());
|
||||||
verify(commandLineTaskExecutor, times(1)).run(any());
|
verify(commandLineTaskExecutor, times(1)).run(any());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,13 @@ class RunApplicationWithTestProfileIntegrationTest {
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenContextLoads_thenTheCommandLineAndApplicationRunnerAreNotLoaded() {
|
void whenContextLoads_thenRunnersAreNotLoaded() {
|
||||||
assertNotNull(context.getBean(TaskService.class));
|
assertNotNull(context.getBean(TaskService.class));
|
||||||
assertThrows(NoSuchBeanDefinitionException.class,
|
assertThrows(NoSuchBeanDefinitionException.class,
|
||||||
() -> context.getBean(CommandLineTaskExecutor.class),
|
() -> context.getBean(CommandLineTaskExecutor.class),
|
||||||
"CommandLineRunner should not be loaded during this integration test");
|
"CommandLineRunner should not be loaded during this integration test");
|
||||||
assertThrows(NoSuchBeanDefinitionException.class,
|
assertThrows(NoSuchBeanDefinitionException.class,
|
||||||
() -> context.getBean(ApplicationRunnerTaskExecutor.class),
|
() -> context.getBean(ApplicationRunnerTaskExecutor.class),
|
||||||
"ApplicationRunner should not be loaded during this integration test");
|
"ApplicationRunner should not be loaded during this integration test");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,23 +12,21 @@ import com.baeldung.prevent.commandline.application.runner.execution.Application
|
||||||
import com.baeldung.prevent.commandline.application.runner.execution.CommandLineTaskExecutor;
|
import com.baeldung.prevent.commandline.application.runner.execution.CommandLineTaskExecutor;
|
||||||
import com.baeldung.prevent.commandline.application.runner.execution.TaskService;
|
import com.baeldung.prevent.commandline.application.runner.execution.TaskService;
|
||||||
|
|
||||||
@SpringBootTest(
|
@SpringBootTest(properties = {
|
||||||
properties = {
|
"command.line.runner.enabled=false",
|
||||||
"command.line.runner.enabled=false",
|
"application.runner.enabled=false" })
|
||||||
"application.runner.enabled=false"
|
|
||||||
})
|
|
||||||
class RunApplicationWithTestPropertiesIntegrationTest {
|
class RunApplicationWithTestPropertiesIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenContextLoads_thenTheCommandLineAndApplicationRunnerAreNotLoaded() {
|
void whenContextLoads_thenRunnersAreNotLoaded() {
|
||||||
assertNotNull(context.getBean(TaskService.class));
|
assertNotNull(context.getBean(TaskService.class));
|
||||||
assertThrows(NoSuchBeanDefinitionException.class,
|
assertThrows(NoSuchBeanDefinitionException.class,
|
||||||
() -> context.getBean(CommandLineTaskExecutor.class),
|
() -> context.getBean(CommandLineTaskExecutor.class),
|
||||||
"CommandLineRunner should not be loaded during this integration test");
|
"CommandLineRunner should not be loaded during this integration test");
|
||||||
assertThrows(NoSuchBeanDefinitionException.class,
|
assertThrows(NoSuchBeanDefinitionException.class,
|
||||||
() -> context.getBean(ApplicationRunnerTaskExecutor.class),
|
() -> context.getBean(ApplicationRunnerTaskExecutor.class),
|
||||||
"ApplicationRunner should not be loaded during this integration test");
|
"ApplicationRunner should not be loaded during this integration test");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue