Update boot 2.6.1

- Migrate tests to junit5 and assertj as those
  are on a classpath automatically.
- Temporarily use spring.main.allow-circular-references=true
  to allow time for fixes to remove cycles.
This commit is contained in:
Janne Valkealahti
2021-12-11 12:57:34 +00:00
parent 592f9e9f99
commit e30edf2446
14 changed files with 269 additions and 281 deletions

View File

@@ -16,13 +16,10 @@
package org.springframework.shell;
import static org.hamcrest.collection.IsMapContaining.hasEntry;
import static org.hamcrest.collection.IsMapContaining.hasKey;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Unit tests for {@link ConfigurableCommandRegistry}.
@@ -31,15 +28,11 @@ import org.junit.rules.ExpectedException;
*/
public class ConfigurableCommandRegistryTest {
@Rule
public ExpectedException thrown= ExpectedException.none();
@Test
public void testRegistration() {
ConfigurableCommandRegistry registry = new ConfigurableCommandRegistry();
registry.register("foo", MethodTarget.of("toString", this, new Command.Help("some command")));
assertThat(registry.listCommands(), hasKey("foo"));
assertThat(registry.listCommands()).containsKeys("foo");
}
@Test
@@ -47,12 +40,11 @@ public class ConfigurableCommandRegistryTest {
ConfigurableCommandRegistry registry = new ConfigurableCommandRegistry();
registry.register("foo", MethodTarget.of("toString", this, new Command.Help("some command")));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("foo");
thrown.expectMessage("toString");
thrown.expectMessage("hashCode");
registry.register("foo", MethodTarget.of("hashCode", this, new Command.Help("some command")));
assertThatThrownBy(() -> {
registry.register("foo", MethodTarget.of("hashCode", this, new Command.Help("some command")));
}).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("foo")
.hasMessageContaining("toString")
.hasMessageContaining("hashCode");
}
}

View File

@@ -22,21 +22,20 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.isA;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,13 +45,12 @@ import static org.mockito.Mockito.when;
*
* @author Eric Bottard
*/
@ExtendWith(MockitoExtension.class)
// @RunWith(JUnitPlatform.class)
public class ShellTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Rule
public ExpectedException thrown= ExpectedException.none();
// @Rule
// public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
private InputProvider inputProvider;
@@ -62,7 +60,7 @@ public class ShellTest {
@Mock
private ParameterResolver parameterResolver;
private ValueResult valueResult;
@InjectMocks
@@ -70,7 +68,7 @@ public class ShellTest {
private boolean invoked;
@Before
@BeforeEach
public void setUp() {
shell.parameterResolvers = Arrays.asList(parameterResolver);
}
@@ -93,7 +91,7 @@ public class ShellTest {
}
Assert.assertTrue(invoked);
assertThat(invoked).isTrue();
}
@Test
@@ -147,12 +145,11 @@ public class ShellTest {
}
Assert.assertTrue(invoked);
assertThat(invoked).isTrue();
}
@Test
public void commandThrowingAnException() throws IOException {
when(parameterResolver.supports(any())).thenReturn(true);
when(inputProvider.readInput()).thenReturn(() -> "fail", null);
doThrow(new Exit()).when(resultHandler).handleResult(isA(SomeException.class));
@@ -166,17 +163,14 @@ public class ShellTest {
}
Assert.assertTrue(invoked);
assertThat(invoked).isTrue();
}
@Test
public void comments() throws IOException {
when(parameterResolver.supports(any())).thenReturn(true);
when(inputProvider.readInput()).thenReturn(() -> "// This is a comment", (Input) null);
shell.run(inputProvider);
}
@Test
@@ -188,8 +182,9 @@ public class ShellTest {
r.register("hw", MethodTarget.of("helloWorld", this, new Command.Help("hellow world")));
}));
thrown.expect(ParameterResolverMissingException.class);
shell.gatherMethodTargets();
assertThatThrownBy(() -> {
shell.gatherMethodTargets();
}).isInstanceOf(ParameterResolverMissingException.class);
}
@Test

View File

@@ -16,9 +16,9 @@
package org.springframework.shell;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link Utils}.