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:
@@ -1,23 +1,23 @@
|
||||
package com.example.test.functional;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.util.ReflectionUtils.findMethod;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import com.example.CalculatorCommands;
|
||||
import com.example.CalculatorState;
|
||||
import com.example.test.BaseCalculatorTest;
|
||||
import com.example.test.TestCalculatorStateConfig;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.shell.ConfigurableCommandRegistry;
|
||||
import org.springframework.shell.MethodTarget;
|
||||
import org.springframework.shell.standard.StandardMethodTargetRegistrar;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import com.example.CalculatorCommands;
|
||||
import com.example.CalculatorState;
|
||||
import com.example.test.BaseCalculatorTest;
|
||||
import com.example.test.TestCalculatorStateConfig;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.util.ReflectionUtils.findMethod;
|
||||
|
||||
/**
|
||||
* Illustrative functional tests for the Spring Shell Calculator application. These
|
||||
@@ -26,7 +26,7 @@ import com.example.test.TestCalculatorStateConfig;
|
||||
*
|
||||
* @author Sualeh Fatehi
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { TestCalculatorStateConfig.class, CalculatorCommands.class })
|
||||
public class CalculatorCommandsTest extends BaseCalculatorTest {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CalculatorCommandsTest extends BaseCalculatorTest {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
final StandardMethodTargetRegistrar registrar = new StandardMethodTargetRegistrar();
|
||||
registrar.setApplicationContext(context);
|
||||
@@ -55,14 +55,15 @@ public class CalculatorCommandsTest extends BaseCalculatorTest {
|
||||
final String commandMethod = "add";
|
||||
|
||||
final MethodTarget commandTarget = lookupCommand(registry, command);
|
||||
assertThat(commandTarget, notNullValue());
|
||||
assertThat(commandTarget.getGroup(), is("Calculator Commands"));
|
||||
assertThat(commandTarget.getHelp(), is("Add two integers"));
|
||||
assertThat(commandTarget.getMethod(),
|
||||
is(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class, int.class)));
|
||||
assertThat(commandTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(invoke(commandTarget, 1, 2), is(3));
|
||||
assertThat(state.getMemory(), is(0));
|
||||
assertThat(commandTarget).isNotNull();
|
||||
assertThat(commandTarget.getGroup()).isEqualTo("Calculator Commands");
|
||||
assertThat(commandTarget.getHelp()).isEqualTo("Add two integers");
|
||||
assertThat(commandTarget.getMethod())
|
||||
.isEqualTo(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class, int.class));
|
||||
assertThat(commandTarget.getAvailability().isAvailable()).isTrue();
|
||||
Object invoke = invoke(commandTarget, 1, 2);
|
||||
assertThat(invoke).isEqualTo(3);
|
||||
assertThat(state.getMemory()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,16 +72,16 @@ public class CalculatorCommandsTest extends BaseCalculatorTest {
|
||||
final String commandMethod = "addToMemory";
|
||||
|
||||
final MethodTarget commandTarget = lookupCommand(registry, command);
|
||||
assertThat(commandTarget, notNullValue());
|
||||
assertThat(commandTarget.getGroup(), is("Calculator Commands"));
|
||||
assertThat(commandTarget.getHelp(), is("Add an integer to the value in memory"));
|
||||
assertThat(commandTarget.getMethod(),
|
||||
is(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class)));
|
||||
assertThat(commandTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(commandTarget).isNotNull();
|
||||
assertThat(commandTarget.getGroup()).isEqualTo("Calculator Commands");
|
||||
assertThat(commandTarget.getHelp()).isEqualTo("Add an integer to the value in memory");
|
||||
assertThat(commandTarget.getMethod()).isEqualTo(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class));
|
||||
assertThat(commandTarget.getAvailability().isAvailable()).isTrue();
|
||||
|
||||
state.setMemory(1);
|
||||
assertThat(invoke(commandTarget, 2), is(3));
|
||||
assertThat(state.getMemory(), is(3));
|
||||
Object invoke = invoke(commandTarget, 2);
|
||||
assertThat(invoke).isEqualTo(3);
|
||||
assertThat(state.getMemory()).isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package com.example.test.integration;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.util.ReflectionUtils.findMethod;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import com.example.CalculatorCommands;
|
||||
import com.example.CalculatorState;
|
||||
import com.example.test.BaseCalculatorTest;
|
||||
import com.example.test.TestCalculatorStateConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.shell.MethodTarget;
|
||||
import org.springframework.shell.Shell;
|
||||
import org.springframework.shell.jline.InteractiveShellApplicationRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import com.example.CalculatorCommands;
|
||||
import com.example.CalculatorState;
|
||||
import com.example.test.BaseCalculatorTest;
|
||||
import com.example.test.TestCalculatorStateConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.util.ReflectionUtils.findMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -25,8 +23,8 @@ import com.example.test.TestCalculatorStateConfig;
|
||||
*
|
||||
* @author Sualeh Fatehi
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(properties = { InteractiveShellApplicationRunner.SPRING_SHELL_INTERACTIVE_ENABLED + "=" + false })
|
||||
@SpringBootTest(properties = { InteractiveShellApplicationRunner.SPRING_SHELL_INTERACTIVE_ENABLED + "=" + false,
|
||||
"spring.main.allow-circular-references=true" })
|
||||
@ContextConfiguration(classes = TestCalculatorStateConfig.class)
|
||||
public class CalculatorCommandsIntegrationTest extends BaseCalculatorTest {
|
||||
|
||||
@@ -48,14 +46,15 @@ public class CalculatorCommandsIntegrationTest extends BaseCalculatorTest {
|
||||
final String commandMethod = "add";
|
||||
|
||||
final MethodTarget commandTarget = lookupCommand(shell, command);
|
||||
assertThat(commandTarget, notNullValue());
|
||||
assertThat(commandTarget.getGroup(), is("Calculator Commands"));
|
||||
assertThat(commandTarget.getHelp(), is("Add two integers"));
|
||||
assertThat(commandTarget.getMethod(),
|
||||
is(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class, int.class)));
|
||||
assertThat(commandTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(shell.evaluate(() -> command + " 1 2"), is(3));
|
||||
assertThat(state.getMemory(), is(0));
|
||||
assertThat(commandTarget).isNotNull();
|
||||
assertThat(commandTarget.getGroup()).isEqualTo("Calculator Commands");
|
||||
assertThat(commandTarget.getHelp()).isEqualTo("Add two integers");
|
||||
assertThat(commandTarget.getMethod())
|
||||
.isEqualTo(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class, int.class));
|
||||
assertThat(commandTarget.getAvailability().isAvailable()).isTrue();
|
||||
Object evaluate = shell.evaluate(() -> command + " 1 2");
|
||||
assertThat(evaluate).isEqualTo(3);
|
||||
assertThat(state.getMemory()).isEqualTo(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,16 +68,16 @@ public class CalculatorCommandsIntegrationTest extends BaseCalculatorTest {
|
||||
final String commandMethod = "addToMemory";
|
||||
|
||||
final MethodTarget commandTarget = lookupCommand(shell, command);
|
||||
assertThat(commandTarget, notNullValue());
|
||||
assertThat(commandTarget.getGroup(), is("Calculator Commands"));
|
||||
assertThat(commandTarget.getHelp(), is("Add an integer to the value in memory"));
|
||||
assertThat(commandTarget.getMethod(),
|
||||
is(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class)));
|
||||
assertThat(commandTarget.getAvailability().isAvailable(), is(true));
|
||||
assertThat(commandTarget).isNotNull();
|
||||
assertThat(commandTarget.getGroup()).isEqualTo("Calculator Commands");
|
||||
assertThat(commandTarget.getHelp()).isEqualTo("Add an integer to the value in memory");
|
||||
assertThat(commandTarget.getMethod()).isEqualTo(findMethod(COMMAND_CLASS_UNDER_TEST, commandMethod, int.class));
|
||||
assertThat(commandTarget.getAvailability().isAvailable()).isTrue();
|
||||
|
||||
state.setMemory(1);
|
||||
assertThat(shell.evaluate(() -> command + " 2"), is(3));
|
||||
assertThat(state.getMemory(), is(3));
|
||||
Object evaluate = shell.evaluate(() -> command + " 2");
|
||||
assertThat(evaluate).isEqualTo(3);
|
||||
assertThat(state.getMemory()).isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.example.test.unit;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import com.example.CalculatorCommands;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -22,7 +22,7 @@ public class AddTest {
|
||||
* Setup test calculator commands as "plain-old Java objects" or POJOs, initialized for
|
||||
* each test.
|
||||
*/
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
commands = new CalculatorCommands();
|
||||
}
|
||||
@@ -32,9 +32,9 @@ public class AddTest {
|
||||
*/
|
||||
@Test
|
||||
public void addHappyPath() {
|
||||
assertThat(commands.add(0, 1), is(1));
|
||||
assertThat(commands.add(1, 2), is(3));
|
||||
assertThat(commands.add(1, 0), is(1));
|
||||
assertThat(commands.add(0, 1)).isEqualTo(1);
|
||||
assertThat(commands.add(1, 2)).isEqualTo(3);
|
||||
assertThat(commands.add(1, 0)).isEqualTo(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,9 +42,9 @@ public class AddTest {
|
||||
*/
|
||||
@Test
|
||||
public void addNegatives() {
|
||||
assertThat(commands.add(0, -1), is(-1));
|
||||
assertThat(commands.add(1, -2), is(-1));
|
||||
assertThat(commands.add(-1, 0), is(-1));
|
||||
assertThat(commands.add(0, -1)).isEqualTo(-1);
|
||||
assertThat(commands.add(1, -2)).isEqualTo(-1);
|
||||
assertThat(commands.add(-1, 0)).isEqualTo(-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.example.test.unit;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.example.CalculatorCommands;
|
||||
import com.example.CalculatorState;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.util.ReflectionUtils.findField;
|
||||
import static org.springframework.util.ReflectionUtils.makeAccessible;
|
||||
import static org.springframework.util.ReflectionUtils.setField;
|
||||
import java.lang.reflect.Field;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import com.example.CalculatorCommands;
|
||||
import com.example.CalculatorState;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -29,7 +30,7 @@ public class AddToMemoryTest {
|
||||
* Setup test calculator commands as "plain-old Java objects" or POJOs, initialized for
|
||||
* each test.
|
||||
*/
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
state = new CalculatorState();
|
||||
commands = new CalculatorCommands();
|
||||
@@ -44,14 +45,14 @@ public class AddToMemoryTest {
|
||||
*/
|
||||
@Test
|
||||
public void addToMemoryHappyPath() {
|
||||
assertThat(commands.addToMemory(1), is(1));
|
||||
assertThat(state.getMemory(), is(1));
|
||||
assertThat(commands.addToMemory(1)).isEqualTo(1);
|
||||
assertThat(state.getMemory()).isEqualTo(1);
|
||||
|
||||
assertThat(commands.addToMemory(2), is(3));
|
||||
assertThat(state.getMemory(), is(3));
|
||||
assertThat(commands.addToMemory(2)).isEqualTo(3);
|
||||
assertThat(state.getMemory()).isEqualTo(3);
|
||||
|
||||
assertThat(commands.addToMemory(0), is(3));
|
||||
assertThat(state.getMemory(), is(3));
|
||||
assertThat(commands.addToMemory(0)).isEqualTo(3);
|
||||
assertThat(state.getMemory()).isEqualTo(3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,14 +61,14 @@ public class AddToMemoryTest {
|
||||
*/
|
||||
@Test
|
||||
public void addToMemoryNegatives() {
|
||||
assertThat(commands.addToMemory(-1), is(-1));
|
||||
assertThat(state.getMemory(), is(-1));
|
||||
assertThat(commands.addToMemory(-1)).isEqualTo(-1);
|
||||
assertThat(state.getMemory()).isEqualTo(-1);
|
||||
|
||||
assertThat(commands.addToMemory(-2), is(-3));
|
||||
assertThat(state.getMemory(), is(-3));
|
||||
assertThat(commands.addToMemory(-2)).isEqualTo(-3);
|
||||
assertThat(state.getMemory()).isEqualTo(-3);
|
||||
|
||||
assertThat(commands.addToMemory(0), is(-3));
|
||||
assertThat(state.getMemory(), is(-3));
|
||||
assertThat(commands.addToMemory(0)).isEqualTo(-3);
|
||||
assertThat(state.getMemory()).isEqualTo(-3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user