diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ApplicationRunnerAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ApplicationRunnerAutoConfigurationTests.java index 4c8fe3d7e..b27b5a238 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ApplicationRunnerAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ApplicationRunnerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ApplicationRunnerAutoConfigurationTests { +class ApplicationRunnerAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(ApplicationRunnerAutoConfiguration.class)); diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/CommandCatalogAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/CommandCatalogAutoConfigurationTests.java index 5386b805e..65a890a0b 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/CommandCatalogAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/CommandCatalogAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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. @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CommandCatalogAutoConfigurationTests { +class CommandCatalogAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(CommandCatalogAutoConfiguration.class, @@ -66,7 +66,7 @@ void customCommandCatalog() { @Test void registerCommandRegistration() { this.contextRunner.withUserConfiguration(CustomCommandRegistrationConfiguration.class) - .run((context) -> { + .run(context -> { CommandCatalog commandCatalog = context.getBean(CommandCatalog.class); assertThat(commandCatalog.getRegistrations().get("customcommand")).isNotNull(); }); @@ -153,7 +153,7 @@ static class CustomCommandResolverConfiguration { @Bean CommandResolver customCommandResolver() { - return () -> Collections.emptyList(); + return Collections::emptyList; } } @@ -176,9 +176,7 @@ CommandRegistration commandRegistration() { return CommandRegistration.builder() .command("customcommand") .withTarget() - .function(ctx -> { - return null; - }) + .function(ctx -> null) .and() .build(); } diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/JLineShellAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/JLineShellAutoConfigurationTests.java index d1de27fb3..0ebd9475b 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/JLineShellAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/JLineShellAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/LineReaderAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/LineReaderAutoConfigurationTests.java index f4aa0fcfc..c72656bfd 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/LineReaderAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/LineReaderAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -36,13 +36,13 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class LineReaderAutoConfigurationTests { +class LineReaderAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(LineReaderAutoConfiguration.class)); @Test - public void testLineReaderCreated() { + void testLineReaderCreated() { this.contextRunner .withUserConfiguration(MockConfiguration.class) .run(context -> { @@ -53,7 +53,7 @@ public void testLineReaderCreated() { } @Test - public void testLineReaderCreatedNoHistoryFile() { + void testLineReaderCreatedNoHistoryFile() { this.contextRunner .withUserConfiguration(MockConfiguration.class) .withPropertyValues("spring.shell.history.enabled=false") @@ -65,7 +65,7 @@ public void testLineReaderCreatedNoHistoryFile() { } @Test - public void testLineReaderCreatedCustomHistoryFile() { + void testLineReaderCreatedCustomHistoryFile() { this.contextRunner .withUserConfiguration(MockConfiguration.class) .withPropertyValues("spring.shell.history.name=fakehistory.txt") diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ParameterResolverAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ParameterResolverAutoConfigurationTests.java index 44c3c6c65..2ed1f9c1f 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ParameterResolverAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ParameterResolverAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ParameterResolverAutoConfigurationTests { +class ParameterResolverAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(ParameterResolverAutoConfiguration.class)); @@ -36,7 +36,7 @@ public class ParameterResolverAutoConfigurationTests { @Test void defaultCompletionResolverExists() { this.contextRunner.withUserConfiguration(CustomShellConversionServiceConfiguration.class) - .run((context) -> { + .run(context -> { assertThat(context).hasSingleBean(CompletionResolver.class); }); } @@ -44,9 +44,8 @@ void defaultCompletionResolverExists() { @Test void defaultCommandExecutionHandlerMethodArgumentResolversExists() { this.contextRunner.withUserConfiguration(CustomShellConversionServiceConfiguration.class) - .run((context) -> { - assertThat(context).hasSingleBean(CommandExecutionHandlerMethodArgumentResolvers.class); - }); + .run(context -> assertThat(context) + .hasSingleBean(CommandExecutionHandlerMethodArgumentResolvers.class)); } @Configuration @@ -54,7 +53,7 @@ static class CustomShellConversionServiceConfiguration { @Bean ShellConversionServiceSupplier shellConversionServiceSupplier() { - return () -> new DefaultConversionService(); + return DefaultConversionService::new; } } } diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java index cb0c2f90a..1158408b4 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ShellRunnerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/SpringShellPropertiesTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/SpringShellPropertiesTests.java index 462dc3202..73ababadc 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/SpringShellPropertiesTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/SpringShellPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2024 the original author or authors. + * Copyright 2021-present 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,15 +24,15 @@ import static org.assertj.core.api.Assertions.assertThat; -public class SpringShellPropertiesTests { +class SpringShellPropertiesTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); @Test - public void defaultNoPropertiesSet() { + void defaultNoPropertiesSet() { this.contextRunner .withUserConfiguration(Config1.class) - .run((context) -> { + .run(context -> { SpringShellProperties properties = context.getBean(SpringShellProperties.class); assertThat(properties.getHistory().isEnabled()).isTrue(); assertThat(properties.getHistory().getName()).isNull(); @@ -75,7 +75,7 @@ public void defaultNoPropertiesSet() { } @Test - public void setProperties() { + void setProperties() { this.contextRunner .withPropertyValues("spring.shell.history.enabled=false") .withPropertyValues("spring.shell.history.name=fakename") @@ -115,7 +115,7 @@ public void setProperties() { .withPropertyValues("spring.shell.option.naming.case-type=camel") .withPropertyValues("spring.shell.context.close=true") .withUserConfiguration(Config1.class) - .run((context) -> { + .run(context -> { SpringShellProperties properties = context.getBean(SpringShellProperties.class); assertThat(properties.getHistory().isEnabled()).isFalse(); assertThat(properties.getHistory().getName()).isEqualTo("fakename"); @@ -159,12 +159,12 @@ public void setProperties() { @Test - public void essentiallyUnset() { + void essentiallyUnset() { this.contextRunner .withPropertyValues("spring.shell.help.long-names=") .withPropertyValues("spring.shell.help.short-names=") .withUserConfiguration(Config1.class) - .run((context) -> { + .run(context -> { SpringShellProperties properties = context.getBean(SpringShellProperties.class); assertThat(properties.getHelp().getLongNames()).isEmpty(); assertThat(properties.getHelp().getShortNames()).isEmpty(); diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/StandardCommandsAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/StandardCommandsAutoConfigurationTests.java index f674b25e1..b0db85ad8 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/StandardCommandsAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/StandardCommandsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,31 +28,28 @@ import static org.assertj.core.api.Assertions.assertThat; -public class StandardCommandsAutoConfigurationTests { +class StandardCommandsAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(StandardCommandsAutoConfiguration.class)); @Test - public void testCompletionCommand() { + void testCompletionCommand() { this.contextRunner .with(disableCommands("help", "clear", "quit", "stacktrace", "script", "history")) - .run((context) -> {assertThat(context).doesNotHaveBean(Completion.class); - }); + .run(context -> assertThat(context).doesNotHaveBean(Completion.class)); this.contextRunner .with(disableCommands("help", "clear", "quit", "stacktrace", "script", "history", "completion")) .withPropertyValues("spring.shell.command.completion.root-command=fake") - .run((context) -> {assertThat(context).doesNotHaveBean(Completion.class); - }); + .run(context -> assertThat(context).doesNotHaveBean(Completion.class)); this.contextRunner .with(disableCommands("help", "clear", "quit", "stacktrace", "script", "history")) .withPropertyValues("spring.shell.command.completion.root-command=fake") - .run((context) -> {assertThat(context).hasSingleBean(Completion.class); - }); + .run(context -> assertThat(context).hasSingleBean(Completion.class)); } @Test - public void testHelpCommand() { + void testHelpCommand() { this.contextRunner .with(disableCommands("clear", "quit", "stacktrace", "script", "history", "completion")) .withPropertyValues("spring.shell.command.help.grouping-mode=flat") @@ -67,7 +64,7 @@ public void testHelpCommand() { } private static Function disableCommands(String... commands) { - return (cr) -> { + return cr -> { for (String command : commands) { cr = cr.withPropertyValues(String.format("spring.shell.command.%s.enabled=false", command)); } diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/TerminalUIAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/TerminalUIAutoConfigurationTests.java index c8ccb03d1..d42a4071b 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/TerminalUIAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/TerminalUIAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -43,17 +43,15 @@ class TerminalUIAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(TerminalUIAutoConfiguration.class)); @Test - public void terminalUICreated() { + void terminalUICreated() { this.contextRunner .withUserConfiguration(MockConfiguration.class) - .run(context -> { - assertThat(context).hasSingleBean(TerminalUIBuilder.class); - }); + .run(context -> assertThat(context).hasSingleBean(TerminalUIBuilder.class)); } @Test @SuppressWarnings("unchecked") - public void canCustomize() { + void canCustomize() { this.contextRunner .withUserConfiguration(TestConfiguration.class, MockConfiguration.class) .run(context -> { @@ -81,9 +79,7 @@ ThemeResolver mockThemeResolver() { @Bean ThemeActive themeActive() { - return () -> { - return "default"; - }; + return () -> "default"; } } diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ThemingAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ThemingAutoConfigurationTests.java index 8ff0f344a..821aab26b 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ThemingAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/ThemingAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ThemingAutoConfigurationTests { +class ThemingAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(ThemingAutoConfiguration.class)); @@ -58,7 +58,7 @@ void createsDefaultBeans() { } @Test - public void canRegisterCustomTheme() { + void canRegisterCustomTheme() { this.contextRunner .withUserConfiguration(CustomThemeConfig.class) .run(context -> { @@ -113,7 +113,7 @@ public ThemeAssert(Theme actual) { public ThemeAssert hasName(String... names) { isNotNull(); - boolean match = Stream.of(names).filter(n -> actual.getName().equals(n)).findFirst().isPresent(); + boolean match = Stream.of(names).anyMatch(n -> actual.getName().equals(n)); if (!match) { failWithMessage("Expected theme to have names %s but was %s", StringUtils.arrayToCommaDelimitedString(names), actual.getName()); diff --git a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/UserConfigAutoConfigurationTests.java b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/UserConfigAutoConfigurationTests.java index c32b50715..1cd0e099e 100644 --- a/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/UserConfigAutoConfigurationTests.java +++ b/spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/UserConfigAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,15 +27,15 @@ import static org.assertj.core.api.Assertions.assertThat; -public class UserConfigAutoConfigurationTests { +class UserConfigAutoConfigurationTests { - private final static Logger log = LoggerFactory.getLogger(UserConfigAutoConfigurationTests.class); + private static final Logger log = LoggerFactory.getLogger(UserConfigAutoConfigurationTests.class); private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(UserConfigAutoConfiguration.class)); @Test - public void testDefaults() { + void testDefaults() { this.contextRunner .run(context -> { assertThat(context).hasSingleBean(UserConfigPathProvider.class); @@ -47,7 +47,7 @@ public void testDefaults() { } @Test - public void testUserConfig() { + void testUserConfig() { this.contextRunner .withPropertyValues("spring.shell.config.location={userconfig}/test") .run(context -> { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/AvailabilityReflectiveProcessorTests.java b/spring-shell-core/src/test/java/org/springframework/shell/AvailabilityReflectiveProcessorTests.java index 529af7715..d1984812f 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/AvailabilityReflectiveProcessorTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/AvailabilityReflectiveProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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,7 +31,7 @@ class AvailabilityReflectiveProcessorTests { private final ReflectionHints hints = new ReflectionHints(); @Test - void registerReflectiveHintsForMethod() throws NoSuchMethodException { + void registerReflectiveHintsForMethod() { processor.registerReflectionHints(hints, SampleBean.class); assertThat(hints.typeHints()).singleElement().satisfies(typeHint -> { assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleBean.class)); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/JnaRuntimeHintsTests.java b/spring-shell-core/src/test/java/org/springframework/shell/JnaRuntimeHintsTests.java index 48c63f08f..592ea8cfa 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/JnaRuntimeHintsTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/JnaRuntimeHintsTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2022-present 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 + * + * https://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.shell; import java.util.Arrays; @@ -14,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class JnaRuntimeHintsTests { +class JnaRuntimeHintsTests { @Test void test() { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/ShellTests.java b/spring-shell-core/src/test/java/org/springframework/shell/ShellTests.java index f91742921..bb113ec98 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/ShellTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/ShellTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-present 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. @@ -15,11 +15,10 @@ */ package org.springframework.shell; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,8 +31,7 @@ import org.springframework.shell.command.CommandRegistration; import org.springframework.shell.completion.RegistrationOptionsCompletionResolver; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doThrow; @@ -45,7 +43,7 @@ * @author Eric Bottard */ @ExtendWith(MockitoExtension.class) -public class ShellTests { +class ShellTests { @Mock private InputProvider inputProvider; @@ -59,15 +57,13 @@ public class ShellTests { @InjectMocks private Shell shell; - private boolean invoked; - @BeforeEach - public void setUp() { - shell.setCompletionResolvers(Arrays.asList(new RegistrationOptionsCompletionResolver())); + void setUp() { + shell.setCompletionResolvers(List.of(new RegistrationOptionsCompletionResolver())); } @Test - public void commandMatch() throws Exception { + void commandMatch() { when(inputProvider.readInput()).thenReturn(() -> "hello world how are you doing ?"); doThrow(new Exit()).when(resultHandlerService).handle(any()); @@ -81,19 +77,11 @@ public void commandMatch() throws Exception { registrations.put("hello world", registration); when(commandRegistry.getRegistrations()).thenReturn(registrations); - try { - shell.run(inputProvider); - fail("Exit expected"); - } - catch (Exit expected) { - System.out.println(expected); - } - - assertThat(invoked).isTrue(); + assertThatExceptionOfType(Exit.class).isThrownBy(() -> shell.run(inputProvider)); } @Test - public void commandNotFound() throws Exception { + void commandNotFound() { when(inputProvider.readInput()).thenReturn(() -> "hello world how are you doing ?"); doThrow(new Exit()).when(resultHandlerService).handle(isA(CommandNotFound.class)); @@ -107,18 +95,12 @@ public void commandNotFound() throws Exception { registrations.put("hello world", registration); when(commandRegistry.getRegistrations()).thenReturn(registrations); - try { - shell.run(inputProvider); - fail("Exit expected"); - } - catch (Exit expected) { - - } + assertThatExceptionOfType(Exit.class).isThrownBy(() -> shell.run(inputProvider)); } @Test // See https://github.com/spring-projects/spring-shell/issues/142 - public void commandNotFoundPrefix() throws Exception { + void commandNotFoundPrefix() { when(inputProvider.readInput()).thenReturn(() -> "helloworld how are you doing ?"); doThrow(new Exit()).when(resultHandlerService).handle(isA(CommandNotFound.class)); @@ -132,17 +114,11 @@ public void commandNotFoundPrefix() throws Exception { registrations.put("hello world", registration); when(commandRegistry.getRegistrations()).thenReturn(registrations); - try { - shell.run(inputProvider); - fail("Exit expected"); - } - catch (Exit expected) { - - } + assertThatExceptionOfType(Exit.class).isThrownBy(() -> shell.run(inputProvider)); } @Test - public void noCommand() throws Exception { + void noCommand() { when(inputProvider.readInput()).thenReturn(() -> "", () -> "hello world how are you doing ?", null); doThrow(new Exit()).when(resultHandlerService).handle(any()); @@ -156,19 +132,11 @@ public void noCommand() throws Exception { registrations.put("hello world", registration); when(commandRegistry.getRegistrations()).thenReturn(registrations); - try { - shell.run(inputProvider); - fail("Exit expected"); - } - catch (Exit expected) { - - } - - assertThat(invoked).isTrue(); + assertThatExceptionOfType(Exit.class).isThrownBy(() -> shell.run(inputProvider)); } @Test - public void commandThrowingAnException() throws Exception { + void commandThrowingAnException() { when(inputProvider.readInput()).thenReturn(() -> "fail"); doThrow(new Exit()).when(resultHandlerService).handle(isA(SomeException.class)); @@ -182,27 +150,18 @@ public void commandThrowingAnException() throws Exception { registrations.put("fail", registration); when(commandRegistry.getRegistrations()).thenReturn(registrations); - - try { - shell.run(inputProvider); - fail("Exit expected"); - } - catch (Exit expected) { - - } - - assertThat(invoked).isTrue(); + assertThatExceptionOfType(Exit.class).isThrownBy(() -> shell.run(inputProvider)); } @Test - public void comments() throws Exception { + void comments() throws Exception { when(inputProvider.readInput()).thenReturn(() -> "// This is a comment", (Input) null); shell.run(inputProvider); } @Test - public void commandNameCompletion() throws Exception { + void commandNameCompletion() { CommandRegistration registration1 = CommandRegistration.builder() .command("hello world") .withTarget() @@ -221,54 +180,52 @@ public void commandNameCompletion() throws Exception { when(commandRegistry.getRegistrations()).thenReturn(registrations); // Invoke at very start - List proposals = shell.complete(new CompletionContext(Arrays.asList(""), 0, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + List proposals = shell.complete(new CompletionContext(List.of(""), 0, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactlyInAnyOrder("another command", "hello world"); // Invoke in middle of first word - proposals = shell.complete(new CompletionContext(Arrays.asList("hel"), 0, "hel".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + proposals = shell.complete(new CompletionContext(List.of("hel"), 0, "hel".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactly("hello world"); // Invoke at end of first word (no space after yet) - proposals = shell.complete(new CompletionContext(Arrays.asList("hello"), 0, "hello".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + proposals = shell.complete(new CompletionContext(List.of("hello"), 0, "hello".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactly("hello world"); // Invoke after first word / start of second word - proposals = shell.complete(new CompletionContext(Arrays.asList("hello", ""), 1, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + proposals = shell.complete(new CompletionContext(List.of("hello", ""), 1, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactly("world"); // Invoke in middle of second word - proposals = shell.complete(new CompletionContext(Arrays.asList("hello", "wo"), 1, "wo".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + proposals = shell.complete(new CompletionContext(List.of("hello", "wo"), 1, "wo".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactly("world"); // Invoke at end of whole command (no space after yet) - proposals = shell.complete(new CompletionContext(Arrays.asList("hello", "world"), 1, "world".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + proposals = shell.complete(new CompletionContext(List.of("hello", "world"), 1, "world".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactly("world"); // Invoke in middle of second word - proposals = shell.complete(new CompletionContext(Arrays.asList("hello", "world", ""), 2, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + proposals = shell.complete(new CompletionContext(List.of("hello", "world", ""), 2, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).isEmpty(); } @SuppressWarnings("unused") private void helloWorld(String a) { - invoked = true; } @SuppressWarnings("unused") private String failing() { - invoked = true; throw new SomeException(); } @Test - public void completionArgWithMethod() throws Exception { + void completionArgWithMethod() { CommandRegistration registration1 = CommandRegistration.builder() .command("hello world") .withTarget() @@ -283,13 +240,13 @@ public void completionArgWithMethod() throws Exception { registrations.put("hello world", registration1); when(commandRegistry.getRegistrations()).thenReturn(registrations); - List proposals = shell.complete(new CompletionContext(Arrays.asList("hello", "world", ""), 2, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + List proposals = shell.complete(new CompletionContext(List.of("hello", "world", ""), 2, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactlyInAnyOrder("--arg1"); } @Test - public void completionArgWithFunction() throws Exception { + void completionArgWithFunction() { CommandRegistration registration1 = CommandRegistration.builder() .command("hello world") .withTarget() @@ -306,13 +263,13 @@ public void completionArgWithFunction() throws Exception { registrations.put("hello world", registration1); when(commandRegistry.getRegistrations()).thenReturn(registrations); - List proposals = shell.complete(new CompletionContext(Arrays.asList("hello", "world", ""), 2, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + List proposals = shell.complete(new CompletionContext(List.of("hello", "world", ""), 2, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals).containsExactlyInAnyOrder("--arg1"); } @Test - public void shouldCompleteWithCorrectArgument() throws Exception { + void shouldCompleteWithCorrectArgument() { CommandRegistration registration1 = CommandRegistration.builder() .command("hello world") .withTarget() @@ -320,27 +277,27 @@ public void shouldCompleteWithCorrectArgument() throws Exception { .and() .withOption() .longNames("arg1") - .completion(ctx -> Arrays.asList("arg1Comp1").stream().map(CompletionProposal::new).collect(Collectors.toList())) + .completion(ctx -> Stream.of("arg1Comp1").map(CompletionProposal::new).toList()) .and() .withOption() .longNames("arg2") - .completion(ctx -> Arrays.asList("arg2Comp1").stream().map(CompletionProposal::new).collect(Collectors.toList())) + .completion(ctx -> Stream.of("arg2Comp1").map(CompletionProposal::new).toList()) .and() .build(); Map registrations = new HashMap<>(); registrations.put("hello world", registration1); when(commandRegistry.getRegistrations()).thenReturn(registrations); - List proposals1 = shell.complete(new CompletionContext(Arrays.asList("hello", "world", "--arg1", ""), 3, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + List proposals1 = shell.complete(new CompletionContext(List.of("hello", "world", "--arg1", ""), 3, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals1).containsExactlyInAnyOrder("--arg2", "arg1Comp1"); - List proposals2 = shell.complete(new CompletionContext(Arrays.asList("hello", "world", "--arg1", "xxx", "--arg2", ""), 5, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + List proposals2 = shell.complete(new CompletionContext(List.of("hello", "world", "--arg1", "xxx", "--arg2", ""), 5, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals2).containsExactlyInAnyOrder("arg2Comp1"); - List proposals3 = shell.complete(new CompletionContext(Arrays.asList("hello", "world", "--arg2", "xxx", "--arg1", ""), 5, "".length(), null, null)) - .stream().map(CompletionProposal::value).collect(Collectors.toList()); + List proposals3 = shell.complete(new CompletionContext(List.of("hello", "world", "--arg2", "xxx", "--arg1", ""), 5, "".length(), null, null)) + .stream().map(CompletionProposal::value).toList(); assertThat(proposals3).containsExactlyInAnyOrder("arg1Comp1"); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/UtilsTests.java b/spring-shell-core/src/test/java/org/springframework/shell/UtilsTests.java index e63d1b841..46f19b4d6 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/UtilsTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/UtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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. @@ -15,7 +15,6 @@ */ package org.springframework.shell; -import java.util.Arrays; import java.util.List; import java.util.function.Predicate; @@ -28,10 +27,10 @@ * * @author Eric Bottard */ -public class UtilsTests { +class UtilsTests { @Test - public void testUnCamelify() throws Exception { + void testUnCamelify() { assertThat(Utils.unCamelify("HelloWorld")).isEqualTo("hello-world"); assertThat(Utils.unCamelify("helloWorld")).isEqualTo("hello-world"); assertThat(Utils.unCamelify("helloWorldHowAreYou")).isEqualTo("hello-world-how-are-you"); @@ -39,26 +38,26 @@ public void testUnCamelify() throws Exception { } @Test - public void testSplit() { + void testSplit() { Predicate predicate = t -> t.startsWith("-"); - List> split = null; + List> split; split = Utils.split(new String[] { "-a1", "a1" }, predicate); - assertThat(split).containsExactly(Arrays.asList("-a1", "a1")); + assertThat(split).containsExactly(List.of("-a1", "a1")); split = Utils.split(new String[] { "-a1", "a1", "-a2", "a2" }, predicate); - assertThat(split).containsExactly(Arrays.asList("-a1", "a1"), Arrays.asList("-a2", "a2")); + assertThat(split).containsExactly(List.of("-a1", "a1"), List.of("-a2", "a2")); split = Utils.split(new String[] { "a0", "-a1", "a1" }, predicate); - assertThat(split).containsExactly(Arrays.asList("a0"), Arrays.asList("-a1", "a1")); + assertThat(split).containsExactly(List.of("a0"), List.of("-a1", "a1")); split = Utils.split(new String[] { "-a1", "-a2" }, predicate); - assertThat(split).containsExactly(Arrays.asList("-a1"), Arrays.asList("-a2")); + assertThat(split).containsExactly(List.of("-a1"), List.of("-a2")); split = Utils.split(new String[] { "a1", "a2" }, predicate); - assertThat(split).containsExactly(Arrays.asList("a1", "a2")); + assertThat(split).containsExactly(List.of("a1", "a2")); split = Utils.split(new String[] { "-a1", "a1", "a2" }, predicate); - assertThat(split).containsExactly(Arrays.asList("-a1", "a1", "a2")); + assertThat(split).containsExactly(List.of("-a1", "a1", "a2")); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/ValueResultAsserts.java b/spring-shell-core/src/test/java/org/springframework/shell/ValueResultAsserts.java deleted file mode 100644 index 51da9c935..000000000 --- a/spring-shell-core/src/test/java/org/springframework/shell/ValueResultAsserts.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2017 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 - * - * https://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.shell; - -import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.Assertions; - -/** - * Assertions for {@link ValueResult}. - * - * @author Camilo Gonzalez - */ -public class ValueResultAsserts extends AbstractAssert { - - public ValueResultAsserts(ValueResult actual) { - super(actual, ValueResultAsserts.class); - } - - public ValueResultAsserts hasValue(Object expectedValue) { - isNotNull(); - Assertions.assertThat(actual.resolvedValue()).isEqualTo(expectedValue); - return this; - } - - public ValueResultAsserts usesWords(int... expectedWordsUsed) { - isNotNull(); - - Assertions.assertThat(actual.wordsUsed().stream().toArray()).containsExactly(expectedWordsUsed); - - return this; - } - - public ValueResultAsserts notUsesWords() { - isNotNull(); - Assertions.assertThat(actual.wordsUsed().isEmpty()); - return this; - } - - public ValueResultAsserts usesWordsForValue(int... expectedWordsUsedForValue) { - isNotNull(); - - Assertions.assertThat(actual.wordsUsedForValue().stream().toArray()).containsExactly(expectedWordsUsedForValue); - - return this; - } - - public ValueResultAsserts notUsesWordsForValue() { - isNotNull(); - Assertions.assertThat(actual.wordsUsedForValue().isEmpty()); - return this; - } - - public static ValueResultAsserts assertThat(ValueResult valueResult) { - return new ValueResultAsserts(valueResult); - } -} diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/AbstractCommandTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/AbstractCommandTests.java index 5dc15e304..3896162e7 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/AbstractCommandTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/AbstractCommandTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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,9 +30,7 @@ public abstract class AbstractCommandTests { return "hi" + arg1; }; - protected Function function2 = ctx -> { - return null; - }; + protected Function function2 = ctx -> null; @BeforeEach public void setupAbstractCommandTests() { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandCatalogTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandCatalogTests.java index b0664c33b..ec47fcd9b 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandCatalogTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandCatalogTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,17 +16,16 @@ package org.springframework.shell.command; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -public class CommandCatalogTests extends AbstractCommandTests { +class CommandCatalogTests extends AbstractCommandTests { @Test - public void testCommandCatalog () { + void testCommandCatalog () { CommandRegistration r1 = CommandRegistration.builder() .command("group1 sub1") .withTarget() @@ -37,11 +36,11 @@ public void testCommandCatalog () { catalog.register(r1); assertThat(catalog.getRegistrations()).hasSize(1); catalog.unregister(r1); - assertThat(catalog.getRegistrations()).hasSize(0); + assertThat(catalog.getRegistrations()).isEmpty(); } @Test - public void testCommandAliases () { + void testCommandAliases () { CommandRegistration r1 = CommandRegistration.builder() .command("group1 sub1") .withAlias() @@ -57,14 +56,14 @@ public void testCommandAliases () { } @Test - public void testResolver() { + void testResolver() { // catalog itself would not have any registered command but // this custom resolver adds one which may dymanically go away. DynamicCommandResolver resolver = new DynamicCommandResolver(); - CommandCatalog catalog = CommandCatalog.of(Arrays.asList(resolver), null); + CommandCatalog catalog = CommandCatalog.of(List.of(resolver), null); assertThat(catalog.getRegistrations()).hasSize(1); resolver.enabled = false; - assertThat(catalog.getRegistrations()).hasSize(0); + assertThat(catalog.getRegistrations()).isEmpty(); } class DynamicCommandResolver implements CommandResolver { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionCustomConversionTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionCustomConversionTests.java index 64a2edd2f..6b2d75eb9 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionCustomConversionTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionCustomConversionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,13 +30,13 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CommandExecutionCustomConversionTests { +class CommandExecutionCustomConversionTests { private CommandExecution execution; private CommandCatalog commandCatalog; @BeforeEach - public void setupCommandExecutionTests() { + void setupCommandExecutionTests() { commandCatalog = CommandCatalog.of(); DefaultConversionService conversionService = new DefaultConversionService(); conversionService.addConverter(new StringToMyPojo2Converter()); @@ -47,7 +47,7 @@ public void setupCommandExecutionTests() { } @Test - public void testCustomPojo() { + void testCustomPojo() { Pojo1 pojo1 = new Pojo1(); CommandRegistration r1 = CommandRegistration.builder() @@ -66,7 +66,7 @@ public void testCustomPojo() { } @Test - public void testCustomPojoArray() { + void testCustomPojoArray() { Pojo1 pojo1 = new Pojo1(); CommandRegistration r1 = CommandRegistration.builder() @@ -81,14 +81,13 @@ public void testCustomPojoArray() { .build(); commandCatalog.register(r1); execution.evaluate(new String[] { "command1", "--arg1", "a,b" }); - assertThat(pojo1.method2Pojo2).isNotNull(); - assertThat(pojo1.method2Pojo2.length).isEqualTo(2); + assertThat(pojo1.method2Pojo2).hasSize(2); assertThat(pojo1.method2Pojo2[0].arg).isEqualTo("a"); assertThat(pojo1.method2Pojo2[1].arg).isEqualTo("b"); } @Test - public void testCustomPojoArrayPositional() { + void testCustomPojoArrayPositional() { Pojo1 pojo1 = new Pojo1(); CommandRegistration r1 = CommandRegistration.builder() @@ -105,14 +104,13 @@ public void testCustomPojoArrayPositional() { .build(); commandCatalog.register(r1); execution.evaluate(new String[] { "command1", "a,b" }); - assertThat(pojo1.method2Pojo2).isNotNull(); - assertThat(pojo1.method2Pojo2.length).isEqualTo(2); + assertThat(pojo1.method2Pojo2).isNotNull().hasSize(2); assertThat(pojo1.method2Pojo2[0].arg).isEqualTo("a"); assertThat(pojo1.method2Pojo2[1].arg).isEqualTo("b"); } @Test - public void testCustomPojoList() { + void testCustomPojoList() { Pojo1 pojo1 = new Pojo1(); ResolvableType type = ResolvableType.forClassWithGenerics(List.class, Pojo1.class); @@ -130,15 +128,14 @@ public void testCustomPojoList() { .build(); commandCatalog.register(r1); execution.evaluate(new String[] { "command1", "--arg1", "a,b" }); - assertThat(pojo1.method3Pojo2).isNotNull(); - assertThat(pojo1.method3Pojo2.size()).isEqualTo(2); + assertThat(pojo1.method3Pojo2).isNotNull().hasSize(2); assertThat(pojo1.method3Pojo2.get(0)).isInstanceOf(Pojo2.class); assertThat(pojo1.method3Pojo2.get(0).arg).isEqualTo("a"); assertThat(pojo1.method3Pojo2.get(1).arg).isEqualTo("b"); } @Test - public void testCustomPojoListPositional() { + void testCustomPojoListPositional() { Pojo1 pojo1 = new Pojo1(); ResolvableType type = ResolvableType.forClassWithGenerics(List.class, Pojo1.class); @@ -158,15 +155,14 @@ public void testCustomPojoListPositional() { .build(); commandCatalog.register(r1); execution.evaluate(new String[] { "command1", "a,b" }); - assertThat(pojo1.method3Pojo2).isNotNull(); - assertThat(pojo1.method3Pojo2.size()).isEqualTo(2); + assertThat(pojo1.method3Pojo2).isNotNull().hasSize(2); assertThat(pojo1.method3Pojo2.get(0)).isInstanceOf(Pojo2.class); assertThat(pojo1.method3Pojo2.get(0).arg).isEqualTo("a"); assertThat(pojo1.method3Pojo2.get(1).arg).isEqualTo("b"); } @Test - public void testCustomPojoSet() { + void testCustomPojoSet() { Pojo1 pojo1 = new Pojo1(); CommandRegistration r1 = CommandRegistration.builder() @@ -181,14 +177,13 @@ public void testCustomPojoSet() { .build(); commandCatalog.register(r1); execution.evaluate(new String[] { "command1", "--arg1", "a,b" }); - assertThat(pojo1.method4Pojo2).isNotNull(); - assertThat(pojo1.method4Pojo2.size()).isEqualTo(2); + assertThat(pojo1.method4Pojo2).isNotNull().hasSize(2); assertThat(pojo1.method4Pojo2.iterator().next()).isInstanceOf(Pojo2.class); assertThat(pojo1.method4Pojo2.stream().map(pojo -> pojo.arg).toList()).containsExactly("a", "b"); } @Test - public void testCustomPojoSetPositional() { + void testCustomPojoSetPositional() { Pojo1 pojo1 = new Pojo1(); CommandRegistration r1 = CommandRegistration.builder() @@ -205,8 +200,7 @@ public void testCustomPojoSetPositional() { .build(); commandCatalog.register(r1); execution.evaluate(new String[] { "command1", "a,b" }); - assertThat(pojo1.method4Pojo2).isNotNull(); - assertThat(pojo1.method4Pojo2.size()).isEqualTo(2); + assertThat(pojo1.method4Pojo2).isNotNull().hasSize(2); assertThat(pojo1.method4Pojo2.iterator().next()).isInstanceOf(Pojo2.class); assertThat(pojo1.method4Pojo2.stream().map(pojo -> pojo.arg).toList()).containsExactly("a", "b"); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionTests.java index 76951b66a..d35ae6521 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandExecutionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class CommandExecutionTests extends AbstractCommandTests { +class CommandExecutionTests extends AbstractCommandTests { private CommandExecution execution; private CommandCatalog commandCatalog; @BeforeEach - public void setupCommandExecutionTests() { + void setupCommandExecutionTests() { commandCatalog = CommandCatalog.of(); ConversionService conversionService = new DefaultConversionService(); List resolvers = new ArrayList<>(); @@ -51,7 +51,7 @@ public void setupCommandExecutionTests() { } @Test - public void testFunctionExecution() { + void testFunctionExecution() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -69,7 +69,7 @@ public void testFunctionExecution() { } @Test - public void testMethodExecution1() { + void testMethodExecution1() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -88,7 +88,7 @@ public void testMethodExecution1() { } @Test - public void testMethodExecution2() { + void testMethodExecution2() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -107,7 +107,7 @@ public void testMethodExecution2() { } @Test - public void testMixedWithCtx1() { + void testMixedWithCtx1() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -132,7 +132,7 @@ public void testMixedWithCtx1() { } @Test - public void testMixedWithCtx2() { + void testMixedWithCtx2() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -157,7 +157,7 @@ public void testMixedWithCtx2() { } @Test - public void testMixedWithCtx3() { + void testMixedWithCtx3() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -182,7 +182,7 @@ public void testMixedWithCtx3() { } @Test - public void testMethodArgWithoutValue() { + void testMethodArgWithoutValue() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -202,7 +202,7 @@ public void testMethodArgWithoutValue() { } @Test - public void testMethodSinglePositionalArgs() { + void testMethodSinglePositionalArgs() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -223,7 +223,7 @@ public void testMethodSinglePositionalArgs() { } @Test - public void testMethodSingleWithNamedArgs() { + void testMethodSingleWithNamedArgs() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -242,7 +242,7 @@ public void testMethodSingleWithNamedArgs() { } @Test - public void testMethodMultiPositionalArgs() { + void testMethodMultiPositionalArgs() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -263,7 +263,7 @@ public void testMethodMultiPositionalArgs() { } @Test - public void testMethodMultiPositionalArgsAll() { + void testMethodMultiPositionalArgsAll() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -284,7 +284,7 @@ public void testMethodMultiPositionalArgsAll() { } @Test - public void testMethodMultiPositionalArgsAllToArray1() { + void testMethodMultiPositionalArgsAllToArray1() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -305,7 +305,7 @@ public void testMethodMultiPositionalArgsAllToArray1() { } @Test - public void testMethodMultiPositionalArgsAllToArray2() { + void testMethodMultiPositionalArgsAllToArray2() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -326,7 +326,7 @@ public void testMethodMultiPositionalArgsAllToArray2() { } @Test - public void testMethodMultipleArgs() { + void testMethodMultipleArgs() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -358,7 +358,7 @@ public void testMethodMultipleArgs() { @Test - public void testMethodMultipleIntArgs() { + void testMethodMultipleIntArgs() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -388,7 +388,7 @@ public void testMethodMultipleIntArgs() { } @Test - public void testMethodMultiplePositionalStringArgs() { + void testMethodMultiplePositionalStringArgs() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -430,7 +430,7 @@ public void testMethodMultiplePositionalStringArgs() { "command1 --arg1 myarg1value myarg2value --arg3 myarg3value", "command1 --arg1 myarg1value --arg2 myarg2value myarg3value" }) - public void testMethodMultiplePositionalStringArgsMixed(String arg) { + void testMethodMultiplePositionalStringArgsMixed(String arg) { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -466,7 +466,7 @@ public void testMethodMultiplePositionalStringArgsMixed(String arg) { } @Test - public void testShortCombinedWithoutValue() { + void testShortCombinedWithoutValue() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -497,7 +497,7 @@ public void testShortCombinedWithoutValue() { } @Test - public void testShortCombinedSomeHavingValue() { + void testShortCombinedSomeHavingValue() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -528,7 +528,7 @@ public void testShortCombinedSomeHavingValue() { } @Test - public void testFloatArrayOne() { + void testFloatArrayOne() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -547,7 +547,7 @@ public void testFloatArrayOne() { } @Test - public void testFloatArrayTwo() { + void testFloatArrayTwo() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -566,7 +566,7 @@ public void testFloatArrayTwo() { } @Test - public void testDefaultValueAsNull() { + void testDefaultValueAsNull() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .withOption() @@ -583,7 +583,7 @@ public void testDefaultValueAsNull() { } @Test - public void testDefaultValue() { + void testDefaultValue() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .withOption() @@ -603,7 +603,7 @@ public void testDefaultValue() { } @Test - public void testRequiredArg() { + void testRequiredArg() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .withOption() @@ -616,13 +616,11 @@ public void testRequiredArg() { .build(); commandCatalog.register(r1); - assertThatThrownBy(() -> { - execution.evaluate(new String[] { "command1" }); - }).isInstanceOf(CommandParserExceptionsException.class); + assertThatThrownBy(() -> execution.evaluate(new String[] { "command1" })).isInstanceOf(CommandParserExceptionsException.class); } @Test - public void testCommandNotAvailable() { + void testCommandNotAvailable() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") @@ -641,7 +639,7 @@ public void testCommandNotAvailable() { } @Test - public void testExecutionWithModifiedLongOption() { + void testExecutionWithModifiedLongOption() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .withOption() diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandHandlingResultTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandHandlingResultTests.java index 55fcc48e6..4720542e7 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandHandlingResultTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandHandlingResultTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CommandHandlingResultTests { +class CommandHandlingResultTests { @Test void hasMessageFromOf() { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserExceptionResolverTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserExceptionResolverTests.java index 92419ac32..c7f229167 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserExceptionResolverTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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. @@ -15,7 +15,6 @@ */ package org.springframework.shell.command; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; @@ -38,7 +37,7 @@ void resolvesCommandParserException() { static CommandParserExceptionsException genericParserException() { CommandParserException e = new CommandParserException("hi"); - List parserExceptions = Arrays.asList(e); + List parserExceptions = List.of(e); return new CommandParserExceptionsException("msg", parserExceptions); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserTests.java index db9a80fea..f83e74d3e 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CommandParserTests extends AbstractCommandTests { +class CommandParserTests extends AbstractCommandTests { @Test - public void testMethodExecution1() { + void testMethodExecution1() { CommandRegistration r1 = CommandRegistration.builder() .command("command1") .description("help") diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandRegistrationTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandRegistrationTests.java index 0df451396..8d82c5ab7 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/CommandRegistrationTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/CommandRegistrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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. @@ -29,17 +29,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class CommandRegistrationTests extends AbstractCommandTests { +class CommandRegistrationTests extends AbstractCommandTests { @Test - public void testCommandMustBeSet() { - assertThatThrownBy(() -> { - CommandRegistration.builder().build(); - }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("command cannot be empty"); + void testCommandMustBeSet() { + assertThatThrownBy(() -> CommandRegistration.builder().build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("command cannot be empty"); } @Test - public void testBasics() { + void testBasics() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withTarget() @@ -63,7 +63,7 @@ public void testBasics() { } @Test - public void testCommandStructures() { + void testCommandStructures() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withTarget() @@ -98,7 +98,7 @@ public void testCommandStructures() { } @Test - public void testFunctionRegistration() { + void testFunctionRegistration() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withTarget() @@ -112,7 +112,7 @@ public void testFunctionRegistration() { } @Test - public void testConsumerRegistration() { + void testConsumerRegistration() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withTarget() @@ -127,7 +127,7 @@ public void testConsumerRegistration() { } @Test - public void testMethodRegistration() { + void testMethodRegistration() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withTarget() @@ -141,20 +141,18 @@ public void testMethodRegistration() { } @Test - public void testCanUseOnlyOneTarget() { - assertThatThrownBy(() -> { - CommandRegistration.builder() - .command("command1") - .withTarget() - .method(pojo1, "method3", String.class) - .function(function1) - .and() - .build(); - }).isInstanceOf(IllegalStateException.class).hasMessageContaining("only one target can exist"); + void testCanUseOnlyOneTarget() { + assertThatThrownBy(() -> CommandRegistration.builder() + .command("command1") + .withTarget() + .method(pojo1, "method3", String.class) + .function(function1) + .and() + .build()).isInstanceOf(IllegalStateException.class).hasMessageContaining("only one target can exist"); } @Test - public void testSimpleFullRegistrationWithFunction() { + void testSimpleFullRegistrationWithFunction() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .description("help") @@ -173,7 +171,7 @@ public void testSimpleFullRegistrationWithFunction() { } @Test - public void testSimpleFullRegistrationWithMethod() { + void testSimpleFullRegistrationWithMethod() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .description("help") @@ -191,7 +189,7 @@ public void testSimpleFullRegistrationWithMethod() { } @Test - public void testOptionWithType() { + void testOptionWithType() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .description("help") @@ -214,7 +212,7 @@ public void testOptionWithType() { } @Test - public void testOptionWithResolvableType() { + void testOptionWithResolvableType() { ResolvableType rtype = ResolvableType.forClassWithGenerics(List.class, String.class); CommandRegistration registration = CommandRegistration.builder() .command("command1") @@ -228,13 +226,11 @@ public void testOptionWithResolvableType() { .build(); assertThat(registration.getCommand()).isEqualTo("command1"); assertThat(registration.getOptions()).hasSize(1); - assertThat(registration.getOptions().get(0).getType()).satisfies(type -> { - assertThat(type).isEqualTo(rtype); - }); + assertThat(registration.getOptions().get(0).getType()).satisfies(type -> assertThat(type).isEqualTo(rtype)); } @Test - public void testOptionWithRequired() { + void testOptionWithRequired() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .description("help") @@ -306,7 +302,7 @@ public void testOptionWithRequired() { } @Test - public void testOptionWithDefaultValue() { + void testOptionWithDefaultValue() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .description("help") @@ -327,7 +323,7 @@ public void testOptionWithDefaultValue() { } @Test - public void testOptionWithPositionValue() { + void testOptionWithPositionValue() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withOption() @@ -348,7 +344,7 @@ public void testOptionWithPositionValue() { } @Test - public void testArityViaInts() { + void testArityViaInts() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withOption() @@ -360,12 +356,12 @@ public void testArityViaInts() { .and() .build(); assertThat(registration.getOptions()).hasSize(1); - assertThat(registration.getOptions().get(0).getArityMin()).isEqualTo(0); - assertThat(registration.getOptions().get(0).getArityMax()).isEqualTo(0); + assertThat(registration.getOptions().get(0).getArityMin()).isZero(); + assertThat(registration.getOptions().get(0).getArityMax()).isZero(); } @Test - public void testArityViaEnum() { + void testArityViaEnum() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withOption() @@ -377,12 +373,12 @@ public void testArityViaEnum() { .and() .build(); assertThat(registration.getOptions()).hasSize(1); - assertThat(registration.getOptions().get(0).getArityMin()).isEqualTo(0); - assertThat(registration.getOptions().get(0).getArityMax()).isEqualTo(0); + assertThat(registration.getOptions().get(0).getArityMin()).isZero(); + assertThat(registration.getOptions().get(0).getArityMax()).isZero(); } @Test - public void testArityViaEnumSetNone() { + void testArityViaEnumSetNone() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withOption() @@ -399,7 +395,7 @@ public void testArityViaEnumSetNone() { } @Test - public void testAliases() { + void testAliases() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .group("Test Group") @@ -425,7 +421,7 @@ public void testAliases() { } @Test - public void testExitCodes() { + void testExitCodes() { CommandRegistration registration; registration = CommandRegistration.builder() .command("command1") @@ -434,7 +430,7 @@ public void testExitCodes() { .and() .build(); assertThat(registration.getExitCode()).isNotNull(); - assertThat(registration.getExitCode().getMappingFunctions()).hasSize(0); + assertThat(registration.getExitCode().getMappingFunctions()).isEmpty(); registration = CommandRegistration.builder() .command("command1") @@ -453,7 +449,7 @@ public void testExitCodes() { } @Test - public void testAvailability() { + void testAvailability() { CommandRegistration registration; registration = CommandRegistration.builder() .command("command1") @@ -476,15 +472,13 @@ public void testAvailability() { } @Test - public void testOptionWithCompletion() { + void testOptionWithCompletion() { CommandRegistration registration; registration = CommandRegistration.builder() .command("command1") .withOption() .longNames("arg1") - .completion(ctx -> { - return new ArrayList<>(); - }) + .completion(ctx -> new ArrayList<>()) .and() .withTarget() .function(function1) @@ -495,13 +489,8 @@ public void testOptionWithCompletion() { } @Test - public void testErrorHandling() { - CommandExceptionResolver er1 = new CommandExceptionResolver() { - @Override - public CommandHandlingResult resolve(Exception e) { - return CommandHandlingResult.empty(); - } - }; + void testErrorHandling() { + CommandExceptionResolver er1 = e -> CommandHandlingResult.empty(); CommandRegistration registration; registration = CommandRegistration.builder() .command("command1") @@ -521,11 +510,11 @@ public CommandHandlingResult resolve(Exception e) { .function(function1) .and() .build(); - assertThat(registration.getExceptionResolvers()).hasSize(0); + assertThat(registration.getExceptionResolvers()).isEmpty(); } @Test - public void testHidden() { + void testHidden() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withTarget() @@ -563,13 +552,13 @@ public void testHidden() { } @Test - public void testHelpOption() { + void testHelpOption() { CommandRegistration registration = CommandRegistration.builder() .command("command1") .withHelpOptions() .enabled(true) - .longNames(new String[] { "help" }) - .shortNames(new Character[] { 'h' }) + .longNames("help") + .shortNames('h') .command("help") .and() .withTarget() diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/ExceptionResolverMethodResolverTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/ExceptionResolverMethodResolverTests.java index 1c8e3398d..efb64f7ca 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/ExceptionResolverMethodResolverTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/ExceptionResolverMethodResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/MethodCommandExceptionResolverTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/MethodCommandExceptionResolverTests.java index b5db4d766..8fd233302 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/MethodCommandExceptionResolverTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/MethodCommandExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandAnnotationUtilsTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandAnnotationUtilsTests.java index c754d6e6e..32cb1d307 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandAnnotationUtilsTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandAnnotationUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,9 +26,9 @@ class CommandAnnotationUtilsTests { - private static MergedAnnotation hiddenTrue = MergedAnnotations.from(HiddenTrue.class).get(Command.class); - private static MergedAnnotation hiddenFalse = MergedAnnotations.from(HiddenFalse.class).get(Command.class); - private static MergedAnnotation hiddenDefault = MergedAnnotations.from(HiddenDefault.class) + private static final MergedAnnotation hiddenTrue = MergedAnnotations.from(HiddenTrue.class).get(Command.class); + private static final MergedAnnotation hiddenFalse = MergedAnnotations.from(HiddenFalse.class).get(Command.class); + private static final MergedAnnotation hiddenDefault = MergedAnnotations.from(HiddenDefault.class) .get(Command.class); @Command(hidden = true) @@ -54,15 +54,15 @@ void testHidden() { assertThat(CommandAnnotationUtils.deduceHidden(hiddenFalse, hiddenTrue)).isTrue(); } - private static MergedAnnotation commandDefault = MergedAnnotations.from(CommandDefault.class) + private static final MergedAnnotation commandDefault = MergedAnnotations.from(CommandDefault.class) .get(Command.class); - private static MergedAnnotation commandValues1 = MergedAnnotations.from(CommandValues1.class) + private static final MergedAnnotation commandValues1 = MergedAnnotations.from(CommandValues1.class) .get(Command.class); - private static MergedAnnotation commandValues2 = MergedAnnotations.from(CommandValues2.class) + private static final MergedAnnotation commandValues2 = MergedAnnotations.from(CommandValues2.class) .get(Command.class); - private static MergedAnnotation commandValues3 = MergedAnnotations.from(CommandValues3.class) + private static final MergedAnnotation commandValues3 = MergedAnnotations.from(CommandValues3.class) .get(Command.class); - private static MergedAnnotation commandValues4 = MergedAnnotations.from(CommandValues4.class) + private static final MergedAnnotation commandValues4 = MergedAnnotations.from(CommandValues4.class) .get(Command.class); @Command @@ -98,19 +98,19 @@ void testCommand() { .isEqualTo(new String[] { "eight", "nine" }); } - private static MergedAnnotation aliasDefault = MergedAnnotations.from(AliasDefault.class) + private static final MergedAnnotation aliasDefault = MergedAnnotations.from(AliasDefault.class) .get(Command.class); - private static MergedAnnotation aliasValues1 = MergedAnnotations.from(AliasValues1.class) + private static final MergedAnnotation aliasValues1 = MergedAnnotations.from(AliasValues1.class) .get(Command.class); - private static MergedAnnotation aliasValues2 = MergedAnnotations.from(AliasValues2.class) + private static final MergedAnnotation aliasValues2 = MergedAnnotations.from(AliasValues2.class) .get(Command.class); - private static MergedAnnotation aliasValues3 = MergedAnnotations.from(AliasValues3.class) + private static final MergedAnnotation aliasValues3 = MergedAnnotations.from(AliasValues3.class) .get(Command.class); - private static MergedAnnotation aliasValues4 = MergedAnnotations.from(AliasValues4.class) + private static final MergedAnnotation aliasValues4 = MergedAnnotations.from(AliasValues4.class) .get(Command.class); - private static MergedAnnotation aliasValues5 = MergedAnnotations.from(AliasValues5.class) + private static final MergedAnnotation aliasValues5 = MergedAnnotations.from(AliasValues5.class) .get(Command.class); - private static MergedAnnotation aliasValues6 = MergedAnnotations.from(AliasValues6.class) + private static final MergedAnnotation aliasValues6 = MergedAnnotations.from(AliasValues6.class) .get(Command.class); @Command @@ -156,11 +156,11 @@ void testAlias() { .isEqualTo(new String[][] { { "one" } }); } - private static MergedAnnotation groupValue1 = MergedAnnotations.from(GroupValues1.class) + private static final MergedAnnotation groupValue1 = MergedAnnotations.from(GroupValues1.class) .get(Command.class); - private static MergedAnnotation groupValue2 = MergedAnnotations.from(GroupValues2.class) + private static final MergedAnnotation groupValue2 = MergedAnnotations.from(GroupValues2.class) .get(Command.class); - private static MergedAnnotation groupDefault = MergedAnnotations.from(GroupDefault.class) + private static final MergedAnnotation groupDefault = MergedAnnotations.from(GroupDefault.class) .get(Command.class); @Command(group = "group1") @@ -177,17 +177,17 @@ private static class GroupDefault { @Test void testGroup() { - assertThat(CommandAnnotationUtils.deduceGroup(groupDefault, groupDefault)).isEqualTo(""); + assertThat(CommandAnnotationUtils.deduceGroup(groupDefault, groupDefault)).isEmpty(); assertThat(CommandAnnotationUtils.deduceGroup(groupDefault, groupValue1)).isEqualTo("group1"); assertThat(CommandAnnotationUtils.deduceGroup(groupValue1, groupDefault)).isEqualTo("group1"); assertThat(CommandAnnotationUtils.deduceGroup(groupValue1, groupValue2)).isEqualTo("group2"); } - private static MergedAnnotation descriptionValue1 = MergedAnnotations.from(DescriptionValues1.class) + private static final MergedAnnotation descriptionValue1 = MergedAnnotations.from(DescriptionValues1.class) .get(Command.class); - private static MergedAnnotation descriptionValue2 = MergedAnnotations.from(DescriptionValues2.class) + private static final MergedAnnotation descriptionValue2 = MergedAnnotations.from(DescriptionValues2.class) .get(Command.class); - private static MergedAnnotation descriptionDefault = MergedAnnotations.from(DescriptionDefault.class) + private static final MergedAnnotation descriptionDefault = MergedAnnotations.from(DescriptionDefault.class) .get(Command.class); @Command(description = "description1") @@ -204,7 +204,7 @@ private static class DescriptionDefault { @Test void testDescription() { - assertThat(CommandAnnotationUtils.deduceDescription(descriptionDefault, descriptionDefault)).isEqualTo(""); + assertThat(CommandAnnotationUtils.deduceDescription(descriptionDefault, descriptionDefault)).isEmpty(); assertThat(CommandAnnotationUtils.deduceDescription(descriptionDefault, descriptionValue1)) .isEqualTo("description1"); assertThat(CommandAnnotationUtils.deduceDescription(descriptionValue1, descriptionDefault)) @@ -213,13 +213,13 @@ void testDescription() { .isEqualTo("description2"); } - private static MergedAnnotation interactionModeDefault = MergedAnnotations + private static final MergedAnnotation interactionModeDefault = MergedAnnotations .from(InteractionModeDefault.class).get(Command.class); - private static MergedAnnotation interactionModeAll = MergedAnnotations.from(InteractionModeAll.class) + private static final MergedAnnotation interactionModeAll = MergedAnnotations.from(InteractionModeAll.class) .get(Command.class); - private static MergedAnnotation interactionModeInteractive = MergedAnnotations + private static final MergedAnnotation interactionModeInteractive = MergedAnnotations .from(InteractionModeInteractive.class).get(Command.class); - private static MergedAnnotation interactionModeNoninteractive = MergedAnnotations + private static final MergedAnnotation interactionModeNoninteractive = MergedAnnotations .from(InteractionModeNoninteractive.class).get(Command.class); @Command() diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationBeanRegistrarTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationBeanRegistrarTests.java index 59efc8bc6..deacfb231 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationBeanRegistrarTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationBeanRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationFactoryBeanTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationFactoryBeanTests.java index 95263b736..f7d4dcb18 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationFactoryBeanTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/annotation/support/CommandRegistrationFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,15 +37,15 @@ class CommandRegistrationFactoryBeanTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); - private final static String BEAN = "commandBean"; - private final static String FACTORYBEAN = "commandRegistrationFactoryBean"; - private final static String FACTORYBEANREF = "&" + FACTORYBEAN; + private static final String BEAN = "commandBean"; + private static final String FACTORY_BEAN = "commandRegistrationFactoryBean"; + private static final String FACTORY_BEAN_REF = "&" + FACTORY_BEAN; @Test void hiddenOnClassLevel() { configCommon(HiddenOnClassBean.class, new HiddenOnClassBean()) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -65,8 +65,8 @@ void command(){ @Test void commandCommonThings() { configCommon(OnBothClassAndMethod.class, new OnBothClassAndMethod(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -78,7 +78,7 @@ void commandCommonThings() { }); configCommon(OnBothClassAndMethod.class, new OnBothClassAndMethod(), "command2", new Class[] { }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -106,8 +106,8 @@ void command2(){ @Test void setsRequiredOption() { configCommon(RequiredOption.class, new RequiredOption(), "command1", new Class[] { String.class }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -117,7 +117,7 @@ void setsRequiredOption() { }); configCommon(RequiredOption.class, new RequiredOption(), "command2", new Class[] { String.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -142,8 +142,8 @@ void command2(@Option(required = false) String arg) { @Test void setsAvailabilitySupplier() { configCommon(AvailabilityIndicator.class, new AvailabilityIndicator(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -172,7 +172,7 @@ public AvailabilityProvider testAvailability() { void setsOptionValuesWithBoolean() { configCommon(OptionValuesWithBoolean.class, new OptionValuesWithBoolean(), "command1", new Class[] { boolean.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -182,7 +182,7 @@ void setsOptionValuesWithBoolean() { }); configCommon(OptionValuesWithBoolean.class, new OptionValuesWithBoolean(), "command2", new Class[] { Boolean.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -192,7 +192,7 @@ void setsOptionValuesWithBoolean() { }); configCommon(OptionValuesWithBoolean.class, new OptionValuesWithBoolean(), "command3", new Class[] { Boolean.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -202,7 +202,7 @@ void setsOptionValuesWithBoolean() { }); configCommon(OptionValuesWithBoolean.class, new OptionValuesWithBoolean(), "command4", new Class[] { Boolean.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -212,7 +212,7 @@ void setsOptionValuesWithBoolean() { }); configCommon(OptionValuesWithBoolean.class, new OptionValuesWithBoolean(), "command5", new Class[] { boolean.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -251,8 +251,8 @@ void command5(boolean arg) { @Test void setsOptionWithCompletion() { configCommon(OptionWithCompletion.class, new OptionWithCompletion(), "command1", new Class[] { String.class }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -270,9 +270,7 @@ void command1(@Option(longNames = "arg") @OptionValues(provider = "completionPro @Bean CompletionProvider completionProvider() { - return ctx -> { - return Collections.emptyList(); - }; + return ctx -> Collections.emptyList(); } } @@ -280,8 +278,8 @@ CompletionProvider completionProvider() { @Test void setsOptionWithArity() { configCommon(OptionWithArity.class, new OptionWithArity(), "command1", new Class[] { String.class }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -291,7 +289,7 @@ void setsOptionWithArity() { }); configCommon(OptionWithArity.class, new OptionWithArity(), "command2", new Class[] { String.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -301,7 +299,7 @@ void setsOptionWithArity() { }); configCommon(OptionWithArity.class, new OptionWithArity(), "command3", new Class[] { String.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -311,7 +309,7 @@ void setsOptionWithArity() { }); configCommon(OptionWithArity.class, new OptionWithArity(), "command4", new Class[] { String.class }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -344,8 +342,8 @@ void command4(@Option(longNames = "arg", arityMax = 2, arity = OptionArity.EXACT @Test void setsOptionWithLabel() { configCommon(OptionWithLabel.class, new OptionWithLabel(), "command1", new Class[] { String.class }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -369,7 +367,7 @@ private ApplicationContextRunner configCommon(Class type, T bean) { private ApplicationContextRunner configCommon(Class type, T bean, String method, Class[] parameters) { return this.contextRunner .withBean(BEAN, type, () -> bean) - .withBean(FACTORYBEAN, CommandRegistrationFactoryBean.class, () -> new CommandRegistrationFactoryBean(), bd -> { + .withBean(FACTORY_BEAN, CommandRegistrationFactoryBean.class, CommandRegistrationFactoryBean::new, bd -> { bd.getPropertyValues().add(CommandRegistrationFactoryBean.COMMAND_BEAN_TYPE, type); bd.getPropertyValues().add(CommandRegistrationFactoryBean.COMMAND_BEAN_NAME, BEAN); bd.getPropertyValues().add(CommandRegistrationFactoryBean.COMMAND_METHOD_NAME, method); @@ -383,8 +381,8 @@ class Aliases { @Test void aliasOnlyOnMethod() { configCommon(AliasOnlyOnMethod.class, new AliasOnlyOnMethod(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -406,8 +404,8 @@ void command1(){ @Test void aliasOnlyOnClass() { configCommon(AliasOnlyOnClass.class, new AliasOnlyOnClass(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -428,8 +426,8 @@ void command1(){ @Test void aliasOnlyOnMethodMultiCommandString() { configCommon(AliasOnlyOnMethodMultiCommandString.class, new AliasOnlyOnMethodMultiCommandString(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -452,7 +450,7 @@ void command1(){ void aliasOnlyOnMethodMultiCommandArray() { configCommon(AliasOnlyOnMethodMultiCommandArray.class, new AliasOnlyOnMethodMultiCommandArray(), "command1", new Class[] { }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -475,8 +473,8 @@ void command1(){ @Test void aliasOnBothMethodStringEmpty() { configCommon(AliasOnBothMethodStringEmpty.class, new AliasOnBothMethodStringEmpty(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -498,8 +496,8 @@ void command1(){ @Test void aliasOnBoth() { configCommon(AliasOnBoth.class, new AliasOnBoth(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -521,8 +519,8 @@ void command1(){ @Test void aliasWithCommandOnBothMethodStringEmpty() { configCommon(AliasWithCommandOnBothMethodStringEmpty.class, new AliasWithCommandOnBothMethodStringEmpty(), "command1", new Class[] { }) - .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + .run(context -> { + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); @@ -533,7 +531,7 @@ void aliasWithCommandOnBothMethodStringEmpty() { }); configCommon(AliasWithCommandOnBothMethodStringEmpty.class, new AliasWithCommandOnBothMethodStringEmpty(), "command2", new Class[] { }) .run((context) -> { - CommandRegistrationFactoryBean fb = context.getBean(FACTORYBEANREF, + CommandRegistrationFactoryBean fb = context.getBean(FACTORY_BEAN_REF, CommandRegistrationFactoryBean.class); assertThat(fb).isNotNull(); CommandRegistration registration = fb.getObject(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/invocation/InvocableShellMethodTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/invocation/InvocableShellMethodTests.java index 30ae665a7..fe7f15d98 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/invocation/InvocableShellMethodTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/invocation/InvocableShellMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,7 +26,7 @@ class InvocableShellMethodTests { @Test - public void resolveArg() throws Exception { + void resolveArg() throws Exception { Handler bean = new Handler(); Method method = ReflectionUtils.findMethod(Handler.class, "handle", Integer.class, String.class); InvocableShellMethod invocable = new InvocableShellMethod(bean, method); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AbstractParsingTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AbstractParsingTests.java index fe5b2a580..5797e1c5b 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AbstractParsingTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AbstractParsingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AstTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AstTests.java index 798322458..d0b9cb774 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AstTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/AstTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -74,9 +74,7 @@ void createsMultipleCommandNodes() { assertThat(n4).isInstanceOf(OptionNode.class); OptionNode on4 = (OptionNode)n4; assertThat(on4.getChildren()).satisfiesExactly( - n5 -> { - assertThat(n5).isInstanceOf(OptionArgumentNode.class); - } + n5 -> assertThat(n5).isInstanceOf(OptionArgumentNode.class) ); } ); @@ -101,10 +99,8 @@ void createsOptionNodeNoOptionArg() { assertThat(cn.getCommand()).isEqualTo("root3"); assertThat(cn.getChildren()).hasSize(1); assertThat(cn.getChildren()) - .filteredOn(on -> on instanceof OptionNode) - .extracting(on -> { - return ((OptionNode)on).getName(); - }) + .filteredOn(OptionNode.class::isInstance) + .extracting(on -> ((OptionNode)on).getName()) .containsExactly("--arg1"); }); } @@ -125,10 +121,8 @@ void createsOptionNodeWithOptionArg() { assertThat(cn.getCommand()).isEqualTo("root3"); assertThat(cn.getChildren()).hasSize(1); assertThat(cn.getChildren()) - .filteredOn(on -> on instanceof OptionNode) - .extracting(on -> { - return ((OptionNode)on).getName(); - }) + .filteredOn(OptionNode.class::isInstance) + .extracting(on -> ((OptionNode)on).getName()) .containsExactly("--arg1"); OptionNode on = (OptionNode) cn.getChildren().get(0); assertThat(on.getChildren()).hasSize(1); @@ -155,10 +149,8 @@ void createsOptionNodesWithTwoOptionArg() { assertThat(cn.getCommand()).isEqualTo("root3"); assertThat(cn.getChildren()).hasSize(2); assertThat(cn.getChildren()) - .filteredOn(on -> on instanceof OptionNode) - .extracting(on -> { - return ((OptionNode)on).getName(); - }) + .filteredOn(OptionNode.class::isInstance) + .extracting(on -> ((OptionNode)on).getName()) .containsExactly("--arg1", "--arg2"); OptionNode on1 = (OptionNode) cn.getChildren().get(0); assertThat(on1.getChildren()).hasSize(1); @@ -187,10 +179,8 @@ void createsOptionNodeWithShortOptionArg() { assertThat(cn.getCommand()).isEqualTo("root3"); assertThat(cn.getChildren()).hasSize(1); assertThat(cn.getChildren()) - .filteredOn(on -> on instanceof OptionNode) - .extracting(on -> { - return ((OptionNode)on).getName(); - }) + .filteredOn(OptionNode.class::isInstance) + .extracting(on -> ((OptionNode)on).getName()) .containsExactly("-a"); OptionNode on = (OptionNode) cn.getChildren().get(0); assertThat(on.getChildren()).hasSize(1); @@ -217,10 +207,8 @@ void createsOptionNodesWithTwoShortOptionArg() { assertThat(cn.getCommand()).isEqualTo("root3"); assertThat(cn.getChildren()).hasSize(2); assertThat(cn.getChildren()) - .filteredOn(on -> on instanceof OptionNode) - .extracting(on -> { - return ((OptionNode)on).getName(); - }) + .filteredOn(OptionNode.class::isInstance) + .extracting(on -> ((OptionNode)on).getName()) .containsExactly("-a", "-b"); OptionNode on1 = (OptionNode) cn.getChildren().get(0); assertThat(on1.getChildren()).hasSize(1); @@ -249,10 +237,8 @@ void createOptionNodesWhenNoOptionArguments() { assertThat(cn.getCommand()).isEqualTo("root3"); assertThat(cn.getChildren()).hasSize(2); assertThat(cn.getChildren()) - .filteredOn(on -> on instanceof OptionNode) - .extracting(on -> { - return ((OptionNode)on).getName(); - }) + .filteredOn(OptionNode.class::isInstance) + .extracting(on -> ((OptionNode)on).getName()) .containsExactly("--arg1", "--arg2"); }); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/CommandModelTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/CommandModelTests.java index eb0180701..1ec697658 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/CommandModelTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/CommandModelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -15,7 +15,7 @@ */ package org.springframework.shell.command.parser; -import java.util.Arrays; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; @@ -110,12 +110,8 @@ void onePlainSubCommand2() { assertThat(root1.registration).isNull(); assertThat(root1.getValidTokens()).satisfies(map -> { assertThat(map).hasSize(2); - assertThat(map).hasEntrySatisfying("sub1", token -> { - assertThat(token.getType()).isEqualTo(TokenType.COMMAND); - }); - assertThat(map).hasEntrySatisfying("sub2", token -> { - assertThat(token.getType()).isEqualTo(TokenType.COMMAND); - }); + assertThat(map).hasEntrySatisfying("sub1", token -> assertThat(token.getType()).isEqualTo(TokenType.COMMAND)); + assertThat(map).hasEntrySatisfying("sub2", token -> assertThat(token.getType()).isEqualTo(TokenType.COMMAND)); }); assertThat(root1.getChildren()).satisfiesExactlyInAnyOrder( sub1 -> { @@ -155,27 +151,16 @@ void onePlainSubCommand3() { assertThat(root1.registration).isNull(); assertThat(root1.getValidTokens()).satisfies(map -> { assertThat(map).hasSize(1); - assertThat(map).hasEntrySatisfying("sub1", token -> { - assertThat(token.getType()).isEqualTo(TokenType.COMMAND); - }); + assertThat(map).hasEntrySatisfying("sub1", token -> assertThat(token.getType()).isEqualTo(TokenType.COMMAND)); }); assertThat(root1.getChildren()).satisfiesExactlyInAnyOrder( sub1 -> { assertThat(sub1.command).isEqualTo("sub1"); assertThat(sub1.getChildren()).satisfiesExactlyInAnyOrder( - sub2 -> { - assertThat(sub2.getChildren()).isEmpty(); - }, - sub3 -> { - assertThat(sub3.getChildren()).isEmpty(); - }, - sub4 -> { - assertThat(sub4.getChildren()).isEmpty(); - } + sub2 -> assertThat(sub2.getChildren()).isEmpty(), + sub3 -> assertThat(sub3.getChildren()).isEmpty(), + sub4 -> assertThat(sub4.getChildren()).isEmpty() ); - // assertThat(sub1).isNotNull(); - // assertThat(sub1.getChildren()).isEmpty(); - // assertThat(sub1.registration).isNotNull(); } ); }); @@ -186,7 +171,7 @@ void shouldResolveCommand() { register(ROOT2_SUB1); CommandModel model = commandModel(); - assertThat(model.resolve(Arrays.asList("root2", "sub1"))).isNotNull(); + assertThat(model.resolve(List.of("root2", "sub1"))).isNotNull(); } @Test @@ -195,10 +180,8 @@ void shouldResolveParentCommand() { register(ROOT2_SUB1_SUB2); CommandModel model = commandModel(); - assertThat(model.resolve(Arrays.asList("root2"))).satisfies( - info -> { - assertThat(info.registration).isNotNull(); - } + assertThat(model.resolve(List.of("root2"))).satisfies( + info -> assertThat(info.registration).isNotNull() ); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/LexerTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/LexerTests.java index 87f633d35..4361137d9 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/LexerTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/LexerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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. @@ -43,12 +43,10 @@ void rootCommandNoOptions() { List tokens = tokenize("root1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root1")); } } @@ -65,12 +63,10 @@ void commandRegUpperCommandLower() { List tokens = tokenize(lexer(config), "root1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root1")); } @Test @@ -82,33 +78,14 @@ void commandRegLowerCommandUpper() { List tokens = tokenize(lexer(config), "Root1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("Root1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("Root1")); } } - - // @Test - // void commandWithCaseInsensitiveInArguments() { - // register(ROOT1); - // ParserConfig configuration = new ParserConfig() - // .setOptionsCaseSensitive(false); - // List tokens = tokenize(lexer(configuration), "ROOT1"); - - // assertThat(tokens).satisfiesExactly( - // token -> { - // ParserAssertions.assertThat(token) - // .isType(TokenType.COMMAND) - // .hasPosition(0) - // .hasValue("ROOT1"); - // }); - // } - @Test void rootCommandWithChildGetsRootForRoot() { register(ROOT1); @@ -116,12 +93,10 @@ void rootCommandWithChildGetsRootForRoot() { List tokens = tokenize("root1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root1")); } @Test @@ -130,18 +105,14 @@ void subCommandLevel1WithoutRoot() { List tokens = tokenize("root2", "sub1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root2"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(1) - .hasValue("sub1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root2"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(1) + .hasValue("sub1")); } @Test @@ -150,24 +121,18 @@ void subCommandLevel2WithoutRoot() { List tokens = tokenize("root2", "sub1", "sub2"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root2"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(1) - .hasValue("sub1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(2) - .hasValue("sub2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root2"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(1) + .hasValue("sub1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(2) + .hasValue("sub2")); } @Test @@ -176,36 +141,26 @@ void subCommandLevel2WithoutRootWithOption() { List tokens = tokenize("root2", "sub1", "sub2", "--arg1", "xxx"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root2"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(1) - .hasValue("sub1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(2) - .hasValue("sub2"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(3) - .hasValue("--arg1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.ARGUMENT) - .hasPosition(4) - .hasValue("xxx"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root2"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(1) + .hasValue("sub1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(2) + .hasValue("sub2"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(3) + .hasValue("--arg1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.ARGUMENT) + .hasPosition(4) + .hasValue("xxx")); } @Test @@ -214,18 +169,14 @@ void definedOptionShouldBeOptionAfterCommand() { List tokens = tokenize("root3", "--arg1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root3"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("--arg1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root3"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("--arg1")); } @Test @@ -234,18 +185,14 @@ void notDefinedOptionShouldBeOptionAfterCommand() { List tokens = tokenize("root3", "--arg2"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root3"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("--arg2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root3"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("--arg2")); } @Test @@ -254,24 +201,18 @@ void notDefinedOptionShouldBeOptionAfterDefinedOption() { List tokens = tokenize("root3", "--arg1", "--arg2"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root3"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("--arg1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(2) - .hasValue("--arg2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root3"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("--arg1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(2) + .hasValue("--arg2")); } @Test @@ -280,30 +221,22 @@ void notDefinedOptionShouldBeOptionAfterDefinedOptionHavingArgument() { List tokens = tokenize("root3", "--arg1", "value1", "--arg2"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root3"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("--arg1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.ARGUMENT) - .hasPosition(2) - .hasValue("value1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(3) - .hasValue("--arg2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root3"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("--arg1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.ARGUMENT) + .hasPosition(2) + .hasValue("value1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(3) + .hasValue("--arg2")); } @Test @@ -312,24 +245,18 @@ void optionsWithoutValuesFromRoot() { List tokens = tokenize("root5", "--arg1", "--arg2"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root5"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("--arg1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(2) - .hasValue("--arg2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root5"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("--arg1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(2) + .hasValue("--arg2")); } @Test @@ -338,36 +265,26 @@ void optionsWithValuesFromRoot() { List tokens = tokenize("root5", "--arg1", "value1", "--arg2", "value2"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root5"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("--arg1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.ARGUMENT) - .hasPosition(2) - .hasValue("value1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(3) - .hasValue("--arg2"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.ARGUMENT) - .hasPosition(4) - .hasValue("value2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root5"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("--arg1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.ARGUMENT) + .hasPosition(2) + .hasValue("value1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(3) + .hasValue("--arg2"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.ARGUMENT) + .hasPosition(4) + .hasValue("value2")); } @Test @@ -376,24 +293,18 @@ void shortOptionWithValuesFromRoot() { List tokens = tokenize("root3", "-a", "value1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root3"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("-a"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.ARGUMENT) - .hasPosition(2) - .hasValue("value1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root3"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("-a"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.ARGUMENT) + .hasPosition(2) + .hasValue("value1")); } @Test @@ -402,36 +313,26 @@ void shortOptionsWithValuesFromRoot() { List tokens = tokenize("root3", "-a", "value1", "-b", "value2"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(0) - .hasValue("root3"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(1) - .hasValue("-a"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.ARGUMENT) - .hasPosition(2) - .hasValue("value1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.OPTION) - .hasPosition(3) - .hasValue("-b"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.ARGUMENT) - .hasPosition(4) - .hasValue("value2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(0) + .hasValue("root3"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(1) + .hasValue("-a"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.ARGUMENT) + .hasPosition(2) + .hasValue("value1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.OPTION) + .hasPosition(3) + .hasValue("-b"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.ARGUMENT) + .hasPosition(4) + .hasValue("value2")); } @Test @@ -511,18 +412,14 @@ void directiveWithCommand() { List tokens = tokenize(lexer(config), "[fake]", "root1"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.DIRECTIVE) - .hasPosition(0) - .hasValue("fake"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.COMMAND) - .hasPosition(1) - .hasValue("root1"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.DIRECTIVE) + .hasPosition(0) + .hasValue("fake"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.COMMAND) + .hasPosition(1) + .hasValue("root1")); } @Test @@ -532,12 +429,10 @@ void hasOneDirective() { List tokens = tokenize(lexer(config), "[fake]"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.DIRECTIVE) - .hasPosition(0) - .hasValue("fake"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.DIRECTIVE) + .hasPosition(0) + .hasValue("fake")); } @Test @@ -547,18 +442,14 @@ void hasMultipleDirectives() { List tokens = tokenize(lexer(config), "[fake1][fake2]"); assertThat(tokens).satisfiesExactly( - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.DIRECTIVE) - .hasPosition(0) - .hasValue("fake1"); - }, - token -> { - ParserAssertions.assertThat(token) - .isType(TokenType.DIRECTIVE) - .hasPosition(0) - .hasValue("fake2"); - }); + token -> ParserAssertions.assertThat(token) + .isType(TokenType.DIRECTIVE) + .hasPosition(0) + .hasValue("fake1"), + token -> ParserAssertions.assertThat(token) + .isType(TokenType.DIRECTIVE) + .hasPosition(0) + .hasValue("fake2")); } @Test @@ -596,11 +487,11 @@ void hasErrorMessageWithoutArguments() { assertThat(result.messageResults()).satisfiesExactly( message -> { assertThat(message.parserMessage().getCode()).isEqualTo(1000); - assertThat(message.position()).isEqualTo(0); + assertThat(message.position()).isZero(); }, message -> { assertThat(message.parserMessage().getCode()).isEqualTo(1000); - assertThat(message.position()).isEqualTo(0); + assertThat(message.position()).isZero(); }); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/MessageResultAssert.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/MessageResultAssert.java index 63d854253..b3284bb50 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/MessageResultAssert.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/MessageResultAssert.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserAssertions.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserAssertions.java index 7a65f6b59..8066c4313 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserAssertions.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserAssertions.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserConfigTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserConfigTests.java index 1ea9c896d..bb7952900 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserConfigTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserMessageAssert.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserMessageAssert.java index 4a0cc5c77..b5e8d0dd9 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserMessageAssert.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserMessageAssert.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserTests.java index 5ec3a1759..73dadacc5 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/ParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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. @@ -54,7 +54,7 @@ void commandArgumentsGetsAddedWhenNoOptions() { assertThat(result.argumentResults()).satisfiesExactly( ar -> { assertThat(ar.value()).isEqualTo("arg1"); - assertThat(ar.position()).isEqualTo(0); + assertThat(ar.position()).isZero(); }, ar -> { assertThat(ar.value()).isEqualTo("arg2"); @@ -71,7 +71,7 @@ void commandArgumentsGetsAddedAfterDoubleDash() { assertThat(result.argumentResults()).satisfiesExactly( ar -> { assertThat(ar.value()).isEqualTo("arg1"); - assertThat(ar.position()).isEqualTo(0); + assertThat(ar.position()).isZero(); }, ar -> { assertThat(ar.value()).isEqualTo("arg2"); @@ -142,9 +142,7 @@ void shouldHaveErrorResult() { register(ROOT4); ParseResult result = parse("root4"); assertThat(result).isNotNull(); - assertThat(result.messageResults()).satisfiesExactly(message -> { - ParserAssertions.assertThat(message.parserMessage()).hasCode(2000).hasType(ParserMessage.Type.ERROR); - }); + assertThat(result.messageResults()).satisfiesExactly(message -> ParserAssertions.assertThat(message.parserMessage()).hasCode(2000).hasType(ParserMessage.Type.ERROR)); // "100E:(pos 0): Missing option, longnames='arg1', shortnames=''" assertThat(result.messageResults().get(0).getMessage()).contains("Missing mandatory option", "arg1"); } @@ -156,12 +154,8 @@ void shouldHaveErrorResult2() { assertThat(result).isNotNull(); assertThat(result.messageResults()).satisfiesExactlyInAnyOrder( - message -> { - ParserAssertions.assertThat(message.parserMessage()).hasCode(2000).hasType(ParserMessage.Type.ERROR); - }, - message -> { - ParserAssertions.assertThat(message.parserMessage()).hasCode(2001).hasType(ParserMessage.Type.ERROR); - } + message -> ParserAssertions.assertThat(message.parserMessage()).hasCode(2000).hasType(ParserMessage.Type.ERROR), + message -> ParserAssertions.assertThat(message.parserMessage()).hasCode(2001).hasType(ParserMessage.Type.ERROR) ); } @@ -183,9 +177,7 @@ void shouldHaveErrorForUnrecognisedOption(RegAndArgs regAndArgs) { register(regAndArgs.reg()); ParseResult result = parse(regAndArgs.args()); assertThat(result.messageResults()).satisfiesExactlyInAnyOrder( - message -> { - ParserAssertions.assertThat(message.parserMessage()).hasCode(2001).hasType(ParserMessage.Type.ERROR); - } + message -> ParserAssertions.assertThat(message.parserMessage()).hasCode(2001).hasType(ParserMessage.Type.ERROR) ); } @@ -286,9 +278,7 @@ void shouldFindLongOptionArgument() { assertThat(result.commandRegistration()).isNotNull(); assertThat(result.optionResults()).isNotEmpty(); assertThat(result.optionResults()).satisfiesExactly( - r -> { - assertThat(r.value()).isEqualTo("value1"); - } + r -> assertThat(r.value()).isEqualTo("value1") ); assertThat(result.messageResults()).isEmpty(); } @@ -432,9 +422,7 @@ void shouldFindLongOptionRegLowerCommandUpper() { assertThat(result.commandRegistration()).isNotNull(); assertThat(result.optionResults()).isNotEmpty(); assertThat(result.optionResults()).satisfiesExactly( - r -> { - assertThat(r.value()).isEqualTo("value1"); - } + r -> assertThat(r.value()).isEqualTo("value1") ); assertThat(result.messageResults()).isEmpty(); } @@ -449,9 +437,7 @@ void shouldAddOptionIfItHasDefaultValue() { register(ROOT6_OPTION_DEFAULT_VALUE); ParseResult result = parse("root6"); assertThat(result.optionResults()).satisfiesExactly( - r -> { - assertThat(r.value()).isEqualTo("defaultvalue"); - } + r -> assertThat(r.value()).isEqualTo("defaultvalue") ); } } @@ -466,7 +452,7 @@ void shouldGetPositionalArgWhenOneAsString() { assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("a"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); } ); } @@ -478,7 +464,7 @@ void shouldGetPositionalArgWhenTwoAsString() { assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("a"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); }, r -> { assertThat(r.value()).isEqualTo("b"); @@ -509,7 +495,7 @@ void positionOverridesDefault() { assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("a"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); } ); assertThat(result.optionResults()).isNotNull().satisfiesExactly( @@ -546,7 +532,7 @@ void positionOverridesDefaultKeepsDefault() { assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("a"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); } ); assertThat(result.optionResults()).isNotNull().satisfiesExactly( @@ -569,7 +555,7 @@ void positionOverridesDefaultsKeepsDefault() { assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("a"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); }, r -> { assertThat(r.value()).isEqualTo("b"); @@ -596,7 +582,7 @@ void positionOverridesDefaultsKeepsDefaultWhenOption() { assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("b"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); } ); assertThat(result.optionResults()).isNotNull().satisfiesExactly( @@ -621,7 +607,7 @@ void positionWithLastHavingNoDefault() { assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("c"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); } ); assertThat(result.optionResults()).isNotNull().satisfiesExactly( @@ -647,18 +633,16 @@ void tooManyArgsInMiddleShouldCreateError() { result = parse("root7", "--arg1", "a", "b", "--arg2", "c", "d"); assertThat(result.messageResults()).satisfiesExactlyInAnyOrder( - message -> { - ParserAssertions.assertThat(message.parserMessage()).hasCode(2004).hasType(ParserMessage.Type.ERROR); - } + message -> ParserAssertions.assertThat(message.parserMessage()).hasCode(2004).hasType(ParserMessage.Type.ERROR) ); assertThat(result.argumentResults()).satisfiesExactly( r -> { assertThat(r.value()).isEqualTo("b"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); }, r -> { assertThat(r.value()).isEqualTo("d"); - assertThat(r.position()).isEqualTo(0); + assertThat(r.position()).isZero(); } ); assertThat(result.optionResults()).isNotNull().satisfiesExactly( diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/TokenAssert.java b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/TokenAssert.java index 5c5e3ea58..533872341 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/parser/TokenAssert.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/parser/TokenAssert.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present§ 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/command/support/OptionNameModifierSupportTests.java b/spring-shell-core/src/test/java/org/springframework/shell/command/support/OptionNameModifierSupportTests.java index ca8360b48..a60577f0c 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/command/support/OptionNameModifierSupportTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/command/support/OptionNameModifierSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/completion/RegistrationOptionsCompletionResolverTests.java b/spring-shell-core/src/test/java/org/springframework/shell/completion/RegistrationOptionsCompletionResolverTests.java index e30bae613..37d69e966 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/completion/RegistrationOptionsCompletionResolverTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/completion/RegistrationOptionsCompletionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -15,7 +15,6 @@ */ package org.springframework.shell.completion; -import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; @@ -26,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class RegistrationOptionsCompletionResolverTests { +class RegistrationOptionsCompletionResolverTests { private final RegistrationOptionsCompletionResolver resolver = new RegistrationOptionsCompletionResolver(); @@ -44,10 +43,9 @@ void completesAllOptions() { .longNames("arg2") .and() .build(); - CompletionContext ctx = new CompletionContext(Arrays.asList("hello", "world", ""), 2, "".length(), registration, null); + CompletionContext ctx = new CompletionContext(List.of("hello", "world", ""), 2, "".length(), registration, null); List proposals = resolver.apply(ctx); - assertThat(proposals).isNotNull(); - assertThat(proposals).hasSize(2); + assertThat(proposals).isNotNull().hasSize(2); } @Test @@ -64,10 +62,9 @@ void completesNonExistingOptions() { .longNames("arg2") .and() .build(); - CompletionContext ctx = new CompletionContext(Arrays.asList("hello", "world", "--arg1", ""), 2, "".length(), registration, null); + CompletionContext ctx = new CompletionContext(List.of("hello", "world", "--arg1", ""), 2, "".length(), registration, null); List proposals = resolver.apply(ctx); - assertThat(proposals).isNotNull(); - assertThat(proposals).hasSize(1); + assertThat(proposals).isNotNull().hasSize(1); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/AbstractShellTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/AbstractShellTests.java index b13095cdb..27ce4de58 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/AbstractShellTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/AbstractShellTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,14 +44,14 @@ public abstract class AbstractShellTests { - private ExecutorService executorService; - private PipedInputStream pipedInputStream; - private PipedOutputStream pipedOutputStream; - private LinkedBlockingQueue bytesQueue; + private ExecutorService executorService; + private PipedInputStream pipedInputStream; + private PipedOutputStream pipedOutputStream; + private LinkedBlockingQueue bytesQueue; private ByteArrayOutputStream consoleOut; private Terminal terminal; private TemplateExecutor templateExecutor; - private ResourceLoader resourceLoader; + private ResourceLoader resourceLoader; @BeforeEach public void setup() throws Exception { @@ -76,22 +76,22 @@ public ThemeSettings getSettings() { ThemeResolver themeResolver = new ThemeResolver(themeRegistry, "dump"); templateExecutor = new TemplateExecutor(themeResolver); - resourceLoader = new DefaultResourceLoader(); + resourceLoader = new DefaultResourceLoader(); - pipedInputStream.connect(pipedOutputStream); + pipedInputStream.connect(pipedOutputStream); terminal = new DumbTerminal("terminal", "ansi", pipedInputStream, consoleOut, StandardCharsets.UTF_8); - terminal.setSize(new Size(80, 24)); - - executorService.execute(() -> { - try { - while (true) { - byte[] take = bytesQueue.take(); - pipedOutputStream.write(take); - pipedOutputStream.flush(); - } - } catch (Exception e) { - } - }); + terminal.setSize(new Size(80, 24)); + + executorService.execute(() -> { + try { + while (true) { + byte[] take = bytesQueue.take(); + pipedOutputStream.write(take); + pipedOutputStream.flush(); + } + } catch (Exception e) { + } + }); } @AfterEach @@ -104,95 +104,95 @@ protected void write(byte[] bytes) { } protected String consoleOut() { - return AttributedString.fromAnsi(consoleOut.toString()).toString(); + return AttributedString.fromAnsi(consoleOut.toString()).toString(); } protected Terminal getTerminal() { return terminal; } - protected ResourceLoader getResourceLoader() { - return resourceLoader; - } + protected ResourceLoader getResourceLoader() { + return resourceLoader; + } - protected TemplateExecutor getTemplateExecutor() { - return templateExecutor; - } + protected TemplateExecutor getTemplateExecutor() { + return templateExecutor; + } - protected class TestBuffer { - private final ByteArrayOutputStream out = new ByteArrayOutputStream(); + protected class TestBuffer { + private final ByteArrayOutputStream out = new ByteArrayOutputStream(); - public TestBuffer() { - } + public TestBuffer() { + } - public TestBuffer(String str) { - append(str); - } + public TestBuffer(String str) { + append(str); + } - public TestBuffer(char[] chars) { - append(new String(chars)); - } + public TestBuffer(char[] chars) { + append(new String(chars)); + } - @Override - public String toString() { - try { - return out.toString(StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } + @Override + public String toString() { + try { + return out.toString(StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } - public TestBuffer cr() { + public TestBuffer cr() { return append("\r"); - } + } - public TestBuffer backspace() { - return append(del()); - } + public TestBuffer backspace() { + return append(del()); + } - public TestBuffer backspace(int count) { - TestBuffer buf = this; - for (int i = 0; i < count; i++) { - buf = backspace(); - } - return buf; - } + public TestBuffer backspace(int count) { + TestBuffer buf = this; + for (int i = 0; i < count; i++) { + buf = backspace(); + } + return buf; + } public TestBuffer down() { return append("\033[B"); - } + } public TestBuffer ctrl(char let) { - return append(KeyMap.ctrl(let)); - } + return append(KeyMap.ctrl(let)); + } - public TestBuffer ctrlE() { - return ctrl('E'); - } + public TestBuffer ctrlE() { + return ctrl('E'); + } - public TestBuffer ctrlY() { - return ctrl('Y'); - } + public TestBuffer ctrlY() { + return ctrl('Y'); + } public TestBuffer space() { return append(" "); - } - - public byte[] getBytes() { - return out.toByteArray(); - } - - public TestBuffer append(final String str) { - for (byte b : str.getBytes(StandardCharsets.UTF_8)) { - append(b); - } - return this; - } - - public TestBuffer append(final int i) { - // consoleOut.reset(); - out.write((byte) i); - return this; - } + } + + public byte[] getBytes() { + return out.toByteArray(); + } + + public TestBuffer append(final String str) { + for (byte b : str.getBytes(StandardCharsets.UTF_8)) { + append(b); + } + return this; + } + + public TestBuffer append(final int i) { + // consoleOut.reset(); + out.write((byte) i); + return this; + } } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/ConfirmationInputTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/ConfirmationInputTests.java index a1afc60d4..983231aad 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/ConfirmationInputTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/ConfirmationInputTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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. @@ -17,13 +17,10 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jline.terminal.impl.DumbTerminal; @@ -38,22 +35,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -public class ConfirmationInputTests extends AbstractShellTests { +class ConfirmationInputTests extends AbstractShellTests { private ExecutorService service; - private CountDownLatch latch1; private AtomicReference result1; @BeforeEach - public void setupTests() { + void setupTests() { service = Executors.newFixedThreadPool(1); - latch1 = new CountDownLatch(1); result1 = new AtomicReference<>(); } @AfterEach - public void cleanupTests() throws IOException { - latch1 = null; + void cleanupTests() { result1 = null; if (service != null) { service.shutdown(); @@ -75,21 +69,21 @@ void testNoTty() throws Exception { service.execute(() -> { ConfirmationInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - ConfirmationInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + ConfirmationInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNull(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNull(); + }); } @Test - public void testResultUserInputEnterDefaultYes() throws InterruptedException, IOException { + void testResultUserInputEnterDefaultYes() { ComponentContext empty = ComponentContext.empty(); ConfirmationInput component1 = new ConfirmationInput(getTerminal(), "component1"); component1.setResourceLoader(new DefaultResourceLoader()); @@ -98,22 +92,22 @@ public void testResultUserInputEnterDefaultYes() throws InterruptedException, IO service.execute(() -> { ConfirmationInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - ConfirmationInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + ConfirmationInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNotNull(); - assertThat(run1Context.getResultValue()).isTrue(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNotNull(); + assertThat(run1Context.getResultValue()).isTrue(); + }); } @Test - public void testResultUserInputEnterDefaultNo() throws InterruptedException, IOException { + void testResultUserInputEnterDefaultNo() { ComponentContext empty = ComponentContext.empty(); ConfirmationInput component1 = new ConfirmationInput(getTerminal(), "component1", false); component1.setResourceLoader(new DefaultResourceLoader()); @@ -122,22 +116,22 @@ public void testResultUserInputEnterDefaultNo() throws InterruptedException, IOE service.execute(() -> { ConfirmationInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - ConfirmationInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + ConfirmationInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNotNull(); - assertThat(run1Context.getResultValue()).isFalse(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNotNull(); + assertThat(run1Context.getResultValue()).isFalse(); + }); } @Test - public void testResultUserInputNo() throws InterruptedException, IOException { + void testResultUserInputNo() { ComponentContext empty = ComponentContext.empty(); ConfirmationInput component1 = new ConfirmationInput(getTerminal(), "component1"); component1.setResourceLoader(new DefaultResourceLoader()); @@ -146,22 +140,22 @@ public void testResultUserInputNo() throws InterruptedException, IOException { service.execute(() -> { ConfirmationInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("no").cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - ConfirmationInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + ConfirmationInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNotNull(); - assertThat(run1Context.getResultValue()).isFalse(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNotNull(); + assertThat(run1Context.getResultValue()).isFalse(); + }); } @Test - public void testUserInputShown() throws InterruptedException, IOException { + void testUserInputShown() { ComponentContext empty = ComponentContext.empty(); ConfirmationInput component1 = new ConfirmationInput(getTerminal(), "component1"); component1.setResourceLoader(new DefaultResourceLoader()); @@ -170,7 +164,6 @@ public void testUserInputShown() throws InterruptedException, IOException { service.execute(() -> { ConfirmationInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("N"); @@ -182,16 +175,17 @@ public void testUserInputShown() throws InterruptedException, IOException { testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - ConfirmationInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + ConfirmationInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNotNull(); - assertThat(run1Context.getResultValue()).isFalse(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNotNull(); + assertThat(run1Context.getResultValue()).isFalse(); + }); } @Test - public void testResultUserInputYes() throws InterruptedException, IOException { + void testResultUserInputYes() { ComponentContext empty = ComponentContext.empty(); ConfirmationInput component1 = new ConfirmationInput(getTerminal(), "component1"); component1.setResourceLoader(new DefaultResourceLoader()); @@ -200,22 +194,22 @@ public void testResultUserInputYes() throws InterruptedException, IOException { service.execute(() -> { ConfirmationInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("yes").cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - ConfirmationInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + ConfirmationInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNotNull(); - assertThat(run1Context.getResultValue()).isTrue(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNotNull(); + assertThat(run1Context.getResultValue()).isTrue(); + }); } @Test - public void testResultUserInputInvalidInput() throws InterruptedException, IOException { + void testResultUserInputInvalidInput() { ComponentContext empty = ComponentContext.empty(); ConfirmationInput component1 = new ConfirmationInput(getTerminal(), "component1"); component1.setResourceLoader(new DefaultResourceLoader()); @@ -224,19 +218,17 @@ public void testResultUserInputInvalidInput() throws InterruptedException, IOExc service.execute(() -> { ConfirmationInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("x").cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - - assertThat(consoleOut()).contains("input is invalid"); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + assertThat(consoleOut()).contains("input is invalid"); + ConfirmationInputContext run1Context = result1.get(); - ConfirmationInputContext run1Context = result1.get(); - - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNull(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNull(); + }); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/MultiItemSelectorTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/MultiItemSelectorTests.java index a6b004202..150a5f04d 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/MultiItemSelectorTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/MultiItemSelectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -42,38 +42,38 @@ import static org.awaitility.Awaitility.await; import static org.springframework.shell.component.ShellAssertions.assertStringOrderThat; -public class MultiItemSelectorTests extends AbstractShellTests { - - private static SimplePojo SIMPLE_POJO_1 = SimplePojo.of("data1"); - private static SimplePojo SIMPLE_POJO_2 = SimplePojo.of("data2"); - private static SimplePojo SIMPLE_POJO_3 = SimplePojo.of("data3"); - private static SimplePojo SIMPLE_POJO_4 = SimplePojo.of("data4"); - private static SimplePojo SIMPLE_POJO_5 = SimplePojo.of("data5"); - private static SimplePojo SIMPLE_POJO_6 = SimplePojo.of("data6"); - private static SimplePojo SIMPLE_POJO_7 = SimplePojo.of("data7"); - private static SimplePojo SIMPLE_POJO_8 = SimplePojo.of("data8"); - private static SelectorItem SELECTOR_ITEM_1 = SelectorItem.of("simplePojo1", SIMPLE_POJO_1); - private static SelectorItem SELECTOR_ITEM_2 = SelectorItem.of("simplePojo2", SIMPLE_POJO_2); - private static SelectorItem SELECTOR_ITEM_3 = SelectorItem.of("simplePojo3", SIMPLE_POJO_3); - private static SelectorItem SELECTOR_ITEM_4 = SelectorItem.of("simplePojo4", SIMPLE_POJO_4); - private static SelectorItem SELECTOR_ITEM_5 = SelectorItem.of("simplePojo5", SIMPLE_POJO_5); - private static SelectorItem SELECTOR_ITEM_6 = SelectorItem.of("simplePojo6", SIMPLE_POJO_6); - private static SelectorItem SELECTOR_ITEM_7 = SelectorItem.of("simplePojo7", SIMPLE_POJO_7, false, false); - private static SelectorItem SELECTOR_ITEM_8 = SelectorItem.of("simplePojo8", SIMPLE_POJO_8, false, true); +class MultiItemSelectorTests extends AbstractShellTests { + + private static final SimplePojo SIMPLE_POJO_1 = SimplePojo.of("data1"); + private static final SimplePojo SIMPLE_POJO_2 = SimplePojo.of("data2"); + private static final SimplePojo SIMPLE_POJO_3 = SimplePojo.of("data3"); + private static final SimplePojo SIMPLE_POJO_4 = SimplePojo.of("data4"); + private static final SimplePojo SIMPLE_POJO_5 = SimplePojo.of("data5"); + private static final SimplePojo SIMPLE_POJO_6 = SimplePojo.of("data6"); + private static final SimplePojo SIMPLE_POJO_7 = SimplePojo.of("data7"); + private static final SimplePojo SIMPLE_POJO_8 = SimplePojo.of("data8"); + private static final SelectorItem SELECTOR_ITEM_1 = SelectorItem.of("simplePojo1", SIMPLE_POJO_1); + private static final SelectorItem SELECTOR_ITEM_2 = SelectorItem.of("simplePojo2", SIMPLE_POJO_2); + private static final SelectorItem SELECTOR_ITEM_3 = SelectorItem.of("simplePojo3", SIMPLE_POJO_3); + private static final SelectorItem SELECTOR_ITEM_4 = SelectorItem.of("simplePojo4", SIMPLE_POJO_4); + private static final SelectorItem SELECTOR_ITEM_5 = SelectorItem.of("simplePojo5", SIMPLE_POJO_5); + private static final SelectorItem SELECTOR_ITEM_6 = SelectorItem.of("simplePojo6", SIMPLE_POJO_6); + private static final SelectorItem SELECTOR_ITEM_7 = SelectorItem.of("simplePojo7", SIMPLE_POJO_7, false, false); + private static final SelectorItem SELECTOR_ITEM_8 = SelectorItem.of("simplePojo8", SIMPLE_POJO_8, false, true); private ExecutorService service; private CountDownLatch latch; private AtomicReference>> result; @BeforeEach - public void setupMulti() { + void setupMulti() { service = Executors.newFixedThreadPool(1); latch = new CountDownLatch(1); result = new AtomicReference<>(); } @AfterEach - public void cleanupMulti() { + void cleanupMulti() { latch = null; result = null; if (service != null) { @@ -96,7 +96,7 @@ void testNoTty() throws Exception { } @Test - public void testItemsShown() { + void testItemsShown() { scheduleSelect(); await().atMost(Duration.ofSeconds(4)) .untilAsserted(() -> assertStringOrderThat(consoleOut()).containsInOrder("simplePojo1", "simplePojo2", @@ -104,7 +104,7 @@ public void testItemsShown() { } @Test - public void testMaxItems() { + void testMaxItems() { scheduleSelect(Arrays.asList(SELECTOR_ITEM_1, SELECTOR_ITEM_2, SELECTOR_ITEM_3, SELECTOR_ITEM_4, SELECTOR_ITEM_5, SELECTOR_ITEM_6), 6); await().atMost(Duration.ofSeconds(4)) @@ -113,14 +113,14 @@ public void testMaxItems() { } @Test - public void testItemsShownWithDisabled() { + void testItemsShownWithDisabled() { scheduleSelect(Arrays.asList(SELECTOR_ITEM_1, SELECTOR_ITEM_7)); await().atMost(Duration.ofSeconds(4)) .untilAsserted(() -> assertStringOrderThat(consoleOut()).containsInOrder("[ ] simplePojo1", "[ ] simplePojo7")); } @Test - public void testDisableIsNotSelectable() throws InterruptedException { + void testDisableIsNotSelectable() throws InterruptedException { scheduleSelect(Arrays.asList(SELECTOR_ITEM_1, SELECTOR_ITEM_7)); TestBuffer testBuffer = new TestBuffer().space().ctrlE().space().cr(); write(testBuffer.getBytes()); @@ -134,7 +134,7 @@ public void testDisableIsNotSelectable() throws InterruptedException { } @Test - public void testNoneSelected() throws InterruptedException { + void testNoneSelected() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().cr(); @@ -143,11 +143,11 @@ public void testNoneSelected() throws InterruptedException { awaitLatch(); List> selected = result.get(); - assertThat(selected).hasSize(0); + assertThat(selected).isEmpty(); } @Test - public void testSelectFirst() throws InterruptedException { + void testSelectFirst() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().space().cr(); @@ -163,7 +163,7 @@ public void testSelectFirst() throws InterruptedException { } @Test - public void testSelectSecond() throws InterruptedException { + void testSelectSecond() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().ctrlE().space().cr(); @@ -178,7 +178,7 @@ public void testSelectSecond() throws InterruptedException { } @Test - public void testSelectSecondAndFourth() throws InterruptedException { + void testSelectSecondAndFourth() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().ctrlE().space().ctrlE().ctrlE().space().cr(); @@ -193,7 +193,7 @@ public void testSelectSecondAndFourth() throws InterruptedException { } @Test - public void testSelectLastBackwards() throws InterruptedException { + void testSelectLastBackwards() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().ctrlY().space().cr(); @@ -208,7 +208,7 @@ public void testSelectLastBackwards() throws InterruptedException { } @Test - public void testDefaultSelection() throws InterruptedException { + void testDefaultSelection() throws InterruptedException { scheduleSelect(Arrays.asList(SELECTOR_ITEM_1, SELECTOR_ITEM_2, SELECTOR_ITEM_7, SELECTOR_ITEM_8)); TestBuffer testBuffer = new TestBuffer().cr(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/PathInputTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/PathInputTests.java index d9875706b..eef51ad50 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/PathInputTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/PathInputTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,10 +22,9 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; -import java.util.concurrent.CountDownLatch; +import java.time.Duration; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; @@ -40,27 +39,25 @@ import org.springframework.shell.component.context.ComponentContext; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; -public class PathInputTests extends AbstractShellTests { +class PathInputTests extends AbstractShellTests { private ExecutorService service; - private CountDownLatch latch1; private AtomicReference result1; private FileSystem fileSystem; private Function pathProvider; @BeforeEach - public void setupTests() { + void setupTests() { service = Executors.newFixedThreadPool(1); - latch1 = new CountDownLatch(1); result1 = new AtomicReference<>(); fileSystem = Jimfs.newFileSystem(); - pathProvider = (path) -> fileSystem.getPath(path); + pathProvider = path -> fileSystem.getPath(path); } @AfterEach - public void cleanupTests() throws IOException { - latch1 = null; + void cleanupTests() throws IOException { result1 = null; if (service != null) { service.shutdown(); @@ -90,21 +87,21 @@ void testNoTty() throws Exception { service.execute(() -> { PathInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("tmp").cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - PathInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + PathInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNull(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNull(); + }); } @Test - public void testResultUserInput() throws InterruptedException, IOException { + void testResultUserInput() throws IOException { Path path = fileSystem.getPath("tmp"); Files.createDirectories(path); ComponentContext empty = ComponentContext.empty(); @@ -116,17 +113,17 @@ public void testResultUserInput() throws InterruptedException, IOException { service.execute(() -> { PathInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("tmp").cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - PathInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + PathInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNotNull(); - assertThat(run1Context.getResultValue().toString()).contains("tmp"); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNotNull(); + assertThat(run1Context.getResultValue().toString()).contains("tmp"); + }); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/PathSearchTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/PathSearchTests.java index f9f30ffe5..dfab22aa5 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/PathSearchTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/PathSearchTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -15,7 +15,6 @@ */ package org.springframework.shell.component; -import java.util.Arrays; import java.util.List; import java.util.stream.Stream; @@ -29,56 +28,56 @@ import static org.assertj.core.api.Assertions.assertThat; -public class PathSearchTests { +class PathSearchTests { static Stream testParts() { return Stream.of( Arguments.of("0", new int[] { 0 }, - Arrays.asList(PartText.of("0", true))), + List.of(PartText.of("0", true))), Arguments.of("01", new int[] { 0, 1 }, - Arrays.asList( + List.of( PartText.of("0", true), PartText.of("1", true))), Arguments.of("012", new int[] { 0, 1, 2 }, - Arrays.asList( + List.of( PartText.of("0", true), PartText.of("1", true), PartText.of("2", true))), Arguments.of("0123456789", new int[0], - Arrays.asList(PartText.of("0123456789", false))), + List.of(PartText.of("0123456789", false))), Arguments.of("0123456789", new int[] { 0 }, - Arrays.asList( + List.of( PartText.of("0", true), PartText.of("123456789", false))), Arguments.of("0123456789", new int[] { 1 }, - Arrays.asList( + List.of( PartText.of("0", false), PartText.of("1", true), PartText.of("23456789", false))), Arguments.of("0123456789", new int[] { 9 }, - Arrays.asList( + List.of( PartText.of("012345678", false), PartText.of("9", true))), Arguments.of("0123456789", new int[] { 2, 5 }, - Arrays.asList( + List.of( PartText.of("01", false), PartText.of("2", true), PartText.of("34", false), PartText.of("5", true), PartText.of("6789", false))), Arguments.of("0123456789", new int[] { 2, 3 }, - Arrays.asList( + List.of( PartText.of("01", false), PartText.of("2", true), PartText.of("3", true), PartText.of("456789", false))), Arguments.of("0123456789", new int[] { 8, 9 }, - Arrays.asList( + List.of( PartText.of("01234567", false), PartText.of("8", true), PartText.of("9", true))), Arguments.of("spring-shell-core/build/test-results/test/TEST-org.springframework.shell.support.search.FuzzyMatchV2SearchMatchAlgorithmTests.xml", new int[] { 13, 33, 59, 67, 73 }, - Arrays.asList( + List.of( PartText.of("spring-shell-", false), PartText.of("c", true), PartText.of("ore/build/test-resu", false), diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/ShellAssertions.java b/spring-shell-core/src/test/java/org/springframework/shell/component/ShellAssertions.java index b6f8c9b50..56fd2a3f8 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/ShellAssertions.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/ShellAssertions.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/SingleItemSelectorTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/SingleItemSelectorTests.java index d87de7983..ceaa1db12 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/SingleItemSelectorTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/SingleItemSelectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -42,34 +42,34 @@ import static org.awaitility.Awaitility.await; import static org.springframework.shell.component.ShellAssertions.assertStringOrderThat; -public class SingleItemSelectorTests extends AbstractShellTests { - - private static SimplePojo SIMPLE_POJO_1 = SimplePojo.of("data1"); - private static SimplePojo SIMPLE_POJO_2 = SimplePojo.of("data2"); - private static SimplePojo SIMPLE_POJO_3 = SimplePojo.of("data3"); - private static SimplePojo SIMPLE_POJO_4 = SimplePojo.of("data4"); - private static SimplePojo SIMPLE_POJO_5 = SimplePojo.of("data5"); - private static SimplePojo SIMPLE_POJO_6 = SimplePojo.of("data6"); - private static SelectorItem SELECTOR_ITEM_1 = SelectorItem.of("simplePojo1", SIMPLE_POJO_1); - private static SelectorItem SELECTOR_ITEM_2 = SelectorItem.of("simplePojo2", SIMPLE_POJO_2); - private static SelectorItem SELECTOR_ITEM_3 = SelectorItem.of("simplePojo3", SIMPLE_POJO_3); - private static SelectorItem SELECTOR_ITEM_4 = SelectorItem.of("simplePojo4", SIMPLE_POJO_4); - private static SelectorItem SELECTOR_ITEM_5 = SelectorItem.of("simplePojo5", SIMPLE_POJO_5); - private static SelectorItem SELECTOR_ITEM_6 = SelectorItem.of("simplePojo6", SIMPLE_POJO_6); +class SingleItemSelectorTests extends AbstractShellTests { + + private static final SimplePojo SIMPLE_POJO_1 = SimplePojo.of("data1"); + private static final SimplePojo SIMPLE_POJO_2 = SimplePojo.of("data2"); + private static final SimplePojo SIMPLE_POJO_3 = SimplePojo.of("data3"); + private static final SimplePojo SIMPLE_POJO_4 = SimplePojo.of("data4"); + private static final SimplePojo SIMPLE_POJO_5 = SimplePojo.of("data5"); + private static final SimplePojo SIMPLE_POJO_6 = SimplePojo.of("data6"); + private static final SelectorItem SELECTOR_ITEM_1 = SelectorItem.of("simplePojo1", SIMPLE_POJO_1); + private static final SelectorItem SELECTOR_ITEM_2 = SelectorItem.of("simplePojo2", SIMPLE_POJO_2); + private static final SelectorItem SELECTOR_ITEM_3 = SelectorItem.of("simplePojo3", SIMPLE_POJO_3); + private static final SelectorItem SELECTOR_ITEM_4 = SelectorItem.of("simplePojo4", SIMPLE_POJO_4); + private static final SelectorItem SELECTOR_ITEM_5 = SelectorItem.of("simplePojo5", SIMPLE_POJO_5); + private static final SelectorItem SELECTOR_ITEM_6 = SelectorItem.of("simplePojo6", SIMPLE_POJO_6); private ExecutorService service; private CountDownLatch latch; private AtomicReference>> result; @BeforeEach - public void setupMulti() { + void setupMulti() { service = Executors.newFixedThreadPool(1); latch = new CountDownLatch(1); result = new AtomicReference<>(); } @AfterEach - public void cleanupMulti() { + void cleanupMulti() { latch = null; result = null; if (service != null) { @@ -79,17 +79,15 @@ public void cleanupMulti() { } @Test - public void testItemsShownFirstHovered() { + void testItemsShownFirstHovered() { scheduleSelect(); await().atMost(Duration.ofSeconds(4)) - .untilAsserted(() -> { - assertStringOrderThat(consoleOut()).containsInOrder("> simplePojo1", "simplePojo2", "simplePojo3", "simplePojo4"); - }); + .untilAsserted(() -> assertStringOrderThat(consoleOut()).containsInOrder("> simplePojo1", "simplePojo2", "simplePojo3", "simplePojo4")); } @Test - public void testMaxItems() { + void testMaxItems() { scheduleSelect(Arrays.asList(SELECTOR_ITEM_1, SELECTOR_ITEM_2, SELECTOR_ITEM_3, SELECTOR_ITEM_4, SELECTOR_ITEM_5, SELECTOR_ITEM_6), 6); await().atMost(Duration.ofSeconds(4)) @@ -111,7 +109,7 @@ void testNoTty() throws Exception { } @Test - public void testSelectFirst() throws InterruptedException { + void testSelectFirst() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().cr(); @@ -127,7 +125,7 @@ public void testSelectFirst() throws InterruptedException { } @Test - public void testSelectSecond() throws InterruptedException { + void testSelectSecond() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().ctrlE().cr(); @@ -142,7 +140,7 @@ public void testSelectSecond() throws InterruptedException { } @Test - public void testSelectLastBackwards() throws InterruptedException { + void testSelectLastBackwards() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().ctrlY().cr(); @@ -157,7 +155,7 @@ public void testSelectLastBackwards() throws InterruptedException { } @Test - public void testFilterShowsNoneThenSelect() throws InterruptedException { + void testFilterShowsNoneThenSelect() throws InterruptedException { scheduleSelect(); TestBuffer testBuffer = new TestBuffer().append("xxx").cr(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/StringInputTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/StringInputTests.java index a0cf26e02..407224a79 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/StringInputTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/StringInputTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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. @@ -18,10 +18,10 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jline.terminal.impl.DumbTerminal; @@ -34,28 +34,23 @@ import org.springframework.shell.component.context.ComponentContext; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; -public class StringInputTests extends AbstractShellTests { +class StringInputTests extends AbstractShellTests { private ExecutorService service; - private CountDownLatch latch1; - private CountDownLatch latch2; private AtomicReference result1; private AtomicReference result2; @BeforeEach - public void setupTests() { + void setupTests() { service = Executors.newFixedThreadPool(1); - latch1 = new CountDownLatch(1); - latch2 = new CountDownLatch(1); result1 = new AtomicReference<>(); result2 = new AtomicReference<>(); } @AfterEach - public void cleanupTests() { - latch1 = null; - latch2 = null; + void cleanupTests() { result1 = null; result2 = null; if (service != null) { @@ -79,21 +74,21 @@ void testNoTty() throws Exception { service.execute(() -> { StringInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - StringInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + StringInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isNull(); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isNull(); + }); } @Test - public void testResultBasic() throws InterruptedException { + void testResultBasic() { ComponentContext empty = ComponentContext.empty(); StringInput component1 = new StringInput(getTerminal(), "component1", "component1ResultValue"); component1.setPrintResults(true); @@ -103,22 +98,22 @@ public void testResultBasic() throws InterruptedException { service.execute(() -> { StringInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - StringInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + StringInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isEqualTo("component1ResultValue"); - assertThat(consoleOut()).contains("component1 component1ResultValue"); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isEqualTo("component1ResultValue"); + assertThat(consoleOut()).contains("component1 component1ResultValue"); + }); } @Test - public void testResultBasicWithMask() throws InterruptedException { + void testResultBasicWithMask() { ComponentContext empty = ComponentContext.empty(); StringInput component1 = new StringInput(getTerminal(), "component1", "component1ResultValue"); component1.setPrintResults(true); @@ -129,22 +124,22 @@ public void testResultBasicWithMask() throws InterruptedException { service.execute(() -> { StringInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - StringInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + StringInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isEqualTo("component1ResultValue"); - assertThat(consoleOut()).contains("component1 *********************"); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isEqualTo("component1ResultValue"); + assertThat(consoleOut()).contains("component1 *********************"); + }); } @Test - public void testResultUserInput() throws InterruptedException { + void testResultUserInput() { ComponentContext empty = ComponentContext.empty(); StringInput component1 = new StringInput(getTerminal(), "component1", "component1ResultValue"); component1.setResourceLoader(new DefaultResourceLoader()); @@ -153,21 +148,21 @@ public void testResultUserInput() throws InterruptedException { service.execute(() -> { StringInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("test").cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - StringInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + StringInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isEqualTo("test"); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isEqualTo("test"); + }); } @Test - public void testResultUserInputUnicode() throws InterruptedException { + void testResultUserInputUnicode() { ComponentContext empty = ComponentContext.empty(); StringInput component1 = new StringInput(getTerminal(), "component1", "component1ResultValue"); component1.setResourceLoader(new DefaultResourceLoader()); @@ -176,21 +171,21 @@ public void testResultUserInputUnicode() throws InterruptedException { service.execute(() -> { StringInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().append("😂").cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - StringInputContext run1Context = result1.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + StringInputContext run1Context = result1.get(); - assertThat(run1Context).isNotNull(); - assertThat(run1Context.getResultValue()).isEqualTo("😂"); + assertThat(run1Context).isNotNull(); + assertThat(run1Context.getResultValue()).isEqualTo("😂"); + }); } @Test - public void testPassingViaContext() throws InterruptedException { + void testPassingViaContext() { ComponentContext empty = ComponentContext.empty(); StringInput component1 = new StringInput(getTerminal(), "component1", "component1ResultValue"); StringInput component2 = new StringInput(getTerminal(), "component2", "component2ResultValue"); @@ -199,9 +194,7 @@ public void testPassingViaContext() throws InterruptedException { component2.setResourceLoader(new DefaultResourceLoader()); component2.setTemplateExecutor(getTemplateExecutor()); - component1.addPostRunHandler(context -> { - context.put("component1ResultValue", context.getResultValue()); - }); + component1.addPostRunHandler(context -> context.put("component1ResultValue", context.getResultValue())); component2.addPreRunHandler(context -> { String component1ResultValue = context.get("component1ResultValue"); @@ -213,33 +206,29 @@ public void testPassingViaContext() throws InterruptedException { service.execute(() -> { StringInputContext run1Context = component1.run(empty); result1.set(run1Context); - latch1.countDown(); }); TestBuffer testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch1.await(2, TimeUnit.SECONDS); - service.execute(() -> { StringInputContext run1Context = result1.get(); StringInputContext run2Context = component2.run(run1Context); result2.set(run2Context); - latch2.countDown(); }); write(testBuffer.getBytes()); - latch2.await(2, TimeUnit.SECONDS); - - StringInputContext run1Context = result1.get(); - StringInputContext run2Context = result2.get(); + await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> { + StringInputContext run1Context = result1.get(); + StringInputContext run2Context = result2.get(); - assertThat(run1Context).isNotSameAs(run2Context); + assertThat(run1Context).isNotSameAs(run2Context); - assertThat(run1Context).isNotNull(); - assertThat(run2Context).isNotNull(); - assertThat(run1Context.getResultValue()).isEqualTo("component1ResultValue"); - assertThat(run2Context.getResultValue()).isEqualTo("component1ResultValue"); + assertThat(run1Context).isNotNull(); + assertThat(run2Context).isNotNull(); + assertThat(run1Context.getResultValue()).isEqualTo("component1ResultValue"); + assertThat(run2Context.getResultValue()).isEqualTo("component1ResultValue"); + }); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/context/ComponentContextTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/context/ComponentContextTests.java index 95d13596e..5806d3003 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/context/ComponentContextTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/context/ComponentContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,11 +22,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -public class ComponentContextTests { +class ComponentContextTests { @Test @SuppressWarnings("unused") - public void testBasics() { + void testBasics() { ComponentContext context = ComponentContext.empty(); assertThat(context.stream()).isEmpty(); @@ -41,8 +41,6 @@ public void testBasics() { }).isInstanceOf(ClassCastException.class); assertThat(context.get("foo", String.class)).isEqualTo("bar"); - assertThatThrownBy(() -> { - context.get("foo", Integer.class); - }).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> context.get("foo", Integer.class)).isInstanceOf(IllegalArgumentException.class); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/flow/AbstractShellTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/flow/AbstractShellTests.java index d8d657bae..ea94d7209 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/flow/AbstractShellTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/flow/AbstractShellTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,14 +44,14 @@ public abstract class AbstractShellTests { - private ExecutorService executorService; - private PipedInputStream pipedInputStream; - private PipedOutputStream pipedOutputStream; - private LinkedBlockingQueue bytesQueue; + private ExecutorService executorService; + private PipedInputStream pipedInputStream; + private PipedOutputStream pipedOutputStream; + private LinkedBlockingQueue bytesQueue; private ByteArrayOutputStream consoleOut; private Terminal terminal; private TemplateExecutor templateExecutor; - private ResourceLoader resourceLoader; + private ResourceLoader resourceLoader; @BeforeEach public void setup() throws Exception { @@ -76,22 +76,22 @@ public ThemeSettings getSettings() { ThemeResolver themeResolver = new ThemeResolver(themeRegistry, "default"); templateExecutor = new TemplateExecutor(themeResolver); - resourceLoader = new DefaultResourceLoader(); + resourceLoader = new DefaultResourceLoader(); - pipedInputStream.connect(pipedOutputStream); + pipedInputStream.connect(pipedOutputStream); terminal = new DumbTerminal("terminal", "ansi", pipedInputStream, consoleOut, StandardCharsets.UTF_8); - terminal.setSize(new Size(1, 1)); - - executorService.execute(() -> { - try { - while (true) { - byte[] take = bytesQueue.take(); - pipedOutputStream.write(take); - pipedOutputStream.flush(); - } - } catch (Exception e) { - } - }); + terminal.setSize(new Size(1, 1)); + + executorService.execute(() -> { + try { + while (true) { + byte[] take = bytesQueue.take(); + pipedOutputStream.write(take); + pipedOutputStream.flush(); + } + } catch (Exception e) { + } + }); } @AfterEach @@ -104,95 +104,95 @@ protected void write(byte[] bytes) { } protected String consoleOut() { - return AttributedString.fromAnsi(consoleOut.toString()).toString(); + return AttributedString.fromAnsi(consoleOut.toString()).toString(); } protected Terminal getTerminal() { return terminal; } - protected ResourceLoader getResourceLoader() { - return resourceLoader; - } + protected ResourceLoader getResourceLoader() { + return resourceLoader; + } - protected TemplateExecutor getTemplateExecutor() { - return templateExecutor; - } + protected TemplateExecutor getTemplateExecutor() { + return templateExecutor; + } - protected class TestBuffer { - private final ByteArrayOutputStream out = new ByteArrayOutputStream(); + protected class TestBuffer { + private final ByteArrayOutputStream out = new ByteArrayOutputStream(); - public TestBuffer() { - } + public TestBuffer() { + } - public TestBuffer(String str) { - append(str); - } + public TestBuffer(String str) { + append(str); + } - public TestBuffer(char[] chars) { - append(new String(chars)); - } + public TestBuffer(char[] chars) { + append(new String(chars)); + } - @Override - public String toString() { - try { - return out.toString(StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } + @Override + public String toString() { + try { + return out.toString(StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } - public TestBuffer cr() { + public TestBuffer cr() { return append("\r"); - } + } - public TestBuffer backspace() { - return append(del()); - } + public TestBuffer backspace() { + return append(del()); + } - public TestBuffer backspace(int count) { - TestBuffer buf = this; - for (int i = 0; i < count; i++) { - buf = backspace(); - } - return buf; - } + public TestBuffer backspace(int count) { + TestBuffer buf = this; + for (int i = 0; i < count; i++) { + buf = backspace(); + } + return buf; + } public TestBuffer down() { return append("\033[B"); - } + } public TestBuffer ctrl(char let) { - return append(KeyMap.ctrl(let)); - } + return append(KeyMap.ctrl(let)); + } - public TestBuffer ctrlE() { - return ctrl('E'); - } + public TestBuffer ctrlE() { + return ctrl('E'); + } - public TestBuffer ctrlY() { - return ctrl('Y'); - } + public TestBuffer ctrlY() { + return ctrl('Y'); + } public TestBuffer space() { return append(" "); - } - - public byte[] getBytes() { - return out.toByteArray(); - } - - public TestBuffer append(final String str) { - for (byte b : str.getBytes(StandardCharsets.UTF_8)) { - append(b); - } - return this; - } - - public TestBuffer append(final int i) { - // consoleOut.reset(); - out.write((byte) i); - return this; - } + } + + public byte[] getBytes() { + return out.toByteArray(); + } + + public TestBuffer append(final String str) { + for (byte b : str.getBytes(StandardCharsets.UTF_8)) { + append(b); + } + return this; + } + + public TestBuffer append(final int i) { + // consoleOut.reset(); + out.write((byte) i); + return this; + } } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/flow/ComponentFlowTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/flow/ComponentFlowTests.java index 3510a38cf..f045df75d 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/flow/ComponentFlowTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/flow/ComponentFlowTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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,13 @@ package org.springframework.shell.component.flow; import java.nio.file.Path; -import java.util.Arrays; +import java.time.Duration; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.Test; @@ -33,15 +32,16 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; -public class ComponentFlowTests extends AbstractShellTests { +class ComponentFlowTests extends AbstractShellTests { @Test - public void testSimpleFlow() throws InterruptedException { + void testSimpleFlow() { Map single1SelectItems = new HashMap<>(); single1SelectItems.put("key1", "value1"); single1SelectItems.put("key2", "value2"); - List multi1SelectItems = Arrays.asList(SelectItem.of("key1", "value1"), + List multi1SelectItems = List.of(SelectItem.of("key1", "value1"), SelectItem.of("key2", "value2"), SelectItem.of("key3", "value3")); ComponentFlow wizard = ComponentFlow.builder() .terminal(getTerminal()) @@ -68,13 +68,9 @@ public void testSimpleFlow() throws InterruptedException { .build(); ExecutorService service = Executors.newFixedThreadPool(1); - CountDownLatch latch = new CountDownLatch(1); AtomicReference result = new AtomicReference<>(); - service.execute(() -> { - result.set(wizard.run()); - latch.countDown(); - }); + service.execute(() -> result.set(wizard.run())); // field1 TestBuffer testBuffer = new TestBuffer().cr(); @@ -92,24 +88,26 @@ public void testSimpleFlow() throws InterruptedException { testBuffer = new TestBuffer().ctrlE().space().cr(); write(testBuffer.getBytes()); - latch.await(4, TimeUnit.SECONDS); - ComponentFlowResult inputWizardResult = result.get(); - assertThat(inputWizardResult).isNotNull(); - String field1 = inputWizardResult.getContext().get("field1"); - String field2 = inputWizardResult.getContext().get("field2"); - Path path1 = inputWizardResult.getContext().get("path1"); - String single1 = inputWizardResult.getContext().get("single1"); - List multi1 = inputWizardResult.getContext().get("multi1"); - assertThat(field1).isEqualTo("defaultField1Value"); - assertThat(field2).isEqualTo("Field2Value"); - assertThat(path1.toString()).contains("fakedir"); - assertThat(single1).isEqualTo("value1"); - assertThat(multi1).containsExactlyInAnyOrder("value2"); - assertThat(consoleOut()).contains("Field1 defaultField1Value"); + await().atMost(Duration.ofSeconds(4)).untilAsserted(() -> { + ComponentFlowResult inputWizardResult = result.get(); + assertThat(inputWizardResult).isNotNull(); + String field1 = inputWizardResult.getContext().get("field1"); + String field2 = inputWizardResult.getContext().get("field2"); + Path path1 = inputWizardResult.getContext().get("path1"); + String single1 = inputWizardResult.getContext().get("single1"); + List multi1 = inputWizardResult.getContext().get("multi1"); + assertThat(field1).isEqualTo("defaultField1Value"); + assertThat(field2).isEqualTo("Field2Value"); + assertThat(path1.toString()).contains("fakedir"); + assertThat(single1).isEqualTo("value1"); + assertThat(multi1).containsExactlyInAnyOrder("value2"); + assertThat(consoleOut()).contains("Field1 defaultField1Value"); + }); + } @Test - public void testSkipsGivenComponents() throws InterruptedException { + void testSkipsGivenComponents() { ComponentFlow wizard = ComponentFlow.builder() .terminal(getTerminal()) .withStringInput("id1") @@ -127,7 +125,7 @@ public void testSkipsGivenComponents() throws InterruptedException { .resultMode(ResultMode.ACCEPT) .and() .withMultiItemSelector("id4") - .resultValues(Arrays.asList("value4")) + .resultValues(List.of("value4")) .resultMode(ResultMode.ACCEPT) .and() .withConfirmationInput("id5") @@ -137,15 +135,11 @@ public void testSkipsGivenComponents() throws InterruptedException { .build(); ExecutorService service = Executors.newFixedThreadPool(1); - CountDownLatch latch = new CountDownLatch(1); AtomicReference result = new AtomicReference<>(); - service.execute(() -> { - result.set(wizard.run()); - latch.countDown(); - }); + service.execute(() -> result.set(wizard.run())); - latch.await(4, TimeUnit.SECONDS); + await().atMost(Duration.ofSeconds(4)).untilAsserted(() -> { ComponentFlowResult inputWizardResult = result.get(); assertThat(inputWizardResult).isNotNull(); @@ -160,10 +154,11 @@ public void testSkipsGivenComponents() throws InterruptedException { assertThat(id3).isEqualTo("value3"); assertThat(id4).containsExactlyInAnyOrder("value4"); assertThat(id5).isFalse(); - } + }); + } @Test - public void testChoosesDynamicallyShouldJumpOverAndStop() throws InterruptedException { + void testChoosesDynamicallyShouldJumpOverAndStop() { ComponentFlow wizard = ComponentFlow.builder() .terminal(getTerminal()) .resourceLoader(getResourceLoader()) @@ -187,12 +182,8 @@ public void testChoosesDynamicallyShouldJumpOverAndStop() throws InterruptedExce .build(); ExecutorService service = Executors.newFixedThreadPool(1); - CountDownLatch latch = new CountDownLatch(1); AtomicReference result = new AtomicReference<>(); - service.execute(() -> { - result.set(wizard.run()); - latch.countDown(); - }); + service.execute(() -> result.set(wizard.run())); // id1 TestBuffer testBuffer = new TestBuffer().append("id3").cr(); @@ -200,18 +191,20 @@ public void testChoosesDynamicallyShouldJumpOverAndStop() throws InterruptedExce // id3 testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch.await(4, TimeUnit.SECONDS); - ComponentFlowResult inputWizardResult = result.get(); - assertThat(inputWizardResult).isNotNull(); - String id1 = inputWizardResult.getContext().get("id1"); - String id3 = inputWizardResult.getContext().get("id3"); - assertThat(id1).isEqualTo("id3"); - assertThat(id3).isEqualTo("value3"); - assertThat(inputWizardResult.getContext().containsKey("id2")).isFalse(); + + await().atMost(Duration.ofSeconds(4)).untilAsserted(() -> { + ComponentFlowResult inputWizardResult = result.get(); + assertThat(inputWizardResult).isNotNull(); + String id1 = inputWizardResult.getContext().get("id1"); + String id3 = inputWizardResult.getContext().get("id3"); + assertThat(id1).isEqualTo("id3"); + assertThat(id3).isEqualTo("value3"); + assertThat(inputWizardResult.getContext().containsKey("id2")).isFalse(); + }); } @Test - public void testChoosesDynamicallyShouldNotContinueToNext() throws InterruptedException { + void testChoosesDynamicallyShouldNotContinueToNext() { ComponentFlow wizard = ComponentFlow.builder() .terminal(getTerminal()) .resourceLoader(getResourceLoader()) @@ -248,18 +241,20 @@ public void testChoosesDynamicallyShouldNotContinueToNext() throws InterruptedEx // id2 testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch.await(4, TimeUnit.SECONDS); - ComponentFlowResult inputWizardResult = result.get(); - assertThat(inputWizardResult).isNotNull(); - String id1 = inputWizardResult.getContext().get("id1"); - String id2 = inputWizardResult.getContext().get("id2"); - assertThat(id1).isEqualTo("id2"); - assertThat(id2).isEqualTo("value2"); - assertThat(inputWizardResult.getContext().containsKey("id3")).isFalse(); + + await().atMost(Duration.ofSeconds(4)).untilAsserted(() -> { + ComponentFlowResult inputWizardResult = result.get(); + assertThat(inputWizardResult).isNotNull(); + String id1 = inputWizardResult.getContext().get("id1"); + String id2 = inputWizardResult.getContext().get("id2"); + assertThat(id1).isEqualTo("id2"); + assertThat(id2).isEqualTo("value2"); + assertThat(inputWizardResult.getContext().containsKey("id3")).isFalse(); + }); } @Test - public void testChoosesNonExistingComponent() throws InterruptedException { + void testChoosesNonExistingComponent() { ComponentFlow wizard = ComponentFlow.builder() .terminal(getTerminal()) .resourceLoader(getResourceLoader()) @@ -283,12 +278,8 @@ public void testChoosesNonExistingComponent() throws InterruptedException { .build(); ExecutorService service = Executors.newFixedThreadPool(1); - CountDownLatch latch = new CountDownLatch(1); AtomicReference result = new AtomicReference<>(); - service.execute(() -> { - result.set(wizard.run()); - latch.countDown(); - }); + service.execute(() -> result.set(wizard.run())); // id1 TestBuffer testBuffer = new TestBuffer().append("fake").cr(); @@ -297,17 +288,19 @@ public void testChoosesNonExistingComponent() throws InterruptedException { // don't execute id2 or id3 testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch.await(4, TimeUnit.SECONDS); - ComponentFlowResult inputWizardResult = result.get(); - assertThat(inputWizardResult).isNotNull(); - String id1 = inputWizardResult.getContext().get("id1"); - assertThat(id1).isEqualTo("fake"); - assertThat(inputWizardResult.getContext().containsKey("id2")).isFalse(); - assertThat(inputWizardResult.getContext().containsKey("id3")).isFalse(); + + await().atMost(Duration.ofSeconds(4)).untilAsserted(() -> { + ComponentFlowResult inputWizardResult = result.get(); + assertThat(inputWizardResult).isNotNull(); + String id1 = inputWizardResult.getContext().get("id1"); + assertThat(id1).isEqualTo("fake"); + assertThat(inputWizardResult.getContext().containsKey("id2")).isFalse(); + assertThat(inputWizardResult.getContext().containsKey("id3")).isFalse(); + }); } @Test - public void testAutoShowsDefault() throws InterruptedException { + void testAutoShowsDefault() { Map single1SelectItems = new HashMap<>(); single1SelectItems.put("key1", "value1"); single1SelectItems.put("key2", "value2"); @@ -323,29 +316,26 @@ public void testAutoShowsDefault() throws InterruptedException { .build(); ExecutorService service = Executors.newFixedThreadPool(1); - CountDownLatch latch = new CountDownLatch(1); AtomicReference result = new AtomicReference<>(); - service.execute(() -> { - result.set(wizard.run()); - latch.countDown(); - }); + service.execute(() -> result.set(wizard.run())); TestBuffer testBuffer = new TestBuffer(); testBuffer = new TestBuffer().cr(); write(testBuffer.getBytes()); - latch.await(4, TimeUnit.SECONDS); - ComponentFlowResult inputWizardResult = result.get(); - assertThat(inputWizardResult).isNotNull(); - String single1 = inputWizardResult.getContext().get("single1"); - assertThat(single1).isEqualTo("value2"); + await().atMost(Duration.ofSeconds(4)).untilAsserted(() -> { + ComponentFlowResult inputWizardResult = result.get(); + assertThat(inputWizardResult).isNotNull(); + String single1 = inputWizardResult.getContext().get("single1"); + assertThat(single1).isEqualTo("value2"); + }); } @Test @SuppressWarnings("unchecked") - public void testBuilderSingleTypes() { - List selectItems1 = Arrays.asList(SelectItem.of("key1", "value1"), SelectItem.of("key2", "value2")); + void testBuilderSingleTypes() { + List selectItems1 = List.of(SelectItem.of("key1", "value1"), SelectItem.of("key2", "value2")); Map selectItems2 = new HashMap<>(); selectItems2.put("key2", "value2"); selectItems2.put("key3", "value3"); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/support/SelectorListTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/support/SelectorListTests.java index d4a4b8e3d..0ef195298 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/support/SelectorListTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/support/SelectorListTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -255,10 +255,8 @@ public String getName() { List items(int count) { return IntStream.range(0, count) - .mapToObj(i -> { - return new TestItem("name" + i); - }) - .collect(Collectors.toList()); + .mapToObj(i -> new TestItem("name" + i)) + .toList(); } @SuppressWarnings("rawtypes") @@ -285,8 +283,8 @@ public SelectorListAssert(SelectorList actual) { public SelectorListAssert namesContainsExactly(String... names) { isNotNull(); List actualNames = actual.getProjection().stream() - .map(i -> i.getName()) - .collect(Collectors.toList()); + .map(Nameable::getName) + .toList(); assertThat(actualNames).containsExactly(names); return this; } @@ -294,8 +292,8 @@ public SelectorListAssert namesContainsExactly(String... names) { public SelectorListAssert selectedContainsExactly(Boolean... selected) { isNotNull(); List actualSelected = actual.getProjection().stream() - .map(i -> i.isSelected()) - .collect(Collectors.toList()); + .map(Selectable::isSelected) + .toList(); assertThat(actualSelected).containsExactly(selected); return this; } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssert.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssert.java index 131e2a760..151524485 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssert.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssert.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -95,7 +95,7 @@ public ScreenAssert hasForegroundColor(int x, int y, int color) { * * @param x a x position in a screen * @param y a y position in a screen - * @param color the style + * @param style the style * @return this assertion object */ public ScreenAssert hasStyle(int x, int y, int style) { @@ -252,7 +252,7 @@ private ScreenAssert hasBorderType(int x, int y, int width, int height, boolean } else { if (b != null) { - assertThat(b.getBorder()).isEqualTo(0); + assertThat(b.getBorder()).isZero(); } } }); @@ -263,7 +263,7 @@ private ScreenAssert hasBorderType(int x, int y, int width, int height, boolean } else { if (b != null) { - assertThat(b.getBorder()).isEqualTo(0); + assertThat(b.getBorder()).isZero(); } } }); @@ -274,20 +274,18 @@ private ScreenAssert hasBorderType(int x, int y, int width, int height, boolean } else { if (b != null) { - assertThat(b.getBorder()).isEqualTo(0); + assertThat(b.getBorder()).isZero(); } } }); assertThat(leftBorder).withFailMessage(failMessage).allSatisfy(b -> { if (border) { assertThat(b).isNotNull(); - // assertThat(b.getType()).isEqualTo(Screen.Type.BORDER); assertThat(b.getBorder()).isGreaterThan(0); } else { if (b != null) { - // assertThat(b.getType()).isNotEqualTo(Screen.Type.BORDER); - assertThat(b.getBorder()).isEqualTo(0); + assertThat(b.getBorder()).isZero(); } } }); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssertTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssertTests.java index 4f9300df7..e7e03d451 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssertTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/ScreenAssertTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -149,13 +149,6 @@ void hasNoHorizontalText() { assertThat(forScreen(screen)).hasNoHorizontalText("test", 0, 0, 4); } - // @Test - // void xxx() { - // Screen screen = new Screen(5, 5); - // screen.printBorder(0, 0, 5, 5); - // assertThat(forScreen(screen)).hasBorder(0, 0, 5, 4); - // } - private AssertProvider forScreen(Screen screen) { return () -> new ScreenAssert(screen); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AbstractViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AbstractViewTests.java index 4f1e042d0..7062e6ab8 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AbstractViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AbstractViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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. @@ -75,14 +75,10 @@ protected void configure(View view) { v.setEventLoop(eventLoop); } eventLoop.onDestroy(eventLoop.mouseEvents() - .doOnNext(m -> { - view.getMouseHandler().handle(MouseHandler.argsOf(m)); - }) + .doOnNext(m -> view.getMouseHandler().handle(MouseHandler.argsOf(m))) .subscribe()); eventLoop.onDestroy(eventLoop.keyEvents() - .doOnNext(m -> { - view.getKeyHandler().handle(KeyHandler.argsOf(m)); - }) + .doOnNext(m -> view.getKeyHandler().handle(KeyHandler.argsOf(m))) .subscribe()); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AppViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AppViewTests.java index 150d16554..a030af2ff 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AppViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/AppViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BaseViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BaseViewTests.java index 2c28a0673..10799b086 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BaseViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BaseViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BoxViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BoxViewTests.java index 199f35d7c..44bbddcc3 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BoxViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/BoxViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -78,8 +78,6 @@ void mouseClickInBounds() { MouseHandlerResult result = view.getMouseHandler().handle(MouseHandler.argsOf(event)); assertThat(result).isNotNull().satisfies(r -> { assertThat(r.event()).isEqualTo(event); - // assertThat(r.consumed()).isTrue(); - // assertThat(r.focus()).isEqualTo(view); assertThat(r.capture()).isEqualTo(view); }); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ButtonViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ButtonViewTests.java index 7e804a315..1e507227e 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ButtonViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ButtonViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -95,9 +95,7 @@ void handlesMouseClick() { MouseHandlerResult result = handleMouseClick(view, click); - assertThat(result).isNotNull().satisfies(r -> { - assertThat(r.consumed()).isTrue(); - }); + assertThat(result).isNotNull().satisfies(r -> assertThat(r.consumed()).isTrue()); verifier.verify(Duration.ofSeconds(1)); } @@ -112,9 +110,7 @@ void handlesKeyEnter() { KeyHandlerResult result = handleKey(view, KeyEvent.Key.Enter); - assertThat(result).isNotNull().satisfies(r -> { - assertThat(r.consumed()).isTrue(); - }); + assertThat(result).isNotNull().satisfies(r -> assertThat(r.consumed()).isTrue()); verifier.verify(Duration.ofSeconds(1)); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/DialogViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/DialogViewTests.java index c21b57abf..2205c87d6 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/DialogViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/DialogViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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,7 +16,7 @@ package org.springframework.shell.component.view.control; import java.time.Duration; -import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -43,7 +43,7 @@ void constructView() { view = new DialogView(); ButtonView button = new ButtonView("text"); - view = new DialogView(new BoxView(), Arrays.asList(button)); + view = new DialogView(new BoxView(), List.of(button)); } } @@ -79,9 +79,7 @@ void handlesMouseClick() { MouseHandlerResult result = handleMouseClick(view, click); - assertThat(result).isNotNull().satisfies(r -> { - assertThat(r.consumed()).isTrue(); - }); + assertThat(result).isNotNull().satisfies(r -> assertThat(r.consumed()).isTrue()); verifier1.verify(Duration.ofSeconds(1)); verifier2.verify(Duration.ofSeconds(1)); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java index 455be78bb..15ed8475e 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/GridViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/InputViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/InputViewTests.java index e771e9cc0..8adacacc0 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/InputViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/InputViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -126,19 +126,19 @@ int cursorIndex() { @Test void initialCursorPosition() { - assertThat(cursorIndex()).isEqualTo(0); + assertThat(cursorIndex()).isZero(); } @Test void shouldNotMoveOutOfBoundsIfMovingRight() { handleKey(view, Key.CursorRight); - assertThat(cursorIndex()).isEqualTo(0); + assertThat(cursorIndex()).isZero(); } @Test void shouldNotMoveOutOfBoundsIfMovingLeft() { handleKey(view, Key.CursorLeft); - assertThat(cursorIndex()).isEqualTo(0); + assertThat(cursorIndex()).isZero(); } @Test @@ -169,13 +169,13 @@ void addEmojiAndBackspace() { handleKey(view, "😂"); assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isEqualTo(1); handleKey(view, Key.Backspace); - assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isEqualTo(0); + assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isZero(); } @Test void deleteFromLastPosition() { handleKey(view, Key.Delete); - assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isEqualTo(0); + assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isZero(); handleKey(view, Key.a); assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isEqualTo(1); } @@ -193,14 +193,14 @@ void setup() { @Test void shouldAddToCursorPosition() { - assertThat(callIntMethod(view, CURSOR_POSITION_METHOD)).isEqualTo(0); + assertThat(callIntMethod(view, CURSOR_POSITION_METHOD)).isZero(); handleKey(view, Key.a); assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isEqualTo(1); assertThat(view.getInputText()).isEqualTo("a"); assertThat(callIntMethod(view, CURSOR_POSITION_METHOD)).isEqualTo(1); handleKey(view, Key.CursorLeft); - assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isEqualTo(0); + assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isZero(); handleKey(view, Key.b); assertThat(getIntField(view, CURSOR_INDEX_FIELD)).isEqualTo(1); @@ -230,9 +230,7 @@ void handlesKeyEnter() { KeyHandlerResult result = handleKey(view, KeyEvent.Key.Enter); - assertThat(result).isNotNull().satisfies(r -> { - assertThat(r.consumed()).isTrue(); - }); + assertThat(result).isNotNull().satisfies(r -> assertThat(r.consumed()).isTrue()); verifier.verify(Duration.ofSeconds(1)); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ListViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ListViewTests.java index bcd6ab043..19c99918a 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ListViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ListViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,7 +16,7 @@ package org.springframework.shell.component.view.control; import java.time.Duration; -import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -49,8 +49,9 @@ class ListViewTests extends AbstractViewTests { - private final static ParameterizedTypeReference> LISTVIEW_STRING_TYPEREF - = new ParameterizedTypeReference>() {}; + private static final ParameterizedTypeReference> LISTVIEW_STRING_TYPEREF + = new ParameterizedTypeReference<>() { + }; private static final String SELECTED_FIELD = "selected"; private static final String START_FIELD = "start"; @@ -61,7 +62,7 @@ class ListViewTests extends AbstractViewTests { ThemeResolver themeResolver; @BeforeEach - public void setupListView() { + void setupListView() { ThemeRegistry themeRegistry = new ThemeRegistry(); themeRegistry.register(new Theme() { @Override @@ -98,7 +99,7 @@ void arrowKeysMoveActive() { view = new ListView<>(); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); Flux> actions = eventLoop .viewEvents(LISTVIEW_STRING_TYPEREF); @@ -113,7 +114,7 @@ void arrowKeysMoveActive() { assertThat(r.event()).isEqualTo(eventDown); assertThat(r.consumed()).isTrue(); }); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); verifier.verify(Duration.ofSeconds(1)); } @@ -123,7 +124,7 @@ void mouseWheelMoveActive() { view = new ListView<>(); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); Flux> actions = eventLoop .viewEvents(LISTVIEW_STRING_TYPEREF); @@ -138,7 +139,7 @@ void mouseWheelMoveActive() { assertThat(r.event()).isEqualTo(eventDown); assertThat(r.capture()).isEqualTo(view); }); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); verifier.verify(Duration.ofSeconds(1)); } @@ -148,7 +149,7 @@ void mouseClickMoveActive() { view = new ListView<>(); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); Flux> actions = eventLoop .viewEvents(LISTVIEW_STRING_TYPEREF); @@ -159,7 +160,7 @@ void mouseClickMoveActive() { MouseEvent event01 = mouseClick(0, 1); view.getMouseHandler().handle(MouseHandler.argsOf(event01)); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); verifier.verify(Duration.ofSeconds(1)); } @@ -174,11 +175,11 @@ void initialActiveIndexZeroWhenItemsSet() { view = new ListView<>(); configure(view); view.setRect(0, 0, 80, 24); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); - view.setItems(Arrays.asList("item1", "item2")); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); + view.setItems(List.of("item1", "item2")); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); } @Test @@ -186,12 +187,12 @@ void arrowMovesActiveFromFirstToLast() { view = new ListView<>(); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); view.getKeyHandler().handle(KeyHandler.argsOf(KeyEvent.of(Key.CursorUp))); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); } @@ -200,17 +201,17 @@ void arrowMovesActiveFromLastToFirst() { view = new ListView<>(); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); view.getKeyHandler().handle(KeyHandler.argsOf(KeyEvent.of(Key.CursorDown))); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); view.getKeyHandler().handle(KeyHandler.argsOf(KeyEvent.of(Key.CursorDown))); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); } } @@ -232,7 +233,7 @@ void selectedHighlightNoTheme() { view = new ListView<>(); view.setShowBorder(true); view.setRect(0, 0, 10, 7); - view.setItems(Arrays.asList("item1", "item2", "item3")); + view.setItems(List.of("item1", "item2", "item3")); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasStyle(1, 1, 1); assertThat(forScreen(screen7x10)).hasForegroundColor(1, 1, -1); @@ -246,7 +247,7 @@ void selectedHighlightThemeSet() { view.setThemeName("default"); view.setShowBorder(true); view.setRect(0, 0, 10, 7); - view.setItems(Arrays.asList("item1", "item2", "item3")); + view.setItems(List.of("item1", "item2", "item3")); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasStyle(1, 1, 5); assertThat(forScreen(screen7x10)).hasForegroundColor(1, 1, Color.RED); @@ -258,7 +259,7 @@ void showingAllCells() { view = new ListView<>(); view.setShowBorder(true); view.setRect(0, 0, 10, 7); - view.setItems(Arrays.asList("item1", "item2", "item3")); + view.setItems(List.of("item1", "item2", "item3")); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item2", 1, 2, 5); @@ -270,7 +271,7 @@ void showingCellsWhichFitVertically() { view = new ListView<>(); view.setShowBorder(true); view.setRect(0, 0, 10, 7); - view.setItems(Arrays.asList("item1", "item2", "item3", "item4", "item5", "item6", "item7")); + view.setItems(List.of("item1", "item2", "item3", "item4", "item5", "item6", "item7")); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item2", 1, 2, 5); @@ -285,10 +286,10 @@ void scrollUpThrough() { view = new ListView<>(); view.setShowBorder(true); view.setRect(0, 0, 10, 7); - view.setItems(Arrays.asList("item1", "item2", "item3", "item4", "item5", "item6", "item7")); + view.setItems(List.of("item1", "item2", "item3", "item4", "item5", "item6", "item7")); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); + assertThat(getIntField(view, START_FIELD)).isZero(); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item2", 1, 2, 5); @@ -343,7 +344,7 @@ void scrollUpThrough() { callVoidIntMethod(view, SCROLL_METHOD, -1); assertThat(getIntField(view, START_FIELD)).isEqualTo(2); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item3", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item4", 1, 2, 5); @@ -354,7 +355,7 @@ void scrollUpThrough() { callVoidIntMethod(view, SCROLL_METHOD, -1); assertThat(getIntField(view, START_FIELD)).isEqualTo(1); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item2", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item3", 1, 2, 5); @@ -364,8 +365,8 @@ void scrollUpThrough() { clearScreens(); callVoidIntMethod(view, SCROLL_METHOD, -1); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item2", 1, 2, 5); @@ -381,9 +382,9 @@ void scrollDownThrough() { view.setShowBorder(true); view.setRect(0, 0, 10, 7); - view.setItems(Arrays.asList("item1", "item2", "item3", "item4", "item5", "item6", "item7")); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + view.setItems(List.of("item1", "item2", "item3", "item4", "item5", "item6", "item7")); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item2", 1, 2, 5); @@ -393,7 +394,7 @@ void scrollDownThrough() { clearScreens(); callVoidIntMethod(view, SCROLL_METHOD, 1); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); @@ -404,7 +405,7 @@ void scrollDownThrough() { clearScreens(); callVoidIntMethod(view, SCROLL_METHOD, 1); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(2); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); @@ -415,7 +416,7 @@ void scrollDownThrough() { clearScreens(); callVoidIntMethod(view, SCROLL_METHOD, 1); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(3); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); @@ -426,7 +427,7 @@ void scrollDownThrough() { clearScreens(); callVoidIntMethod(view, SCROLL_METHOD, 1); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(4); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); @@ -459,8 +460,8 @@ void scrollDownThrough() { clearScreens(); callVoidIntMethod(view, SCROLL_METHOD, 1); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); - assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); + assertThat(getIntField(view, POSITION_FIELD)).isZero(); view.draw(screen7x10); assertThat(forScreen(screen7x10)).hasHorizontalText("item1", 1, 1, 5); assertThat(forScreen(screen7x10)).hasHorizontalText("item2", 1, 2, 5); @@ -480,7 +481,7 @@ void showRadio() { view = new ListView<>(ItemStyle.RADIO); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); view.getKeyHandler().handle(KeyHandler.argsOf(KeyEvent.of(Key.Space))); assertThat(getIntSetField(view, SELECTED_FIELD)).containsExactly(0); view.getKeyHandler().handle(KeyHandler.argsOf(KeyEvent.of(Key.CursorDown))); @@ -498,7 +499,7 @@ void showChecked() { view = new ListView<>(ItemStyle.CHECKED); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); view.getKeyHandler().handle(KeyHandler.argsOf(KeyEvent.of(Key.Space))); assertThat(getIntSetField(view, SELECTED_FIELD)).containsExactly(0); view.getKeyHandler().handle(KeyHandler.argsOf(KeyEvent.of(Key.CursorDown))); @@ -517,7 +518,7 @@ void customCellFactory() { view.setShowBorder(true); view.setCellFactory((list, item) -> new TestListCell(item)); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1")); + view.setItems(List.of("item1")); view.draw(screen24x80); assertThat(forScreen(screen24x80)).hasHorizontalText("pre-item1-post", 0, 1, 16); } @@ -547,7 +548,7 @@ void setup() { view = new ListView<>(); configure(view); view.setRect(0, 0, 80, 24); - view.setItems(Arrays.asList("item1", "item2")); + view.setItems(List.of("item1", "item2")); } @Test @@ -563,7 +564,7 @@ void lineDown() { .verifyLater(); view.runViewCommand(ViewCommand.LINE_DOWN); verifier.verify(Duration.ofSeconds(1)); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); } @@ -575,7 +576,7 @@ void lineUp() { .verifyLater(); view.runViewCommand(ViewCommand.LINE_UP); verifier.verify(Duration.ofSeconds(1)); - assertThat(getIntField(view, START_FIELD)).isEqualTo(0); + assertThat(getIntField(view, START_FIELD)).isZero(); assertThat(getIntField(view, POSITION_FIELD)).isEqualTo(1); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuBarViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuBarViewTests.java index 1cb8f706c..d159e7467 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuBarViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuBarViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -115,12 +115,6 @@ void hasBorder() { } - // @Nested - // class Selection { - // MenuBarView view; - - // } - @Nested class Menus { @@ -142,7 +136,7 @@ void mouseClicksSameOpensAndClosesMenu() { }); Integer selected = (Integer) ReflectionTestUtils.getField(view, SELECTED_FIELD); - assertThat(selected).isEqualTo(0); + assertThat(selected).isZero(); MenuView menuView1 = (MenuView) ReflectionTestUtils.getField(view, MENUVIEW_FIELD); assertThat(menuView1).isNotNull(); @@ -180,7 +174,7 @@ void mouseClicksOpensDifferentMenus() { }); Integer selected = (Integer) ReflectionTestUtils.getField(view, SELECTED_FIELD); - assertThat(selected).isEqualTo(0); + assertThat(selected).isZero(); MenuView menuView1 = (MenuView) ReflectionTestUtils.getField(view, MENUVIEW_FIELD); assertThat(menuView1).isNotNull(); @@ -221,7 +215,7 @@ void arrowKeysMoveBetweenDifferentMenus() { }); Integer selected = (Integer) ReflectionTestUtils.getField(view, SELECTED_FIELD); - assertThat(selected).isEqualTo(0); + assertThat(selected).isZero(); MenuView menuView1 = (MenuView) ReflectionTestUtils.getField(view, MENUVIEW_FIELD); assertThat(menuView1).isNotNull(); @@ -257,11 +251,8 @@ void menuHasPositionRelativeToHeader() { }); MenuView menuView = (MenuView) ReflectionTestUtils.getField(view, MENUVIEW_FIELD); - assertThat(menuView).isNotNull().satisfies(m -> { - assertThat(m.getRect()).satisfies(r -> { - assertThat(r.x()).isEqualTo(7); - }); - }); + assertThat(menuView).isNotNull().satisfies(m -> assertThat(m.getRect()) + .satisfies(r -> assertThat(r.x()).isEqualTo(7))); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuViewTests.java index 295ea823e..623f9aaaf 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/MenuViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,7 +16,7 @@ package org.springframework.shell.component.view.control; import java.time.Duration; -import java.util.Arrays; +import java.util.List; import java.util.Set; import org.junit.jupiter.api.BeforeEach; @@ -51,7 +51,7 @@ class MenuViewTests extends AbstractViewTests { ThemeResolver themeResolver; @BeforeEach - public void setupMenuView() { + void setupMenuView() { ThemeRegistry themeRegistry = new ThemeRegistry(); themeRegistry.register(new Theme() { @Override @@ -126,8 +126,7 @@ void constructView() { }); assertThat(view.getItems()).hasSize(2); Set checkedActive = (Set) ReflectionTestUtils.getField(view, CHECKED_ACTIVE_FIELD); - assertThat(checkedActive).isNotNull(); - assertThat(checkedActive).hasSize(2); + assertThat(checkedActive).isNotNull().hasSize(2); } @Test @@ -169,7 +168,7 @@ class Styling { @Test void hasBorder() { MenuItem menuItem = new MenuView.MenuItem("sub1"); - view = new MenuView(Arrays.asList(menuItem)); + view = new MenuView(List.of(menuItem)); view.setShowBorder(true); view.setRect(0, 0, 80, 24); view.draw(screen24x80); @@ -179,7 +178,7 @@ void hasBorder() { @Test void selectedHighlightNoTheme() { MenuItem menuItem = new MenuView.MenuItem("sub1"); - view = new MenuView(Arrays.asList(menuItem)); + view = new MenuView(List.of(menuItem)); view.setShowBorder(true); view.setRect(0, 0, 10, 7); view.draw(screen7x10); @@ -191,7 +190,7 @@ void selectedHighlightNoTheme() { @Test void selectedHighlightThemeSet() { MenuItem menuItem = new MenuView.MenuItem("sub1"); - view = new MenuView(Arrays.asList(menuItem)); + view = new MenuView(List.of(menuItem)); view.setThemeResolver(themeResolver); view.setThemeName("default"); view.setShowBorder(true); @@ -205,10 +204,8 @@ void selectedHighlightThemeSet() { @Test void defaultItemCheckStyleIsNoCheck() { MenuItem menuItem = new MenuView.MenuItem("sub1"); - view = new MenuView(Arrays.asList(menuItem)); - assertThat(view.getItems()).allSatisfy(item -> { - assertThat(item.getCheckStyle()).isEqualTo(MenuItemCheckStyle.NOCHECK); - }); + view = new MenuView(List.of(menuItem)); + assertThat(view.getItems()).allSatisfy(item -> assertThat(item.getCheckStyle()).isEqualTo(MenuItemCheckStyle.NOCHECK)); } } @@ -231,9 +228,9 @@ void setup() { @Test void firstItemShouldAlwaysBeSelected() { MenuItem menuItem = new MenuView.MenuItem("sub1"); - MenuView view = new MenuView(Arrays.asList(menuItem)); - Integer selected = (Integer) ReflectionTestUtils.getField(view, SELECTED_FIELD); - assertThat(selected).isEqualTo(0); + MenuView menuView = new MenuView(List.of(menuItem)); + Integer selected = (Integer) ReflectionTestUtils.getField(menuView, SELECTED_FIELD); + assertThat(selected).isZero(); } @Test @@ -271,7 +268,7 @@ void wheelMovesSelection() { handleMouseWheelUp(view, 0, 1); selected = (Integer) ReflectionTestUtils.getField(view, SELECTED_FIELD); - assertThat(selected).isEqualTo(0); + assertThat(selected).isZero(); } @Test @@ -284,12 +281,9 @@ void selectionShouldNotMoveOutOfBounds() { handleKey(view, Key.CursorDown); selected = (Integer) ReflectionTestUtils.getField(view, SELECTED_FIELD); - assertThat(selected).isEqualTo(0); + assertThat(selected).isZero(); } - void canSelectManually() { - - } } @Nested @@ -457,10 +451,10 @@ void setup() { @Test void hasDefaultItemSelected() { MenuItem menuItem = new MenuView.MenuItem("sub1"); - MenuView view = new MenuView(Arrays.asList(menuItem)); - view.setShowBorder(true); - view.setRect(0, 0, 80, 24); - view.draw(screen24x80); + MenuView menuView = new MenuView(List.of(menuItem)); + menuView.setShowBorder(true); + menuView.setRect(0, 0, 80, 24); + menuView.draw(screen24x80); assertThat(forScreen(screen24x80)).hasHorizontalText("sub1", 0, 1, 5); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ProgressViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ProgressViewTests.java index 1c5f45da4..bb10f7ce3 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ProgressViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/ProgressViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 the original author or authors. + * Copyright 2024-present 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. @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ProgressViewTests extends AbstractViewTests { +class ProgressViewTests extends AbstractViewTests { @Nested class Construction { @@ -43,7 +43,7 @@ class Construction { void constructDefault() { view = new ProgressView(); assertThat(getViewItems(view)).hasSize(3); - assertThat(view.getState().tickValue()).isEqualTo(0); + assertThat(view.getState().tickValue()).isZero(); } @Test @@ -118,9 +118,9 @@ void setup() { @Test void dontAdvanceBounds() { - assertThat(view.getState().tickValue()).isEqualTo(0); + assertThat(view.getState().tickValue()).isZero(); view.tickAdvance(-1); - assertThat(view.getState().tickValue()).isEqualTo(0); + assertThat(view.getState().tickValue()).isZero(); view.tickAdvance(100); assertThat(view.getState().tickValue()).isEqualTo(100); view.tickAdvance(1); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/StatusBarViewTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/StatusBarViewTests.java index b517aec61..18112e424 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/StatusBarViewTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/StatusBarViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,9 +16,7 @@ package org.springframework.shell.component.view.control; import java.time.Duration; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -45,20 +43,20 @@ void constructView() { StatusBarView view; view = new StatusBarView(); - assertThat(view.getItems()).hasSize(0); + assertThat(view.getItems()).isEmpty(); view = new StatusBarView(new StatusItem[] { new StatusItem("item1") }); assertThat(view.getItems()).hasSize(1); - view = new StatusBarView(Arrays.asList(new StatusItem("item1"))); + view = new StatusBarView(List.of(new StatusItem("item1"))); assertThat(view.getItems()).hasSize(1); - view = new StatusBarView(Arrays.asList(StatusItem.of("item1"))); + view = new StatusBarView(List.of(StatusItem.of("item1"))); assertThat(view.getItems()).hasSize(1); - view = new StatusBarView(Arrays.asList(StatusItem.of("item1", null, null, false, 1))); + view = new StatusBarView(List.of(StatusItem.of("item1", null, null, false, 1))); assertThat(view.getItems()).hasSize(1); } @@ -91,11 +89,11 @@ void itemPosition() { }); view.setRect(0, 0, 10, 1); - item = (StatusItem) ReflectionTestUtils.invokeMethod(view, "itemAt", 0, 0); + item = ReflectionTestUtils.invokeMethod(view, "itemAt", 0, 0); assertThat(item).isNotNull(); assertThat(item.getTitle()).isEqualTo("item1"); - item = (StatusItem) ReflectionTestUtils.invokeMethod(view, "itemAt", 7, 0); + item = ReflectionTestUtils.invokeMethod(view, "itemAt", 7, 0); assertThat(item).isNotNull(); assertThat(item.getTitle()).isEqualTo("item2"); } @@ -136,28 +134,28 @@ void setup() { @Test void defaultsOrderNotChanged() { - view = new StatusBarView(Arrays.asList(p_0_1, p_0_2, p_0_3)); + view = new StatusBarView(List.of(p_0_1, p_0_2, p_0_3)); assertThat(extractTitles()).containsExactly("p_0_1", "p_0_2", "p_0_3"); } @Test void primaryBeforeNonprimary() { - view = new StatusBarView(Arrays.asList(p_0_1, n_0_1)); + view = new StatusBarView(List.of(p_0_1, n_0_1)); assertThat(extractTitles()).containsExactly("p_0_1", "n_0_1"); - view = new StatusBarView(Arrays.asList(n_0_1, p_0_1)); + view = new StatusBarView(List.of(n_0_1, p_0_1)); assertThat(extractTitles()).containsExactly("p_0_1", "n_0_1"); } @Test void priorityTakesOrder() { - view = new StatusBarView(Arrays.asList(p_0_1, p_1_1, p_2_1)); + view = new StatusBarView(List.of(p_0_1, p_1_1, p_2_1)); assertThat(extractTitles()).containsExactly("p_0_1", "p_1_1", "p_2_1"); - view = new StatusBarView(Arrays.asList(p_2_1, p_0_1, p_1_1)); + view = new StatusBarView(List.of(p_2_1, p_0_1, p_1_1)); assertThat(extractTitles()).containsExactly("p_0_1", "p_1_1", "p_2_1"); } private List extractTitles() { - return view.getItems().stream().map(StatusItem::getTitle).collect(Collectors.toList()); + return view.getItems().stream().map(StatusItem::getTitle).toList(); } } @@ -178,7 +176,7 @@ void hasBorder() { void primaryItems() { StatusItem item1 = new StatusItem("item1"); StatusItem item2 = new StatusItem("item2"); - StatusBarView view = new StatusBarView(Arrays.asList(item1, item2)); + StatusBarView view = new StatusBarView(List.of(item1, item2)); view.setItemSeparator(null); view.setRect(0, 0, 80, 1); view.draw(screen1x80); @@ -192,7 +190,7 @@ void nonprimaryItems() { StatusItem item2 = new StatusItem("item2"); item1.setPrimary(false); item2.setPrimary(false); - StatusBarView view = new StatusBarView(Arrays.asList(item1, item2)); + StatusBarView view = new StatusBarView(List.of(item1, item2)); view.setItemSeparator(null); view.setRect(0, 0, 80, 1); view.draw(screen1x80); @@ -205,7 +203,7 @@ void primaryAndNonprimaryItems() { StatusItem item1 = new StatusItem("item1"); StatusItem item2 = new StatusItem("item2"); item2.setPrimary(false); - StatusBarView view = new StatusBarView(Arrays.asList(item1, item2)); + StatusBarView view = new StatusBarView(List.of(item1, item2)); view.setItemSeparator(null); view.setRect(0, 0, 80, 1); view.draw(screen1x80); @@ -216,7 +214,7 @@ void primaryAndNonprimaryItems() { @Test void canChangeText() { StatusItem item1 = new StatusItem("item1"); - StatusBarView view = new StatusBarView(Arrays.asList(item1)); + StatusBarView view = new StatusBarView(List.of(item1)); view.setItemSeparator(null); view.setRect(0, 0, 80, 1); view.draw(screen1x80); @@ -234,7 +232,7 @@ void itemSeparator() { item3.setPrimary(false); StatusItem item4 = new StatusItem("item4"); item4.setPrimary(false); - StatusBarView view = new StatusBarView(Arrays.asList(item1, item2, item3, item4)); + StatusBarView view = new StatusBarView(List.of(item1, item2, item3, item4)); view.setRect(0, 0, 80, 1); view.draw(screen1x80); assertThat(forScreen(screen1x80)).hasHorizontalText("item1 | ", 0, 0, 8); @@ -254,7 +252,7 @@ void skipItemsWhenOverflow() { StatusItem item1 = new StatusItem("item11111111111111111111111111"); StatusItem item2 = new StatusItem("item22222222222222222222222222"); StatusItem item3 = new StatusItem("item33333333333333333333333333"); - StatusBarView view = new StatusBarView(Arrays.asList(item1, item2, item3)); + StatusBarView view = new StatusBarView(List.of(item1, item2, item3)); view.setItemSeparator(null); view.setRect(0, 0, 80, 1); view.draw(screen1x80); @@ -267,7 +265,7 @@ void skipItemsWhenOverflow() { void nullTitleDontDraw() { StatusItem item1 = new StatusItem("item1"); StatusItem item2 = new StatusItem(null); - StatusBarView view = new StatusBarView(Arrays.asList(item1, item2)); + StatusBarView view = new StatusBarView(List.of(item1, item2)); view.setItemSeparator(null); view.setRect(0, 0, 80, 1); view.draw(screen1x80); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/cell/ListCellTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/cell/ListCellTests.java index 87a650467..f5c19f830 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/cell/ListCellTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/control/cell/ListCellTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/DefaultEventLoopTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/DefaultEventLoopTests.java index 1564b111f..aeaca3613 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/DefaultEventLoopTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/DefaultEventLoopTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,8 +16,8 @@ package org.springframework.shell.component.view.event; import java.time.Duration; -import java.util.Arrays; import java.util.EnumSet; +import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -36,7 +36,7 @@ class DefaultEventLoopTests { - private final static Logger log = LoggerFactory.getLogger(DefaultEventLoopTests.class); + private static final Logger log = LoggerFactory.getLogger(DefaultEventLoopTests.class); private DefaultEventLoop loop; @AfterEach @@ -130,7 +130,7 @@ void dispatchNoSubscribersDoesNotError() { } @Test - void subsribtionCompletesWhenLoopDestroyed() { + void subscriptionCompletesWhenLoopDestroyed() { initDefault(); StepVerifier verifier1 = StepVerifier.create(loop.events()) .expectComplete() @@ -161,12 +161,12 @@ public Flux> process(Message message) { @Test void processorCreatesSameMessagesForAll() { TestEventLoopProcessor processor = new TestEventLoopProcessor(); - loop = new DefaultEventLoop(Arrays.asList(processor)); + loop = new DefaultEventLoop(List.of(processor)); StepVerifier verifier1 = StepVerifier.create(loop.events()) .assertNext(m -> { Integer count = m.getHeaders().get("count", Integer.class); - assertThat(count).isEqualTo(0); + assertThat(count).isZero(); }) .thenCancel() .verifyLater(); @@ -174,7 +174,7 @@ void processorCreatesSameMessagesForAll() { StepVerifier verifier2 = StepVerifier.create(loop.events()) .assertNext(m -> { Integer count = m.getHeaders().get("count", Integer.class); - assertThat(count).isEqualTo(0); + assertThat(count).isZero(); }) .thenCancel() .verifyLater(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyEventTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyEventTests.java index 0987a32cd..c108a5e21 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyEventTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyEventTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyHandlerTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyHandlerTests.java index a5993e1e2..028bdd959 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyHandlerTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/KeyHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -43,7 +43,7 @@ void doesNotHandlesOtherIfThisDoesNotConsume() { TestKeyHandler h2 = new TestKeyHandler(false); KeyHandler composed = h2.thenIfConsumed(h1); composed.handle(ARGS); - assertThat(h1.calls).isEqualTo(0); + assertThat(h1.calls).isZero(); assertThat(h2.calls).isEqualTo(1); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseEventTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseEventTests.java index 3bd9fe692..457880a37 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseEventTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseEventTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseHandlerTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseHandlerTests.java index 8a4a716da..855c4d0e7 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseHandlerTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/event/MouseHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -42,7 +42,7 @@ void doesNotHandlesOtherIfThisDoesNotConsume() { TestMouseHandler h2 = new TestMouseHandler(false); MouseHandler composed = h2.thenIfConsumed(h1); composed.handle(ARGS); - assertThat(h1.calls).isEqualTo(0); + assertThat(h1.calls).isZero(); assertThat(h2.calls).isEqualTo(1); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/geom/RectangleTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/geom/RectangleTests.java index 1d5ffebb1..82b50ede5 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/geom/RectangleTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/geom/RectangleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -23,11 +23,9 @@ class RectangleTests { - private Rectangle rect; - @Test void isEmpty() { - rect = new Rectangle(0, 0, 0, 0); + Rectangle rect = new Rectangle(0, 0, 0, 0); assertThat(rect.isEmpty()).isTrue(); rect = new Rectangle(1, 0, 0, 0); assertThat(rect.isEmpty()).isTrue(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/component/view/screen/ScreenTests.java b/spring-shell-core/src/test/java/org/springframework/shell/component/view/screen/ScreenTests.java index 63fe58e89..b16d9863a 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/component/view/screen/ScreenTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/component/view/screen/ScreenTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-present 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,12 +37,8 @@ void zeroDataSizeDoesntBreak() { @Test void cantResizeNegative() { - assertThatThrownBy(() -> { - screen0x0.resize(-1, 0); - }).hasMessageContaining("negative rows"); - assertThatThrownBy(() -> { - screen0x0.resize(0, -1); - }).hasMessageContaining("negative columns"); + assertThatThrownBy(() -> screen0x0.resize(-1, 0)).hasMessageContaining("negative rows"); + assertThatThrownBy(() -> screen0x0.resize(0, -1)).hasMessageContaining("negative columns"); } @Test diff --git a/spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java b/spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java index 38ad5f627..6ccfc0302 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/jline/ExtendedDefaultParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ExtendedDefaultParserTests { +class ExtendedDefaultParserTests { private final ExtendedDefaultParser springParser = new ExtendedDefaultParser(); private final DefaultParser jlineParser = new DefaultParser(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/jline/FileInputProviderTests.java b/spring-shell-core/src/test/java/org/springframework/shell/jline/FileInputProviderTests.java index 317649878..707fd51b9 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/jline/FileInputProviderTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/jline/FileInputProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2025 the original author or authors. + * Copyright 2025-present 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. @@ -55,9 +55,7 @@ void shouldThrowOnUnclosedQuoteDefaultParser(String line) { jlineParser.setEofOnUnclosedQuote(true); Reader reader = new StringReader(line); fileInputProvider = new FileInputProvider(reader, jlineParser); - Exception exception = assertThrows(EOFError.class, () -> { - fileInputProvider.readInput(); - }); + Exception exception = assertThrows(EOFError.class, () -> fileInputProvider.readInput()); String expectedExceptionMessage = "Missing closing quote"; String actualExceptionMessage = exception.getMessage(); assertTrue(actualExceptionMessage.contains(expectedExceptionMessage)); @@ -69,9 +67,7 @@ void shouldThrowOnUnclosedQuoteExtendedParser(String line) { springParser.setEofOnUnclosedQuote(true); Reader reader = new StringReader(line); fileInputProvider = new FileInputProvider(reader, springParser); - Exception exception = assertThrows(EOFError.class, () -> { - fileInputProvider.readInput(); - }); + Exception exception = assertThrows(EOFError.class, () -> fileInputProvider.readInput()); String expectedExceptionMessage = "Missing closing quote"; String actualExceptionMessage = exception.getMessage(); assertTrue(actualExceptionMessage.contains(expectedExceptionMessage)); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/jline/GenericResultHandlerServiceTests.java b/spring-shell-core/src/test/java/org/springframework/shell/jline/GenericResultHandlerServiceTests.java index 389d9561c..458cc4cc3 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/jline/GenericResultHandlerServiceTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/jline/GenericResultHandlerServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2021-present 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,10 +22,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class GenericResultHandlerServiceTests { +class GenericResultHandlerServiceTests { @Test - public void testSimpleHandling() { + void testSimpleHandling() { StringResultHandler stringResultHandler = new StringResultHandler(); IntegerResultHandler integerResultHandler = new IntegerResultHandler(); GenericResultHandlerService resultHandlerService = new GenericResultHandlerService(); @@ -33,13 +33,13 @@ public void testSimpleHandling() { resultHandlerService.addResultHandler(integerResultHandler); resultHandlerService.handle("string"); assertThat(stringResultHandler.result).isEqualTo("string"); - assertThat(integerResultHandler.result).isNull();; + assertThat(integerResultHandler.result).isNull(); resultHandlerService.handle(0); - assertThat(integerResultHandler.result).isEqualTo(0); + assertThat(integerResultHandler.result).isZero(); } @Test - public void testObjectHandling() { + void testObjectHandling() { ObjectResultHandler resultHandler = new ObjectResultHandler(); GenericResultHandlerService resultHandlerService = new GenericResultHandlerService(); resultHandlerService.addResultHandler(resultHandler); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/jline/InteractiveShellRunnerTests.java b/spring-shell-core/src/test/java/org/springframework/shell/jline/InteractiveShellRunnerTests.java index 98bab6a34..d7e3878fc 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/jline/InteractiveShellRunnerTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/jline/InteractiveShellRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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. @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; @Disabled("Hands intermittently") -public class InteractiveShellRunnerTests { +class InteractiveShellRunnerTests { private PipedOutputStream outIn; private InteractiveShellRunner.JLineInputProvider jLineInputProvider; @@ -67,7 +67,7 @@ private void initForShortcutKeyTest() throws Exception { } @Test - public void testClearWithCtrlC() throws Exception { + void testClearWithCtrlC() throws Exception { initForShortcutKeyTest(); @@ -97,7 +97,7 @@ public void testClearWithCtrlC() throws Exception { @Test - public void testExitWithCtrlC() throws Exception { + void testExitWithCtrlC() throws Exception { initForShortcutKeyTest(); @@ -125,7 +125,7 @@ public void testExitWithCtrlC() throws Exception { } @Test - public void testExitWithCtrlD() throws Exception { + void testExitWithCtrlD() throws Exception { initForShortcutKeyTest(); @@ -162,9 +162,7 @@ void oldApiCanRunReturnFalse() { @Test void oldApiRunThrows() { InteractiveShellRunner runner = new InteractiveShellRunner(null, null, null, null); - assertThatThrownBy(() -> { - runner.run(ofApplicationArguments()); - }); + assertThatThrownBy(() -> runner.run(ofApplicationArguments())); } private static ApplicationArguments ofApplicationArguments(String... args) { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/jline/NonInteractiveShellRunnerTests.java b/spring-shell-core/src/test/java/org/springframework/shell/jline/NonInteractiveShellRunnerTests.java index e8faa0c71..b16a3c414 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/jline/NonInteractiveShellRunnerTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/jline/NonInteractiveShellRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2024 the original author or authors. + * Copyright 2022-present 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. @@ -29,24 +29,23 @@ import org.springframework.shell.Shell; import org.springframework.shell.context.DefaultShellContext; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; @ExtendWith(MockitoExtension.class) -public class NonInteractiveShellRunnerTests { +class NonInteractiveShellRunnerTests { @Spy @InjectMocks private Shell shell; @Test - public void testEmptyArgsDontRun() throws Exception { + void testEmptyArgsDontRun() throws Exception { NonInteractiveShellRunner runner = new NonInteractiveShellRunner(null, null); assertThat(runner.run(new String[0])).isFalse(); } @Test - public void testNonEmptyArgsRun() throws Exception { + void testNonEmptyArgsRun() throws Exception { NonInteractiveShellRunner runner = new NonInteractiveShellRunner(shell, new DefaultShellContext()); ArgumentCaptor valueCapture = ArgumentCaptor.forClass(InputProvider.class); Mockito.doNothing().when(shell).run(valueCapture.capture()); @@ -54,7 +53,7 @@ public void testNonEmptyArgsRun() throws Exception { } @Test - public void shouldQuoteWithWhitespace() throws Exception { + void shouldQuoteWithWhitespace() throws Exception { NonInteractiveShellRunner runner = new NonInteractiveShellRunner(shell, new DefaultShellContext()); ArgumentCaptor valueCapture = ArgumentCaptor.forClass(InputProvider.class); Mockito.doNothing().when(shell).run(valueCapture.capture()); @@ -64,7 +63,7 @@ public void shouldQuoteWithWhitespace() throws Exception { } @Test - public void shouldNotQuoteIfQuoted() throws Exception { + void shouldNotQuoteIfQuoted() throws Exception { NonInteractiveShellRunner runner = new NonInteractiveShellRunner(shell, new DefaultShellContext()); ArgumentCaptor valueCapture = ArgumentCaptor.forClass(InputProvider.class); Mockito.doNothing().when(shell).run(valueCapture.capture()); @@ -74,7 +73,7 @@ public void shouldNotQuoteIfQuoted() throws Exception { } @Test - public void shouldNotQuoteWithoutWhitespace() throws Exception { + void shouldNotQuoteWithoutWhitespace() throws Exception { NonInteractiveShellRunner runner = new NonInteractiveShellRunner(shell, new DefaultShellContext()); ArgumentCaptor valueCapture = ArgumentCaptor.forClass(InputProvider.class); Mockito.doNothing().when(shell).run(valueCapture.capture()); @@ -92,9 +91,7 @@ void oldApiCanRunReturnFalse() { @Test void oldApiRunThrows() { NonInteractiveShellRunner runner = new NonInteractiveShellRunner(shell, null); - assertThatThrownBy(() -> { - runner.run(ofApplicationArguments()); - }); + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> runner.run(ofApplicationArguments())); } private static ApplicationArguments ofApplicationArguments(String... args) { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/jline/ScriptShellRunnerTests.java b/spring-shell-core/src/test/java/org/springframework/shell/jline/ScriptShellRunnerTests.java index c5b06c21c..0901ca090 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/jline/ScriptShellRunnerTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/jline/ScriptShellRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 the original author or authors. + * Copyright 2024-present 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,16 +28,15 @@ import org.springframework.boot.DefaultApplicationArguments; import org.springframework.shell.Shell; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; @ExtendWith(MockitoExtension.class) -public class ScriptShellRunnerTests { +class ScriptShellRunnerTests { @Mock Shell shell; - private ScriptShellRunner runner = new ScriptShellRunner(null, null); + private final ScriptShellRunner runner = new ScriptShellRunner(null, null); @Test void shouldNotRunWhenNoArgs() throws Exception { @@ -59,8 +58,8 @@ void shouldRunWhenFirstArgHavingFile(@TempDir Path workingDir) throws Exception Path path = workingDir.resolve("test"); Path file = Files.createFile(path); String pathStr = file.toAbsolutePath().toString(); - ScriptShellRunner runner = new ScriptShellRunner(null, shell); - assertThat(runner.run(new String[]{"@" + pathStr})).isTrue(); + ScriptShellRunner shellRunner = new ScriptShellRunner(null, shell); + assertThat(shellRunner.run(new String[]{"@" + pathStr})).isTrue(); } @Test @@ -70,9 +69,7 @@ void oldApiCanRunReturnFalse() { @Test void oldApiRunThrows() { - assertThatThrownBy(() -> { - runner.run(ofApplicationArguments()); - }); + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> runner.run(ofApplicationArguments())); } private static ApplicationArguments ofApplicationArguments(String... args) { diff --git a/spring-shell-core/src/test/java/org/springframework/shell/result/CommandNotFoundResultHandlerTests.java b/spring-shell-core/src/test/java/org/springframework/shell/result/CommandNotFoundResultHandlerTests.java index 7302eea23..77d2ec400 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/result/CommandNotFoundResultHandlerTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/result/CommandNotFoundResultHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. @@ -81,11 +81,9 @@ void customProviderGetsContext() { List commands = Arrays.asList("one", "two"); Map registrations = Collections.emptyMap(); CommandNotFound e = new CommandNotFound(commands, registrations, "text"); - given(provider.getIfAvailable()).willReturn(ctx -> { - return String.format("%s%s%s%s%s", "hi", ctx.error() == e ? "true" : "false", - ctx.commands().stream().collect(Collectors.joining()), - ctx.registrations() == registrations ? "true" : "false", ctx.text()); - }); + given(provider.getIfAvailable()).willReturn(ctx -> String.format("%s%s%s%s%s", "hi", ctx.error() == e ? "true" : "false", + String.join("", ctx.commands()), + ctx.registrations() == registrations ? "true" : "false", ctx.text())); given(provider.getIfAvailable(any())).willCallRealMethod(); given(terminal.writer()).willReturn(writer); CommandNotFoundResultHandler handler = new CommandNotFoundResultHandler(terminal, provider); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/style/PartsTextRendererTests.java b/spring-shell-core/src/test/java/org/springframework/shell/style/PartsTextRendererTests.java index 29c39cbe1..8c694b704 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/style/PartsTextRendererTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/style/PartsTextRendererTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,7 +30,7 @@ class PartsTextRendererTests { - private static Locale LOCALE = Locale.getDefault(); + private static final Locale LOCALE = Locale.getDefault(); private static PartsTextRenderer renderer; private static ThemeResolver themeResolver; @@ -52,14 +52,6 @@ public ThemeSettings getSettings() { renderer = new PartsTextRenderer(themeResolver); } - static PartsText of() { - return PartsText.of( - PartText.of("012", false), - PartText.of("3456", true), - PartText.of("789", false) - ); - } - static Stream test() { return Stream.of( Arguments.of( diff --git a/spring-shell-core/src/test/java/org/springframework/shell/style/StringToStyleExpressionRendererTests.java b/spring-shell-core/src/test/java/org/springframework/shell/style/StringToStyleExpressionRendererTests.java index 9a6a08580..28c49a61b 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/style/StringToStyleExpressionRendererTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/style/StringToStyleExpressionRendererTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,7 +28,7 @@ class StringToStyleExpressionRendererTests { - private static Locale LOCALE = Locale.getDefault(); + private static final Locale LOCALE = Locale.getDefault(); private static StringToStyleExpressionRenderer renderer; @BeforeAll diff --git a/spring-shell-core/src/test/java/org/springframework/shell/style/TemplateExecutorTests.java b/spring-shell-core/src/test/java/org/springframework/shell/style/TemplateExecutorTests.java index 939c3c35f..d80ac2c7c 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/style/TemplateExecutorTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/style/TemplateExecutorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,12 +26,12 @@ import static org.assertj.core.api.Assertions.assertThat; -public class TemplateExecutorTests { +class TemplateExecutorTests { private ThemeResolver themeResolver; @BeforeEach - public void setup() { + void setup() { ThemeRegistry themeRegistry = new ThemeRegistry(); themeRegistry.register(new Theme() { @Override @@ -48,7 +48,7 @@ public ThemeSettings getSettings() { } @Test - public void testSimple() { + void testSimple() { TemplateExecutor executor = new TemplateExecutor(themeResolver); String template = "<(\"foo\")>"; AttributedString result = executor.render(template, null); @@ -57,7 +57,7 @@ public void testSimple() { } @Test - public void testWithExpression() { + void testWithExpression() { TemplateExecutor executor = new TemplateExecutor(themeResolver); String template = ""; Map attributes = new HashMap<>(); @@ -68,7 +68,7 @@ public void testWithExpression() { } @Test - public void testWithTheme() { + void testWithTheme() { TemplateExecutor executor = new TemplateExecutor(themeResolver); String template = ""; Map attributes = new HashMap<>(); @@ -81,7 +81,7 @@ public void testWithTheme() { } @Test - public void testNullDontStyle() { + void testNullDontStyle() { TemplateExecutor executor = new TemplateExecutor(themeResolver); String template = ""; Map attributes = new HashMap<>(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeRegistryTests.java b/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeRegistryTests.java index 2b398c153..62c34273a 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeRegistryTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,10 +19,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ThemeRegistryTests { +class ThemeRegistryTests { @Test - public void test() { + void test() { ThemeRegistry registry = new ThemeRegistry(); Theme theme = Theme.of("name1", ThemeSettings.defaults()); registry.register(theme); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeResolverTests.java b/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeResolverTests.java index 84246a9c3..f9abe90c1 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeResolverTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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,12 +26,12 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ThemeResolverTests { +class ThemeResolverTests { private ThemeResolver themeResolver; @BeforeEach - public void setup() { + void setup() { ThemeRegistry themeRegistry = new ThemeRegistry(); themeRegistry.register(new Theme() { @Override @@ -48,7 +48,7 @@ public ThemeSettings getSettings() { } @Test - public void styleExpression() { + void styleExpression() { assertThat(themeResolver.resolveStyleTag(StyleSettings.TAG_TITLE)).isEqualTo("bold"); assertThat(themeResolver.resolveStyle("bold")).isEqualTo(AttributedStyle.BOLD); assertThat(themeResolver.evaluateExpression("@{bold foo}")) @@ -56,41 +56,41 @@ public void styleExpression() { } @Test - public void resolveValuesIndStyle() { + void resolveValuesIndStyle() { AttributedStyle s = AttributedStyle.DEFAULT.background(AttributedStyle.BLUE).foreground(AttributedStyle.RED); - ResolvedValues resolvedValues = themeResolver.resolveValues(s); + ResolvedValues resolvedValues = ThemeResolver.resolveValues(s); assertThat(resolvedValues.background()).isEqualTo(Colors.DEFAULT_COLORS_256[AttributedStyle.BLUE]); assertThat(resolvedValues.foreground()).isEqualTo(Colors.DEFAULT_COLORS_256[AttributedStyle.RED]); } @Test - public void resolveValuesRgbStyle() { + void resolveValuesRgbStyle() { AttributedStyle s = AttributedStyle.DEFAULT.backgroundRgb(Color.BLUE).foregroundRgb(Color.RED); - ResolvedValues resolvedValues = themeResolver.resolveValues(s); + ResolvedValues resolvedValues = ThemeResolver.resolveValues(s); assertThat(resolvedValues.background()).isEqualTo(Color.BLUE); assertThat(resolvedValues.foreground()).isEqualTo(Color.RED); } @Test - public void resolveValuesRgbExp() { + void resolveValuesRgbExp() { AttributedStyle s = themeResolver.resolveStyle("bg-rgb:#0000FF,fg-rgb:#FF0000"); - ResolvedValues resolvedValues = themeResolver.resolveValues(s); + ResolvedValues resolvedValues = ThemeResolver.resolveValues(s); assertThat(resolvedValues.background()).isEqualTo(Color.BLUE); assertThat(resolvedValues.foreground()).isEqualTo(Color.RED); } @Test - public void resolveValuesIndExp() { + void resolveValuesIndExp() { AttributedStyle s = themeResolver.resolveStyle("bg:blue,fg:red"); - ResolvedValues resolvedValues = themeResolver.resolveValues(s); + ResolvedValues resolvedValues = ThemeResolver.resolveValues(s); assertThat(resolvedValues.background()).isEqualTo(Colors.DEFAULT_COLORS_256[AttributedStyle.BLUE]); assertThat(resolvedValues.foreground()).isEqualTo(Colors.DEFAULT_COLORS_256[AttributedStyle.RED]); } @Test - public void resolveValuesNotDefinedExp() { + void resolveValuesNotDefinedExp() { AttributedStyle s = themeResolver.resolveStyle(""); - ResolvedValues resolvedValues = themeResolver.resolveValues(s); + ResolvedValues resolvedValues = ThemeResolver.resolveValues(s); assertThat(resolvedValues.background()).isEqualTo(-1); assertThat(resolvedValues.foreground()).isEqualTo(-1); } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeSettingsTests.java b/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeSettingsTests.java index fcce4b502..950207234 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeSettingsTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/style/ThemeSettingsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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,10 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ThemeSettingsTests { +class ThemeSettingsTests { @Test - public void testGeneratedStyle() { + void testGeneratedStyle() { ThemeSettings themeSettings = ThemeSettings.defaults(); String resolveTag = themeSettings.styles().resolveTag(StyleSettings.TAG_TITLE); assertThat(resolveTag).isEqualTo("bold"); @@ -55,7 +55,7 @@ public void testGeneratedStyle() { StyleSettings.TAG_ITEM_SELECTOR, StyleSettings.TAG_HIGHLIGHT, StyleSettings.TAG_BACKGROUND }) - public void testTags(String tag) { + void testTags(String tag) { ThemeSettings themeSettings = ThemeSettings.defaults(); String resolveTag = themeSettings.styles().resolveTag(tag); assertThat(resolveTag).isNotNull(); diff --git a/spring-shell-core/src/test/java/org/springframework/shell/support/search/ExactMatchNaiveSearchMatchAlgorithmTests.java b/spring-shell-core/src/test/java/org/springframework/shell/support/search/ExactMatchNaiveSearchMatchAlgorithmTests.java index 125a2d8d7..858ad1894 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/support/search/ExactMatchNaiveSearchMatchAlgorithmTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/support/search/ExactMatchNaiveSearchMatchAlgorithmTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -46,9 +46,9 @@ static Stream testExactMatch() { Arguments.of(false, false, true, "/.oh-my-zsh/cache", "zsh/c", false, 8, 13, new int[] { 8, 9, 10, 11, 12 }, SCORE_MATCH * 5 + BONUS_BOUNDARY * (BONUS_FIRST_CHAR_MULTIPLIER + 3) + BONUS_BOUNDARY_DELIMITER), Arguments.of(false, false, true, "fooBarbaz", "o", false, 1, 2, new int[] { 1 }, - SCORE_MATCH * 1), + SCORE_MATCH), Arguments.of(false, false, true, "/tmp/test/11/file11.txt", "e", false, 6, 7, new int[] { 6 }, - SCORE_MATCH * 1), + SCORE_MATCH), Arguments.of(false, true, true, "Só Danço Samba", "So", false, 0, 2, new int[] { 0, 1 }, 62), Arguments.of(false, true, true, "Danço", "danco", false, 0, 5, new int[] { 0, 1, 2, 3, 4 }, diff --git a/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV1SearchMatchAlgorithmTests.java b/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV1SearchMatchAlgorithmTests.java index 8d71acd72..95478172d 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV1SearchMatchAlgorithmTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV1SearchMatchAlgorithmTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV2SearchMatchAlgorithmTests.java b/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV2SearchMatchAlgorithmTests.java index 0c8959ecf..f1d183682 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV2SearchMatchAlgorithmTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/support/search/FuzzyMatchV2SearchMatchAlgorithmTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-core/src/test/java/org/springframework/shell/support/search/NormalizeTests.java b/spring-shell-core/src/test/java/org/springframework/shell/support/search/NormalizeTests.java index 26372d12e..f22bcbbed 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/support/search/NormalizeTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/support/search/NormalizeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -23,8 +23,7 @@ class NormalizeTests { @Test void testNormalizeMap() { - assertThat(Normalize.normalized.get('á')).isEqualTo('a'); - assertThat(Normalize.normalized.get('ự')).isEqualTo('u'); + assertThat(Normalize.normalized).containsEntry('á', 'a').containsEntry('ự', 'u'); } @Test diff --git a/spring-shell-core/src/test/java/org/springframework/shell/support/search/SearchMatchTests.java b/spring-shell-core/src/test/java/org/springframework/shell/support/search/SearchMatchTests.java index 78bafaf43..05082ff41 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/support/search/SearchMatchTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/support/search/SearchMatchTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class SearchMatchTests { +class SearchMatchTests { @Test void testAlgoType() { @@ -29,7 +29,7 @@ void testAlgoType() { .forward(true) .build(); assertThat(searchMatch).isNotNull(); - SearchMatchResult result = null; + SearchMatchResult result; result = searchMatch.match("fake", "fake"); assertThat(result.getAlgorithm()).isInstanceOf(FuzzyMatchV2SearchMatchAlgorithm.class); diff --git a/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java b/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java index 3c7484aca..77abb4c72 100644 --- a/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java +++ b/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/standard/ComponentCommandsTests.java b/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/standard/ComponentCommandsTests.java index aa5bc76cc..151587107 100644 --- a/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/standard/ComponentCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-commands/src/test/java/org/springframework/shell/samples/standard/ComponentCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,23 +37,15 @@ public class ComponentCommandsTests extends AbstractSampleTests { void componentSingle(String command, boolean interactive) { BaseShellSession session = createSession(command, interactive); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(session.screen().lines()).anySatisfy(line -> { - assertThat(line).containsPattern("[>❯] key1"); - }); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(session.screen().lines()) + .anySatisfy(line -> assertThat(line).containsPattern("[>❯] key1"))); session.write(session.writeSequence().keyDown().build()); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(session.screen().lines()).anySatisfy(line -> { - assertThat(line).containsPattern("[>❯] key2"); - }); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(session.screen().lines()) + .anySatisfy(line -> assertThat(line).containsPattern("[>❯] key2"))); session.write(session.writeSequence().cr().build()); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - ShellAssertions.assertThat(session.screen()).containsText("Got value value2"); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> ShellAssertions.assertThat(session.screen()).containsText("Got value value2")); } @ParameterizedTest @@ -64,22 +56,14 @@ void componentSingle(String command, boolean interactive) { void componentMulti(String command, boolean interactive) { BaseShellSession session = createSession(command, interactive); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(session.screen().lines()).anySatisfy(line -> { - assertThat(line).containsPattern("[>❯] (☐|\\[ \\]) key1"); - }); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(session.screen().lines()) + .anySatisfy(line -> assertThat(line).containsPattern("[>❯] (☐|\\[ \\]) key1"))); session.write(session.writeSequence().space().build()); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(session.screen().lines()).anySatisfy(line -> { - assertThat(line).containsPattern("[>❯] (☒|\\[x\\]) key1"); - }); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(session.screen().lines()) + .anySatisfy(line -> assertThat(line).containsPattern("[>❯] (☒|\\[x\\]) key1"))); session.write(session.writeSequence().cr().build()); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - ShellAssertions.assertThat(session.screen()).containsText("Got value value1,value2"); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> ShellAssertions.assertThat(session.screen()).containsText("Got value value1,value2")); } } diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java index f8ff05491..02c86f873 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/AbstractSampleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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. @@ -41,9 +41,7 @@ public class AbstractSampleTests { protected ShellTestClient client; protected void assertScreenContainsText(BaseShellSession session, String text) { - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - ShellAssertions.assertThat(session.screen()).containsText(text); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> ShellAssertions.assertThat(session.screen()).containsText(text)); } protected void assertScreenNotContainsText(BaseShellSession session, String textFound, String textNotFound) { diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/AliasCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/AliasCommandsTests.java index 4698b2788..8cffe89d1 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/AliasCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/AliasCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ArityCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ArityCommandsTests.java index ee207a39b..d9c55bbe8 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ArityCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ArityCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/DefaultValueCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/DefaultValueCommandsTests.java index 87f493824..79e3b53df 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/DefaultValueCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/DefaultValueCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2EArgumentsProvider.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2EArgumentsProvider.java index 7bc1453bf..8eb8ab5b2 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2EArgumentsProvider.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2EArgumentsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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,7 +34,7 @@ public void accept(E2ESource annotation) { } @Override - public Stream provideArguments(ExtensionContext context) throws Exception { + public Stream provideArguments(ExtensionContext context) { String command = this.annotation.command(); List arguments = new ArrayList<>(); boolean anno = this.annotation.anno(); diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2ESource.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2ESource.java index 5c43ca5b2..595520974 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2ESource.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/E2ESource.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ErrorHandlingCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ErrorHandlingCommandsTests.java index a9900c35e..09ad95e56 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ErrorHandlingCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/ErrorHandlingCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpCommandsTests.java index 20fc50f38..120082656 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpOptionCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpOptionCommandsTests.java index 8542cc429..5d476e86e 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpOptionCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HelpOptionCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HiddenCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HiddenCommandsTests.java index ed6e3050e..b180a5012 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HiddenCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/HiddenCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionConversionCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionConversionCommandsTests.java index 2fcdd828e..477f19825 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionConversionCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionConversionCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionTypeCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionTypeCommandsTests.java index e27b8c3d7..abebe4a41 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionTypeCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionTypeCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionalValueCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionalValueCommandsTests.java index 0d2f695da..18adfbf8a 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionalValueCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/OptionalValueCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/RequiredValueCommandsTests.java b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/RequiredValueCommandsTests.java index dd2ad721d..87f4712bb 100644 --- a/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/RequiredValueCommandsTests.java +++ b/spring-shell-samples/spring-shell-sample-e2e/src/test/java/org/springframework/shell/samples/e2e/RequiredValueCommandsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/CommandValueProviderTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/CommandValueProviderTests.java index 4d2de9e12..289200e41 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/CommandValueProviderTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/CommandValueProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-present 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. @@ -38,18 +38,18 @@ * * @author Eric Bottard */ -public class CommandValueProviderTests { +class CommandValueProviderTests { @Mock private CommandCatalog catalog; @BeforeEach - public void setUp() { + void setUp() { MockitoAnnotations.openMocks(this); } @Test - public void testValues() { + void testValues() { CommandValueProvider valueProvider = new CommandValueProvider(catalog); CompletionContext completionContext = new CompletionContext(Arrays.asList("help", "m"), 0, 0, null, null); diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/StandardMethodTargetRegistrarTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/StandardMethodTargetRegistrarTests.java index d6fb4fef7..8e6f485d6 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/StandardMethodTargetRegistrarTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/StandardMethodTargetRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 the original author or authors. + * Copyright 2017-present 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. @@ -41,22 +41,22 @@ * * @author Eric Bottard */ -public class StandardMethodTargetRegistrarTests { +class StandardMethodTargetRegistrarTests { private StandardMethodTargetRegistrar registrar; private AnnotationConfigApplicationContext applicationContext; private CommandCatalog catalog; private DefaultShellContext shellContext; - private CommandRegistration.BuilderSupplier builder = () -> CommandRegistration.builder(); + private final CommandRegistration.BuilderSupplier builder = CommandRegistration::builder; @BeforeEach - public void setup() { + void setup() { shellContext = new DefaultShellContext(); catalog = CommandCatalog.of(null, shellContext); } @AfterEach - public void cleanup() { + void cleanup() { if (applicationContext != null) { applicationContext.close(); } @@ -65,7 +65,7 @@ public void cleanup() { } @Test - public void testRegistrations() { + void testRegistrations() { applicationContext = new AnnotationConfigApplicationContext(Sample1.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); registrar.register(catalog); @@ -100,7 +100,7 @@ public String greet(String what) { } @Test - public void testOptionRequiredWithAnnotation() { + void testOptionRequiredWithAnnotation() { applicationContext = new AnnotationConfigApplicationContext(Sample2.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); registrar.register(catalog); @@ -122,7 +122,7 @@ public String sayHello(@ShellOption String what) { } @Test - public void testOptionOptionalWithAnnotation() { + void testOptionOptionalWithAnnotation() { applicationContext = new AnnotationConfigApplicationContext(Sample3.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); registrar.register(catalog); @@ -145,7 +145,7 @@ public String sayHello(@ShellOption( defaultValue = ShellOption.NULL) String wha } @Test - public void testAvailabilityIndicators() { + void testAvailabilityIndicators() { applicationContext = new AnnotationConfigApplicationContext(SampleWithAvailability.class); SampleWithAvailability sample = applicationContext.getBean(SampleWithAvailability.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); @@ -219,13 +219,11 @@ private Availability availabilityFromWildcard() { } @Test - public void testAvailabilityIndicatorErrorMultipleExplicit() { + void testAvailabilityIndicatorErrorMultipleExplicit() { applicationContext = new AnnotationConfigApplicationContext(WrongAvailabilityIndicatorOnShellMethod.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); - assertThatThrownBy(() -> { - registrar.register(catalog); - }).isInstanceOf(IllegalArgumentException.class) + assertThatThrownBy(() -> registrar.register(catalog)).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("When set on a @ShellMethod method, the value of the @ShellMethodAvailability should be a single element") .hasMessageContaining("Found [one, two]") .hasMessageContaining("wrong()"); @@ -241,13 +239,11 @@ public void wrong() { } @Test - public void testAvailabilityIndicatorWildcardNotAlone() { + void testAvailabilityIndicatorWildcardNotAlone() { applicationContext = new AnnotationConfigApplicationContext(WrongAvailabilityIndicatorWildcardNotAlone.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); - assertThatThrownBy(() -> { - registrar.register(catalog); - }).isInstanceOf(IllegalArgumentException.class) + assertThatThrownBy(() -> registrar.register(catalog)).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("When using '*' as a wildcard for ShellMethodAvailability, this can be the only value. Found [one, *]") .hasMessageContaining("availability()"); } @@ -267,13 +263,11 @@ public void wrong() { } @Test - public void testAvailabilityIndicatorAmbiguous() { + void testAvailabilityIndicatorAmbiguous() { applicationContext = new AnnotationConfigApplicationContext(WrongAvailabilityIndicatorAmbiguous.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); - assertThatThrownBy(() -> { - registrar.register(catalog); - }).isInstanceOf(IllegalArgumentException.class) + assertThatThrownBy(() -> registrar.register(catalog)).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Found several @ShellMethodAvailability") .hasMessageContaining("wrong()") .hasMessageContaining("availability()") @@ -300,7 +294,7 @@ public void wrong() { } @Test - public void testGrouping() { + void testGrouping() { applicationContext = new AnnotationConfigApplicationContext(GroupOneCommands.class, GroupTwoCommands.class, GroupThreeCommands.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); @@ -333,7 +327,7 @@ public void testGrouping() { } @Test - public void testInteractionModeInteractive() { + void testInteractionModeInteractive() { shellContext.setInteractionMode(InteractionMode.INTERACTIVE); applicationContext = new AnnotationConfigApplicationContext(InteractionModeCommands.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); @@ -345,7 +339,7 @@ public void testInteractionModeInteractive() { } @Test - public void testInteractionModeNonInteractive() { + void testInteractionModeNonInteractive() { shellContext.setInteractionMode(InteractionMode.NONINTERACTIVE); applicationContext = new AnnotationConfigApplicationContext(InteractionModeCommands.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); @@ -373,7 +367,7 @@ public void foo3() { } @Test - public void testOptionUseDefaultValue() { + void testOptionUseDefaultValue() { shellContext.setInteractionMode(InteractionMode.NONINTERACTIVE); applicationContext = new AnnotationConfigApplicationContext(DefaultValuesCommands.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); @@ -409,7 +403,7 @@ public void foo3(@ShellOption(defaultValue = ShellOption.NULL) String arg1) { } @Test - public void testOptionValuesWithBoolean() { + void testOptionValuesWithBoolean() { applicationContext = new AnnotationConfigApplicationContext(ValuesWithBoolean.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); registrar.register(catalog); @@ -418,28 +412,28 @@ public void testOptionValuesWithBoolean() { assertThat(catalog.getRegistrations().get("foo1").getOptions()).hasSize(1); assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getDefaultValue()).isEqualTo("false"); assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).isRequired()).isFalse(); - assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getArityMin()).isEqualTo(0); + assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getArityMin()).isZero(); assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getArityMax()).isEqualTo(1); assertThat(catalog.getRegistrations().get("foo2")).isNotNull(); assertThat(catalog.getRegistrations().get("foo2").getOptions()).hasSize(1); assertThat(catalog.getRegistrations().get("foo2").getOptions().get(0).getDefaultValue()).isEqualTo("true"); assertThat(catalog.getRegistrations().get("foo2").getOptions().get(0).isRequired()).isFalse(); - assertThat(catalog.getRegistrations().get("foo2").getOptions().get(0).getArityMin()).isEqualTo(0); + assertThat(catalog.getRegistrations().get("foo2").getOptions().get(0).getArityMin()).isZero(); assertThat(catalog.getRegistrations().get("foo2").getOptions().get(0).getArityMax()).isEqualTo(1); assertThat(catalog.getRegistrations().get("foo3")).isNotNull(); assertThat(catalog.getRegistrations().get("foo3").getOptions()).hasSize(1); assertThat(catalog.getRegistrations().get("foo3").getOptions().get(0).isRequired()).isFalse(); assertThat(catalog.getRegistrations().get("foo3").getOptions().get(0).getDefaultValue()).isEqualTo("false"); - assertThat(catalog.getRegistrations().get("foo3").getOptions().get(0).getArityMin()).isEqualTo(0); + assertThat(catalog.getRegistrations().get("foo3").getOptions().get(0).getArityMin()).isZero(); assertThat(catalog.getRegistrations().get("foo3").getOptions().get(0).getArityMax()).isEqualTo(1); assertThat(catalog.getRegistrations().get("foo4")).isNotNull(); assertThat(catalog.getRegistrations().get("foo4").getOptions()).hasSize(1); assertThat(catalog.getRegistrations().get("foo4").getOptions().get(0).isRequired()).isFalse(); assertThat(catalog.getRegistrations().get("foo4").getOptions().get(0).getDefaultValue()).isEqualTo("false"); - assertThat(catalog.getRegistrations().get("foo4").getOptions().get(0).getArityMin()).isEqualTo(0); + assertThat(catalog.getRegistrations().get("foo4").getOptions().get(0).getArityMin()).isZero(); assertThat(catalog.getRegistrations().get("foo4").getOptions().get(0).getArityMax()).isEqualTo(1); } @@ -464,7 +458,7 @@ public void foo4(boolean arg1) { } @Test - public void testOptionWithoutHyphenRegisterFromDefaultPrefix() { + void testOptionWithoutHyphenRegisterFromDefaultPrefix() { applicationContext = new AnnotationConfigApplicationContext(OptionWithoutHyphenRegisterFromDefaultPrefix.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); registrar.register(catalog); @@ -472,7 +466,7 @@ public void testOptionWithoutHyphenRegisterFromDefaultPrefix() { assertThat(catalog.getRegistrations().get("foo1")).isNotNull(); assertThat(catalog.getRegistrations().get("foo1").getOptions()).hasSize(1); assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getLongNames()).hasSize(1); - assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getShortNames()).hasSize(0); + assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getShortNames()).isEmpty(); } @ShellComponent @@ -484,14 +478,14 @@ public void foo1(@ShellOption("xxx") boolean arg1) { } @Test - public void testOptionWithoutHyphenRegisterFromChangedPrefix() { + void testOptionWithoutHyphenRegisterFromChangedPrefix() { applicationContext = new AnnotationConfigApplicationContext(OptionWithoutHyphenRegisterFromChangedPrefix.class); registrar = new StandardMethodTargetRegistrar(applicationContext, builder); registrar.register(catalog); assertThat(catalog.getRegistrations().get("foo1")).isNotNull(); assertThat(catalog.getRegistrations().get("foo1").getOptions()).hasSize(1); - assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getLongNames()).hasSize(0); + assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getLongNames()).isEmpty(); assertThat(catalog.getRegistrations().get("foo1").getOptions().get(0).getShortNames()).hasSize(1); } @@ -510,11 +504,9 @@ void OptionWithCustomType() { registrar.register(catalog); assertThat(catalog.getRegistrations().get("foo1")).isNotNull(); - assertThat(catalog.getRegistrations().get("foo1")).satisfies(reg -> { - assertThat(reg.getOptions().get(0)).satisfies(option -> { - assertThat(option.getType().getGeneric(0).getType()).isEqualTo(Pojo.class); - }); - }); + assertThat(catalog.getRegistrations().get("foo1")).satisfies(reg -> assertThat(reg.getOptions().get(0)) + .satisfies(option -> assertThat(option.getType().getGeneric(0).getType()) + .isEqualTo(Pojo.class))); } diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandAvailabilityInfoModelTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandAvailabilityInfoModelTests.java index 0620f4e39..67ad6e82c 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandAvailabilityInfoModelTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandAvailabilityInfoModelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CommandAvailabilityInfoModelTests { +class CommandAvailabilityInfoModelTests { @Test void hasDefaults() { diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java index 85fbff92d..488149bd6 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/CommandInfoModelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CommandInfoModelTests { +class CommandInfoModelTests { @Test void hasGivenName() { diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/GroupsInfoModelTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/GroupsInfoModelTests.java index 95a21e145..49aa473d6 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/GroupsInfoModelTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/GroupsInfoModelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. @@ -23,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class GroupsInfoModelTests { +class GroupsInfoModelTests { private CommandCatalog commandCatalog; diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/HelpTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/HelpTests.java index 563b6f33c..3eebbc0c2 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/HelpTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/HelpTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Locale; import java.util.Optional; @@ -55,11 +56,11 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = HelpTests.Config.class) -public class HelpTests { +class HelpTests { private static Locale previousLocale; private String testName; - private CommandsPojo commandsPojo = new CommandsPojo(); + private final CommandsPojo commandsPojo = new CommandsPojo(); @Autowired private CommandCatalog commandCatalog; @@ -68,30 +69,26 @@ public class HelpTests { private Help help; @BeforeAll - public static void setAssumedLocale() { + static void setAssumedLocale() { previousLocale = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); } @AfterAll - public static void restorePreviousLocale() { + static void restorePreviousLocale() { Locale.setDefault(previousLocale); } @BeforeEach - public void setup(TestInfo testInfo) { + void setup(TestInfo testInfo) { Optional testMethod = testInfo.getTestMethod(); - if (testMethod.isPresent()) { - this.testName = testMethod.get().getName(); - } + testMethod.ifPresent(method -> this.testName = method.getName()); Collection regs = this.commandCatalog.getRegistrations().values(); - regs.stream().forEach(r -> { - this.commandCatalog.unregister(r); - }); + regs.forEach(r -> this.commandCatalog.unregister(r)); } @Test - public void testCommandHelp() throws Exception { + void testCommandHelp() throws Exception { CommandRegistration registration = CommandRegistration.builder() .command("first-command") .description("A rather extensive description of some command.") @@ -127,7 +124,7 @@ public void testCommandHelp() throws Exception { } @Test - public void testCommandListDefault() throws Exception { + void testCommandListDefault() throws Exception { registerCommandListCommands(); String list = this.help.help(null).toString(); list = removeNewLines(list); @@ -135,7 +132,7 @@ public void testCommandListDefault() throws Exception { } @Test - public void testCommandListFlat() throws Exception { + void testCommandListFlat() throws Exception { registerCommandListCommands(); this.help.setShowGroups(false); String list = this.help.help(null).toString(); @@ -144,10 +141,9 @@ public void testCommandListFlat() throws Exception { } @Test - public void testUnknownCommand() throws Exception { - assertThatThrownBy(() -> { - this.help.help(new String[] { "some", "unknown", "command" }); - }).isInstanceOf(IllegalArgumentException.class); + void testUnknownCommand() { + assertThatThrownBy(() -> this.help.help(new String[] { "some", "unknown", "command" })) + .isInstanceOf(IllegalArgumentException.class); } private String removeNewLines(String str) { @@ -156,10 +152,10 @@ private String removeNewLines(String str) { private String sample() throws IOException { InputStream is = new ClassPathResource(HelpTests.class.getSimpleName() + "-" + testName + ".txt", HelpTests.class).getInputStream(); - return removeNewLines(FileCopyUtils.copyToString(new InputStreamReader(is, "UTF-8"))); + return removeNewLines(FileCopyUtils.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8))); } - private void registerCommandListCommands() throws Exception { + private void registerCommandListCommands() { CommandRegistration registration1 = CommandRegistration.builder() .command("first-command") .description("A rather extensive description of some command.") diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/StandardCommandsAutoConfigurationTest.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/StandardCommandsAutoConfigurationTest.java deleted file mode 100644 index 2815a158c..000000000 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/commands/StandardCommandsAutoConfigurationTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2017 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 - * - * https://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.shell.standard.commands; - -/** - * Tests for {@link StandardCommandsAutoConfiguration}. - * - * @author Eric Bottard - */ -public class StandardCommandsAutoConfigurationTest { - -} diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/AbstractCompletionsTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/AbstractCompletionsTests.java index 77286a8f3..42c28b157 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/AbstractCompletionsTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/AbstractCompletionsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class AbstractCompletionsTests { +class AbstractCompletionsTests { private final TestCommands commands = new TestCommands(); @@ -116,7 +116,7 @@ public class AbstractCompletionsTests { .build(); @Test - public void deepL3Commands() { + void deepL3Commands() { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); CommandCatalog commandCatalog = CommandCatalog.of(); @@ -130,30 +130,22 @@ public void deepL3Commands() { assertThat(commandModel.getCommands()).satisfiesExactlyInAnyOrder( c3 -> { assertThat(c3.getMainCommand()).isEqualTo("test3"); - assertThat(c3.getOptions()).hasSize(0); + assertThat(c3.getOptions()).isEmpty(); assertThat(c3.getSubCommands()).hasSize(2); assertThat(c3.getCommands()).hasSize(2); assertThat(c3.getCommands()).satisfiesExactlyInAnyOrder( c34 -> { assertThat(c34.getMainCommand()).isEqualTo("test4"); assertThat(c34.getCommands()).satisfiesExactlyInAnyOrder( - c345 -> { - assertThat(c345.getMainCommand()).isEqualTo("test5"); - }, - c346 -> { - assertThat(c346.getMainCommand()).isEqualTo("test6"); - } + c345 -> assertThat(c345.getMainCommand()).isEqualTo("test5"), + c346 -> assertThat(c346.getMainCommand()).isEqualTo("test6") ); }, c35 -> { assertThat(c35.getMainCommand()).isEqualTo("test5"); assertThat(c35.getCommands()).satisfiesExactlyInAnyOrder( - c355 -> { - assertThat(c355.getMainCommand()).isEqualTo("test5"); - }, - c356 -> { - assertThat(c356.getMainCommand()).isEqualTo("test6"); - } + c355 -> assertThat(c355.getMainCommand()).isEqualTo("test5"), + c356 -> assertThat(c356.getMainCommand()).isEqualTo("test6") ); } ); @@ -162,7 +154,7 @@ public void deepL3Commands() { } @Test - public void deepL2Commands() { + void deepL2Commands() { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); CommandCatalog commandCatalog = CommandCatalog.of(); @@ -174,7 +166,7 @@ public void deepL2Commands() { assertThat(commandModel.getCommands()).satisfiesExactlyInAnyOrder( c3 -> { assertThat(c3.getMainCommand()).isEqualTo("test3"); - assertThat(c3.getOptions()).hasSize(0); + assertThat(c3.getOptions()).isEmpty(); assertThat(c3.getSubCommands()).hasSize(2); assertThat(c3.getCommands()).hasSize(2); assertThat(c3.getCommands()).satisfiesExactlyInAnyOrder( @@ -182,18 +174,14 @@ public void deepL2Commands() { assertThat(c34.getMainCommand()).isEqualTo("test4"); assertThat(c34.getOptions()).hasSize(1); assertThat(c34.getOptions()).satisfiesExactly( - o -> { - assertThat(o.option()).isEqualTo("--param4"); - } + o -> assertThat(o.option()).isEqualTo("--param4") ); }, c35 -> { assertThat(c35.getMainCommand()).isEqualTo("test5"); assertThat(c35.getOptions()).hasSize(1); assertThat(c35.getOptions()).satisfiesExactly( - o -> { - assertThat(o.option()).isEqualTo("--param4"); - } + o -> assertThat(o.option()).isEqualTo("--param4") ); } ); @@ -202,7 +190,7 @@ public void deepL2Commands() { } @Test - public void testBasicModelGeneration() { + void testBasicModelGeneration() { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); CommandCatalog commandCatalog = CommandCatalog.of(); @@ -216,22 +204,20 @@ public void testBasicModelGeneration() { assertThat(commandModel.getCommands()).satisfiesExactlyInAnyOrder( c1 -> { assertThat(c1.getMainCommand()).isEqualTo("test1"); - assertThat(c1.getSubCommands()).hasSize(0); + assertThat(c1.getSubCommands()).isEmpty(); assertThat(c1.getOptions()).hasSize(1); assertThat(c1.getOptions()).satisfiesExactly( - o -> { - assertThat(o.option()).isEqualTo("--param1"); - } + o -> assertThat(o.option()).isEqualTo("--param1") ); }, c2 -> { assertThat(c2.getMainCommand()).isEqualTo("test2"); - assertThat(c2.getSubCommands()).hasSize(0); - assertThat(c2.getOptions()).hasSize(0); + assertThat(c2.getSubCommands()).isEmpty(); + assertThat(c2.getOptions()).isEmpty(); }, c3 -> { assertThat(c3.getMainCommand()).isEqualTo("test3"); - assertThat(c3.getOptions()).hasSize(0); + assertThat(c3.getOptions()).isEmpty(); assertThat(c3.getSubCommands()).hasSize(1); assertThat(c3.getCommands()).hasSize(1); assertThat(c3.getCommands()).satisfiesExactly( @@ -239,9 +225,7 @@ public void testBasicModelGeneration() { assertThat(c34.getMainCommand()).isEqualTo("test4"); assertThat(c34.getOptions()).hasSize(1); assertThat(c34.getOptions()).satisfiesExactly( - o -> { - assertThat(o.option()).isEqualTo("--param4"); - } + o -> assertThat(o.option()).isEqualTo("--param4") ); } ); @@ -250,7 +234,7 @@ public void testBasicModelGeneration() { } @Test - public void testBuilder() { + void testBuilder() { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); CommandCatalog commandCatalog = CommandCatalog.of(); TestCompletions completions = new TestCompletions(resourceLoader, commandCatalog); diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/BashCompletionsTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/BashCompletionsTests.java index af374b092..22aff007c 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/BashCompletionsTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/BashCompletionsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,18 +28,18 @@ import static org.assertj.core.api.Assertions.assertThat; -public class BashCompletionsTests { +class BashCompletionsTests { AnnotationConfigApplicationContext context; @BeforeEach - public void setup() { + void setup() { context = new AnnotationConfigApplicationContext(); context.refresh(); } @AfterEach - public void clean() { + void clean() { if (context != null) { context.close(); } @@ -47,7 +47,7 @@ public void clean() { } @Test - public void testNoCommands() { + void testNoCommands() { CommandCatalog commandCatalog = CommandCatalog.of(); BashCompletions completions = new BashCompletions(context, commandCatalog); String bash = completions.generate("root-command"); @@ -55,28 +55,28 @@ public void testNoCommands() { } @Test - public void testCommandFromMethod() { + void testCommandFromMethod() { CommandCatalog commandCatalog = CommandCatalog.of(); registerFromMethod(commandCatalog); BashCompletions completions = new BashCompletions(context, commandCatalog); String bash = completions.generate("root-command"); System.out.println(bash); - assertThat(bash).contains("root-command"); - assertThat(bash).contains("commands+=(\"testmethod1\")"); - assertThat(bash).contains("_root-command_testmethod1()"); - assertThat(bash).contains("two_word_flags+=(\"--arg1\")"); + assertThat(bash).contains("root-command") + .contains("commands+=(\"testmethod1\")") + .contains("_root-command_testmethod1()") + .contains("two_word_flags+=(\"--arg1\")"); } @Test - public void testCommandFromFunction() { + void testCommandFromFunction() { CommandCatalog commandCatalog = CommandCatalog.of(); registerFromFunction(commandCatalog, "testmethod1"); BashCompletions completions = new BashCompletions(context, commandCatalog); String bash = completions.generate("root-command"); - assertThat(bash).contains("root-command"); - assertThat(bash).contains("commands+=(\"testmethod1\")"); - assertThat(bash).contains("_root-command_testmethod1()"); - assertThat(bash).contains("two_word_flags+=(\"--arg1\")"); + assertThat(bash).contains("root-command") + .contains("commands+=(\"testmethod1\")") + .contains("_root-command_testmethod1()") + .contains("two_word_flags+=(\"--arg1\")"); } private void registerFromMethod(CommandCatalog commandCatalog) { diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/ZshCompletionsTests.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/ZshCompletionsTests.java index 21091f067..afaec62ba 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/ZshCompletionsTests.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/completion/ZshCompletionsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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,18 +28,18 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ZshCompletionsTests { +class ZshCompletionsTests { AnnotationConfigApplicationContext context; @BeforeEach - public void setup() { + void setup() { context = new AnnotationConfigApplicationContext(); context.refresh(); } @AfterEach - public void clean() { + void clean() { if (context != null) { context.close(); } @@ -47,7 +47,7 @@ public void clean() { } @Test - public void testNoCommands() { + void testNoCommands() { CommandCatalog commandCatalog = CommandCatalog.of(); ZshCompletions completions = new ZshCompletions(context, commandCatalog); String zsh = completions.generate("root-command"); @@ -55,27 +55,27 @@ public void testNoCommands() { } @Test - public void testCommandFromMethod() { + void testCommandFromMethod() { CommandCatalog commandCatalog = CommandCatalog.of(); registerFromMethod(commandCatalog); ZshCompletions completions = new ZshCompletions(context, commandCatalog); String zsh = completions.generate("root-command"); - assertThat(zsh).contains("root-command"); - assertThat(zsh).contains("testmethod1)"); - assertThat(zsh).contains("_root-command_testmethod1"); - assertThat(zsh).contains("--arg1"); + assertThat(zsh).contains("root-command") + .contains("testmethod1)") + .contains("_root-command_testmethod1") + .contains("--arg1"); } @Test - public void testCommandFromFunction() { + void testCommandFromFunction() { CommandCatalog commandCatalog = CommandCatalog.of(); registerFromFunction(commandCatalog, "testmethod1"); ZshCompletions completions = new ZshCompletions(context, commandCatalog); String zsh = completions.generate("root-command"); - assertThat(zsh).contains("root-command"); - assertThat(zsh).contains("testmethod1)"); - assertThat(zsh).contains("_root-command_testmethod1"); - assertThat(zsh).contains("--arg1"); + assertThat(zsh).contains("root-command") + .contains("testmethod1)") + .contains("_root-command_testmethod1") + .contains("--arg1"); } private void registerFromMethod(CommandCatalog commandCatalog) { diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/test1/GroupOneCommands.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/test1/GroupOneCommands.java index 4aada0256..8c2770375 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/test1/GroupOneCommands.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/test1/GroupOneCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-present 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. diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupThreeCommands.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupThreeCommands.java index 68d634cc4..f6fae51ab 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupThreeCommands.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupThreeCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-present 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. diff --git a/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupTwoCommands.java b/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupTwoCommands.java index 009f4c05c..74127b6bb 100644 --- a/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupTwoCommands.java +++ b/spring-shell-standard/src/test/java/org/springframework/shell/standard/test2/GroupTwoCommands.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-present 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. diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/AbstractTestWithSample.java b/spring-shell-table/src/test/java/org/springframework/shell/table/AbstractTestWithSample.java index 6592b9c1e..6f757e3dc 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/AbstractTestWithSample.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/AbstractTestWithSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; @@ -32,12 +33,12 @@ * * @author Eric Bottard */ -public class AbstractTestWithSample { +class AbstractTestWithSample { private String testName; @BeforeEach - public void setup(TestInfo testInfo) { + void setup(TestInfo testInfo) { testName = testInfo.getDisplayName().replace("()", ""); } @@ -46,7 +47,7 @@ protected String sample() throws IOException { this.getClass().getSimpleName(), testName); InputStream stream = TableTest.class.getResourceAsStream(sampleName); Assert.notNull(stream, "Can't find expected rendering result at " + sampleName); - return FileCopyUtils.copyToString(new InputStreamReader(stream, "UTF-8")).replace("&", ""); + return FileCopyUtils.copyToString(new InputStreamReader(stream, StandardCharsets.UTF_8)).replace("&", ""); } /** diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/ArrayTableModelTest.java b/spring-shell-table/src/test/java/org/springframework/shell/table/ArrayTableModelTest.java index f4cd976e0..0a9c151bc 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/ArrayTableModelTest.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/ArrayTableModelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,10 +26,10 @@ * * @author Eric Bottard */ -public class ArrayTableModelTest { +class ArrayTableModelTest { @Test - public void testValid() { + void testValid() { TableModel model = new ArrayTableModel(new String[][] {{"a", "b"}, {"c", "d"}}); assertThat(model.getColumnCount()).isEqualTo(2); assertThat(model.getRowCount()).isEqualTo(2); @@ -37,16 +37,15 @@ public void testValid() { } @Test - public void testEmpty() { + void testEmpty() { TableModel model = new ArrayTableModel(new String[][] {}); - assertThat(model.getColumnCount()).isEqualTo(0); - assertThat(model.getRowCount()).isEqualTo(0); + assertThat(model.getColumnCount()).isZero(); + assertThat(model.getRowCount()).isZero(); } @Test - public void testInvalidDimensions() { - assertThatThrownBy(() -> { - new ArrayTableModel(new String[][] {{"a", "b"}, {"c", "d", "e"}}); - }).isInstanceOf(IllegalArgumentException.class); + void testInvalidDimensions() { + assertThatThrownBy(() -> new ArrayTableModel(new String[][] {{"a", "b"}, {"c", "d", "e"}})) + .isInstanceOf(IllegalArgumentException.class); } } diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/BeanListTableModelTest.java b/spring-shell-table/src/test/java/org/springframework/shell/table/BeanListTableModelTest.java index 6cc979312..808675278 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/BeanListTableModelTest.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/BeanListTableModelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,50 +25,49 @@ import static org.assertj.core.api.Assertions.assertThat; - /** * Test for BeanListTableModel. * * @author Eric Bottard */ -public class BeanListTableModelTest extends AbstractTestWithSample { +class BeanListTableModelTest extends AbstractTestWithSample { @Test - public void testSimpleConstructor() throws IOException { + void testSimpleConstructor() throws IOException { List data = data(); - Table table = new TableBuilder(new BeanListTableModel(Person.class, data)).build(); + Table table = new TableBuilder(new BeanListTableModel<>(Person.class, data)).build(); String result = table.render(80); assertThat(result).isEqualTo(sample()); } @Test - public void testExplicitPropertyNames() throws IOException { + void testExplicitPropertyNames() throws IOException { List data = data(); - Table table = new TableBuilder(new BeanListTableModel(data, "lastName", "firstName")).build(); + Table table = new TableBuilder(new BeanListTableModel<>(data, "lastName", "firstName")).build(); String result = table.render(80); assertThat(result).isEqualTo(sample()); } @Test - public void testHeaderRow() throws IOException { + void testHeaderRow() throws IOException { List data = data(); - LinkedHashMap header = new LinkedHashMap(); + LinkedHashMap header = new LinkedHashMap<>(); header.put("lastName", "Last Name"); header.put("firstName", "First Name"); - Table table = new TableBuilder(new BeanListTableModel(data, header)).build(); + Table table = new TableBuilder(new BeanListTableModel<>(data, header)).build(); String result = table.render(80); assertThat(result).isEqualTo(sample()); } private List data() { - List data = new ArrayList(); + List data = new ArrayList<>(); data.add(new Person("Alice", "Clark", 12)); data.add(new Person("Bob", "Smith", 42)); data.add(new Person("Sarah", "Connor", 38)); diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/BorderFactoryTest.java b/spring-shell-table/src/test/java/org/springframework/shell/table/BorderFactoryTest.java index b80aa674b..360b3bb86 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/BorderFactoryTest.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/BorderFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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. @@ -23,16 +23,15 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.shell.table.BorderStyle.fancy_double; - /** * Tests for convenience borders factory. * * @author Eric Bottard */ -public class BorderFactoryTest extends AbstractTestWithSample { +class BorderFactoryTest extends AbstractTestWithSample { @Test - public void testOutlineBorder() throws IOException { + void testOutlineBorder() throws IOException { TableModel model = generate(3, 3); Table table = new TableBuilder(model).addOutlineBorder(fancy_double).build(); String result = table.render(80); @@ -40,7 +39,7 @@ public void testOutlineBorder() throws IOException { } @Test - public void testFullBorder() throws IOException { + void testFullBorder() throws IOException { TableModel model = generate(3, 3); Table table = new TableBuilder(model).addFullBorder(fancy_double).build(); String result = table.render(80); @@ -48,7 +47,7 @@ public void testFullBorder() throws IOException { } @Test - public void testHeaderBorder() throws IOException { + void testHeaderBorder() throws IOException { TableModel model = generate(3, 3); Table table = new TableBuilder(model).addHeaderBorder(fancy_double).build(); String result = table.render(80); @@ -56,7 +55,7 @@ public void testHeaderBorder() throws IOException { } @Test - public void testHeaderAndVerticalsBorder() throws IOException { + void testHeaderAndVerticalsBorder() throws IOException { TableModel model = generate(3, 3); Table table = new TableBuilder(model).addHeaderAndVerticalsBorders(fancy_double).build(); String result = table.render(80); diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/BorderStyleTests.java b/spring-shell-table/src/test/java/org/springframework/shell/table/BorderStyleTests.java index cc93e48b6..2e5e8299c 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/BorderStyleTests.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/BorderStyleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,46 +22,45 @@ import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for BorderStyle rendering and combinations. * * @author Eric Bottard */ -public class BorderStyleTests extends AbstractTestWithSample { +class BorderStyleTests extends AbstractTestWithSample { @Test - public void testOldSchool() throws IOException { + void testOldSchool() throws IOException { Table table = new TableBuilder(generate(2, 2)).addFullBorder(BorderStyle.oldschool).build(); assertThat(table.render(10)).isEqualTo(sample()); } @Test - public void testFancySimple() throws IOException { + void testFancySimple() throws IOException { Table table = new TableBuilder(generate(2, 2)).addFullBorder(BorderStyle.fancy_light).build(); assertThat(table.render(10)).isEqualTo(sample()); } @Test - public void testFancyHeavy() throws IOException { + void testFancyHeavy() throws IOException { Table table = new TableBuilder(generate(2, 2)).addFullBorder(BorderStyle.fancy_heavy).build(); assertThat(table.render(10)).isEqualTo(sample()); } @Test - public void testFancyDouble() throws IOException { + void testFancyDouble() throws IOException { Table table = new TableBuilder(generate(2, 2)).addFullBorder(BorderStyle.fancy_double).build(); assertThat(table.render(10)).isEqualTo(sample()); } @Test - public void testAir() throws IOException { + void testAir() throws IOException { Table table = new TableBuilder(generate(2, 2)).addFullBorder(BorderStyle.air).build(); assertThat(table.render(10)).isEqualTo(sample()); } @Test - public void testMixedOldSchoolWithAir() throws IOException { + void testMixedOldSchoolWithAir() throws IOException { Table table = new TableBuilder(generate(2, 2)) .addFullBorder(BorderStyle.air) .addOutlineBorder(BorderStyle.oldschool) @@ -70,7 +69,7 @@ public void testMixedOldSchoolWithAir() throws IOException { } @Test - public void testMixedFancyLightAndHeavy() throws IOException { + void testMixedFancyLightAndHeavy() throws IOException { Table table = new TableBuilder(generate(2, 2)) .addFullBorder(BorderStyle.fancy_heavy) .addOutlineBorder(BorderStyle.fancy_light) @@ -79,7 +78,7 @@ public void testMixedFancyLightAndHeavy() throws IOException { } @Test - public void testMixedFancyHeavyAndLight() throws IOException { + void testMixedFancyHeavyAndLight() throws IOException { Table table = new TableBuilder(generate(2, 2)) .addFullBorder(BorderStyle.fancy_light) .addOutlineBorder(BorderStyle.fancy_heavy) @@ -88,7 +87,7 @@ public void testMixedFancyHeavyAndLight() throws IOException { } @Test - public void testMixedDoubleAndSingle() throws IOException { + void testMixedDoubleAndSingle() throws IOException { Table table = new TableBuilder(generate(2, 2)) .addFullBorder(BorderStyle.fancy_light) .addOutlineBorder(BorderStyle.fancy_double) @@ -97,7 +96,7 @@ public void testMixedDoubleAndSingle() throws IOException { } @Test - public void testMixedSingleAndDouble() throws IOException { + void testMixedSingleAndDouble() throws IOException { Table table = new TableBuilder(generate(2, 2)) .addFullBorder(BorderStyle.fancy_double) .addOutlineBorder(BorderStyle.fancy_light) @@ -106,7 +105,7 @@ public void testMixedSingleAndDouble() throws IOException { } @Test - public void testMixedLightInternalAndHeavy() throws IOException { + void testMixedLightInternalAndHeavy() throws IOException { Table table = new TableBuilder(generate(3, 3)) .addFullBorder(BorderStyle.fancy_heavy) .paintBorder(BorderStyle.fancy_light, BorderSpecification.OUTLINE).fromRowColumn(1, 1).toRowColumn(2, 2) @@ -115,7 +114,7 @@ public void testMixedLightInternalAndHeavy() throws IOException { } @Test - public void testMixedHeavyInternalAndLight() throws IOException { + void testMixedHeavyInternalAndLight() throws IOException { Table table = new TableBuilder(generate(3, 3)) .addFullBorder(BorderStyle.fancy_light) .paintBorder(BorderStyle.fancy_heavy, BorderSpecification.OUTLINE).fromRowColumn(1, 1).toRowColumn(2, 2) @@ -124,7 +123,7 @@ public void testMixedHeavyInternalAndLight() throws IOException { } @Test - public void testHeavyOutlineAndHeader_LightVerticals_AirHorizontals() throws IOException { + void testHeavyOutlineAndHeader_LightVerticals_AirHorizontals() throws IOException { Table table = new TableBuilder(generate(4, 4)) .addOutlineBorder(BorderStyle.fancy_heavy) .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/DelimiterTextWrapperTest.java b/spring-shell-table/src/test/java/org/springframework/shell/table/DelimiterTextWrapperTest.java index e0cf049b8..4e170ec7f 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/DelimiterTextWrapperTest.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/DelimiterTextWrapperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,19 +25,19 @@ * * @author Eric Bottard */ -public class DelimiterTextWrapperTest { +class DelimiterTextWrapperTest { - private TextWrapper wrapper = new DelimiterTextWrapper(); + private final TextWrapper wrapper = new DelimiterTextWrapper(); @Test - public void testNoWordSplit() { + void testNoWordSplit() { String[] text = new String[] {"the quick brown fox jumps over the lazy dog."}; assertThat(wrapper.wrap(text, 10)).containsExactly("the quick ", "brown fox ", "jumps over", "the lazy ", "dog. "); } @Test - public void testWordSplit() { + void testWordSplit() { String[] text = new String[] {"the quick brown fox jumps over the lazy dog."}; assertThat(wrapper.wrap(text, 4)).containsExactly("the ", "quic", "k ", "brow", "n ", "fox ", "jump", "s ", "over", "the ", "lazy", "dog."); diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/KeyValueRenderingTests.java b/spring-shell-table/src/test/java/org/springframework/shell/table/KeyValueRenderingTests.java index 0a8ec2405..beb8c86b2 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/KeyValueRenderingTests.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/KeyValueRenderingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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. @@ -29,11 +29,11 @@ * * @author Eric Bottard */ -public class KeyValueRenderingTests extends AbstractTestWithSample { +class KeyValueRenderingTests extends AbstractTestWithSample { @Test - public void testRenderConstrained() throws IOException { - Map values = new LinkedHashMap(); + void testRenderConstrained() throws IOException { + Map values = new LinkedHashMap<>(); values.put("a", "b"); values.put("long-key", "c"); values.put("d", "long-value"); @@ -47,8 +47,8 @@ public void testRenderConstrained() throws IOException { } @Test - public void testRenderUnconstrained() throws IOException { - Map values = new LinkedHashMap(); + void testRenderUnconstrained() throws IOException { + Map values = new LinkedHashMap<>(); values.put("a", "b"); values.put("long-key", "c"); values.put("d", "long-value"); diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelBuilderTests.java b/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelBuilderTests.java index 3dbae0648..89bafddd8 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelBuilderTests.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,20 +26,20 @@ * * @author Eric Bottard */ -public class TableModelBuilderTests { +class TableModelBuilderTests { @Test - public void emptyModel() { - TableModelBuilder builder = new TableModelBuilder(); + void emptyModel() { + TableModelBuilder builder = new TableModelBuilder<>(); TableModel model = builder.build(); - assertThat(model.getColumnCount()).isEqualTo(0); - assertThat(model.getColumnCount()).isEqualTo(0); + assertThat(model.getColumnCount()).isZero(); + assertThat(model.getColumnCount()).isZero(); } @Test - public void testFrozen() { + void testFrozen() { assertThatThrownBy(() -> { - TableModelBuilder builder = new TableModelBuilder(); + TableModelBuilder builder = new TableModelBuilder<>(); builder.addRow().addValue(5); builder.build(); builder.addRow(); @@ -47,9 +47,9 @@ public void testFrozen() { } @Test - public void testAddingTooManyValues() { + void testAddingTooManyValues() { assertThatThrownBy(() -> { - TableModelBuilder builder = new TableModelBuilder(); + TableModelBuilder builder = new TableModelBuilder<>(); builder.addRow().addValue(5); builder.addRow().addValue(1).addValue(2); builder.build(); @@ -57,9 +57,9 @@ public void testAddingTooManyValues() { } @Test - public void testAddingLessValues() { + void testAddingLessValues() { assertThatThrownBy(() -> { - TableModelBuilder builder = new TableModelBuilder(); + TableModelBuilder builder = new TableModelBuilder<>(); builder.addRow().addValue(1).addValue(2); builder.addRow().addValue(5); builder.addRow(); @@ -68,8 +68,8 @@ public void testAddingLessValues() { } @Test - public void simpleBuild() { - TableModelBuilder builder = new TableModelBuilder(); + void simpleBuild() { + TableModelBuilder builder = new TableModelBuilder<>(); builder .addRow() .addValue(7).addValue(2) diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelTest.java b/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelTest.java index db3cf918f..3ea4e0573 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelTest.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/TableModelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,10 +25,10 @@ * * @author Eric Bottard */ -public class TableModelTest { +class TableModelTest { @Test - public void testTranspose() { + void testTranspose() { TableModel model = new ArrayTableModel(new String[][] {{"a", "b", "c"}, {"d", "e", "f"}}); assertThat(model.transpose().getColumnCount()).isEqualTo(2); diff --git a/spring-shell-table/src/test/java/org/springframework/shell/table/TableTest.java b/spring-shell-table/src/test/java/org/springframework/shell/table/TableTest.java index e39816687..73aeec7bf 100644 --- a/spring-shell-table/src/test/java/org/springframework/shell/table/TableTest.java +++ b/spring-shell-table/src/test/java/org/springframework/shell/table/TableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-present 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,24 +24,23 @@ import java.io.IOException; - /** * Tests for Table rendering. * * @author Eric Bottard */ -public class TableTest extends AbstractTestWithSample { +class TableTest extends AbstractTestWithSample { @Test - public void testEmptyModel() { + void testEmptyModel() { TableModel model = new ArrayTableModel(new Object[0][0]); Table table = new TableBuilder(model).build(); String result = table.render(80); - assertThat(result).isEqualTo(""); + assertThat(result).isEmpty(); } @Test - public void testPreformattedModel() { + void testPreformattedModel() { TableModel model = generate(2, 2); Table table = new TableBuilder(model).build(); String result = table.render(80); @@ -49,7 +48,7 @@ public void testPreformattedModel() { } @Test - public void testExpandingColumns() throws IOException { + void testExpandingColumns() throws IOException { TableModel model = new ArrayTableModel(new String[][] {{"a", "b"}, {"ccc", "d"}}); Table table = new TableBuilder(model).build(); String result = table.render(80); @@ -57,7 +56,7 @@ public void testExpandingColumns() throws IOException { } @Test - public void testRightAlignment() throws IOException { + void testRightAlignment() throws IOException { TableModel model = new ArrayTableModel(new String[][] {{"a\na\na", "bbb"}, {"ccc", "d"}}); Table table = new TableBuilder(model).on(CellMatchers.column(1)).addAligner(right).build(); String result = table.render(80); @@ -65,7 +64,7 @@ public void testRightAlignment() throws IOException { } @Test - public void testVerticalAlignment() throws IOException { + void testVerticalAlignment() throws IOException { TableModel model = new ArrayTableModel(new String[][] {{"a\na\na", "bbb"}, {"ccc", "d"}}); Table table = new TableBuilder(model).on(CellMatchers.row(0)).addAligner(middle).build(); String result = table.render(80); @@ -73,7 +72,7 @@ public void testVerticalAlignment() throws IOException { } @Test - public void testAutoWrapping() throws IOException { + void testAutoWrapping() throws IOException { TableModel model = new ArrayTableModel(new String[][] {{"this is a long line", "bbb"}, {"ccc", "d"}}); Table table = new TableBuilder(model).build(); String result = table.render(10); @@ -81,7 +80,7 @@ public void testAutoWrapping() throws IOException { } @Test - public void testOverflow() throws IOException { + void testOverflow() throws IOException { TableModel model = new ArrayTableModel(new String[][] {{"this is a long line", "bbb"}, {"ccc", "d"}}); Table table = new TableBuilder(model).build(); String result = table.render(3); @@ -89,7 +88,7 @@ public void testOverflow() throws IOException { } @Test - public void testEmptyCellsVerticalAligner() throws IOException { + void testEmptyCellsVerticalAligner() { TableModel model = new ArrayTableModel(new String[][] {{"a", "b"}, {null, null}}); Table table = new TableBuilder(model).on(CellMatchers.table()).addAligner(SimpleVerticalAligner.middle).build(); table.render(3); diff --git a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestIntegrationTests.java b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestIntegrationTests.java index d17aa5026..d308e242c 100644 --- a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestIntegrationTests.java +++ b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,23 +37,19 @@ @ContextConfiguration(classes = ExampleShellApplication.class) @ShellTest @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) -public class ShellTestIntegrationTests { +class ShellTestIntegrationTests { @Autowired ShellTestClient client; @Test - void testInteractive1() throws Exception { + void testInteractive1() { InteractiveShellSession session = client.interactive().run(); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - ShellAssertions.assertThat(session.screen()).containsText("shell"); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> ShellAssertions.assertThat(session.screen()).containsText("shell")); session.write(session.writeSequence().text("help").carriageReturn().build()); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - ShellAssertions.assertThat(session.screen()).containsText("AVAILABLE COMMANDS"); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> ShellAssertions.assertThat(session.screen()).containsText("AVAILABLE COMMANDS")); session.write(session.writeSequence().carriageReturn().build()); await().atMost(4, TimeUnit.SECONDS).untilAsserted(() -> { @@ -70,34 +66,28 @@ void testInteractive1() throws Exception { }); session.write(session.writeSequence().ctrl('c').build()); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(session.isComplete()).isTrue(); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(session.isComplete()).isTrue()); } @Test - void testInteractive2() throws Exception { + void testInteractive2() { InteractiveShellSession session = client.interactive().run(); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - ShellAssertions.assertThat(session.screen()).containsText("shell:"); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> ShellAssertions.assertThat(session.screen()).containsText("shell:")); session.write(session.writeSequence().ctrl('c').build()); - await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(session.isComplete()).isTrue(); - }); + await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> assertThat(session.isComplete()).isTrue()); } @Test - void testNonInteractive() throws Exception { + void testNonInteractive() { Condition helpCondition = new Condition<>(line -> line.contains("AVAILABLE COMMANDS"), "Help has expected output"); Condition helpHelpCondition = new Condition<>(line -> line.contains("help - Display help about available commands"), "Help help has expected output"); - Condition emptyCondition = new Condition<>(line -> line.trim().length() == 0, + Condition emptyCondition = new Condition<>(line -> line.trim().isEmpty(), "Have only whitespace"); NonInteractiveShellSession session = client.nonInterative("help").run(); @@ -123,13 +113,11 @@ void testNonInteractive() throws Exception { }); session.write(session.writeSequence().ctrl('c').build()); - await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(session.isComplete()).isTrue(); - }); + await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(session.isComplete()).isTrue()); } @Test - void testNonInteractive2() throws Exception { + void testNonInteractive2() { Condition helloCondition = new Condition<>(line -> line.contains("hello"), "Hello has expected output"); diff --git a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestPropertiesIntegrationTests.java b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestPropertiesIntegrationTests.java index daece6446..e6850c632 100644 --- a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestPropertiesIntegrationTests.java +++ b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-present 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,7 +34,7 @@ @ShellTest(properties = { "spring.profiles.active=test", "spring.shell.test.terminal-width=81", "spring.shell.test.terminal-height=25" }) @ContextConfiguration(classes = ExampleShellApplication.class) -public class ShellTestPropertiesIntegrationTests { +class ShellTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestTerminalDimensionsIntegrationTests.java b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestTerminalDimensionsIntegrationTests.java index 8c19a7627..be4b71c64 100644 --- a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestTerminalDimensionsIntegrationTests.java +++ b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestTerminalDimensionsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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. diff --git a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/SpringShellTestPropertiesTests.java b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/SpringShellTestPropertiesTests.java index ee1137281..d08f8d0de 100644 --- a/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/SpringShellTestPropertiesTests.java +++ b/spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/SpringShellTestPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-present 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 @@ class SpringShellTestPropertiesTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); @Test - public void defaultNoPropertiesSet() { + void defaultNoPropertiesSet() { this.contextRunner .withUserConfiguration(Config1.class) - .run((context) -> { + .run(context -> { SpringShellTestProperties properties = context.getBean(SpringShellTestProperties.class); assertThat(properties.getTerminalWidth()).isEqualTo(80); assertThat(properties.getTerminalHeight()).isEqualTo(24); @@ -38,12 +38,12 @@ public void defaultNoPropertiesSet() { } @Test - public void setProperties() { + void setProperties() { this.contextRunner .withPropertyValues("spring.shell.test.terminal-width=81") .withPropertyValues("spring.shell.test.terminal-height=25") .withUserConfiguration(Config1.class) - .run((context) -> { + .run(context -> { SpringShellTestProperties properties = context.getBean(SpringShellTestProperties.class); assertThat(properties.getTerminalWidth()).isEqualTo(81); assertThat(properties.getTerminalHeight()).isEqualTo(25); diff --git a/spring-shell-test/src/test/java/org/springframework/shell/test/ShellClientTests.java b/spring-shell-test/src/test/java/org/springframework/shell/test/ShellClientTests.java index ab992de63..0b13f94ce 100644 --- a/spring-shell-test/src/test/java/org/springframework/shell/test/ShellClientTests.java +++ b/spring-shell-test/src/test/java/org/springframework/shell/test/ShellClientTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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. diff --git a/spring-shell-test/src/test/java/org/springframework/shell/test/ShellScreenAssertTests.java b/spring-shell-test/src/test/java/org/springframework/shell/test/ShellScreenAssertTests.java index 6bd2541a0..1c0fef5b8 100644 --- a/spring-shell-test/src/test/java/org/springframework/shell/test/ShellScreenAssertTests.java +++ b/spring-shell-test/src/test/java/org/springframework/shell/test/ShellScreenAssertTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-present 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,9 +24,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -public class ShellScreenAssertTests { +class ShellScreenAssertTests { - List LINES1 = Arrays.asList("line1", "line2"); + public static final List LINES1 = Arrays.asList("line1", "line2"); @Test void assertContainsTextShouldContain() {