Refactor Spring-boot-test examples (#1328)

* Refactor Spring-boot-test examples

* Refactor Spring-boot-test examples
This commit is contained in:
Grzegorz Piwowarek
2017-03-07 19:21:40 +01:00
committed by GitHub
parent 656afd6ff5
commit 250cb7c164
3 changed files with 24 additions and 77 deletions
@@ -1,13 +1,5 @@
package org.baeldung.boot;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
import java.util.HashMap;
import java.util.Map;
import org.baeldung.boot.components.FooComponent;
import org.baeldung.boot.model.Foo;
import org.junit.Before;
@@ -22,8 +14,18 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@SpringBootTest(
classes = DemoApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT)
public class FooComponentTests {
@Autowired
@@ -33,7 +35,7 @@ public class FooComponentTests {
private FooComponent fooComponent;
@Before
public void init() {
public void init() throws Exception {
Foo foo = new Foo();
foo.setId(5);
foo.setName("MOCKED_FOO");
@@ -45,7 +47,7 @@ public class FooComponentTests {
@Test
public void givenInquiryingFooWithId_whenFooComponentIsMocked_thenAssertMockedResult() {
Map<String, String> pathVariables = new HashMap<String, String>();
Map<String, String> pathVariables = new HashMap<>();
pathVariables.put("id", "1");
ResponseEntity<Foo> fooResponse = testRestTemplate.getForEntity("/{id}", Foo.class, pathVariables);
@@ -57,7 +59,7 @@ public class FooComponentTests {
@Test
public void givenInquiryingFooWithName_whenFooComponentIsMocked_thenAssertMockedResult() {
Map<String, String> pathVariables = new HashMap<String, String>();
Map<String, String> pathVariables = new HashMap<>();
pathVariables.put("name", "Foo_Name");
ResponseEntity<Foo> fooResponse = testRestTemplate.getForEntity("/?name={name}", Foo.class, pathVariables);