Fixed conflicts
This commit is contained in:
-41
@@ -1,41 +0,0 @@
|
||||
package com.baeldung.propertyeditor.creditcard;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CreditCardEditorUnitTest {
|
||||
|
||||
private CreditCardEditor creditCardEditor;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
creditCardEditor = new CreditCardEditor();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenInvalidCardNoWithLessDigits_thenThrowsException() {
|
||||
creditCardEditor.setAsText("123-123-123-123");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenInvalidCardNoWithNonDigits_thenThrowsException() {
|
||||
creditCardEditor.setAsText("1234-1234-xxxx-yyyy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCardNoWithNonDigits_parseCreditCard() {
|
||||
creditCardEditor.setAsText("1234-5678-9123-4560");
|
||||
|
||||
CreditCard creditCard = (CreditCard) creditCardEditor.getValue();
|
||||
Assert.assertNotNull(creditCard);
|
||||
|
||||
Assert.assertEquals(123456, creditCard.getBankIdNo().intValue());
|
||||
Assert.assertEquals(789123456, creditCard.getAccountNo().intValue());
|
||||
Assert.assertEquals(0, creditCard.getCheckCode().intValue());
|
||||
}
|
||||
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import com.baeldung.sampleapp.config.WebConfig;
|
||||
import com.baeldung.sampleapp.web.dto.HeavyResource;
|
||||
import com.baeldung.sampleapp.web.dto.HeavyResourceAddressOnly;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = WebConfig.class)
|
||||
@WebAppConfiguration
|
||||
public class HeavyResourceControllerIntegrationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHeavyResource_whenSendPutRequest_thenCreateResource() throws Exception {
|
||||
mockMvc.perform(put("/heavyresource/1")
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.content(objectMapper.writeValueAsString(new HeavyResource(1, "Tom", "Jackson", 12, "heaven street")))
|
||||
).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNewAddressOfResource_whenExecutePatchRequest_thenUpdateResourcePartially() throws Exception {
|
||||
mockMvc.perform(patch("/heavyresource/1")
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.content(objectMapper.writeValueAsString(new HeavyResourceAddressOnly(1, "5th avenue")))
|
||||
).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNewAddressOfResource_whenExecutePatchGeneric_thenUpdateResourcePartially() throws Exception {
|
||||
HashMap<String, Object> updates = new HashMap<>();
|
||||
updates.put("address", "5th avenue");
|
||||
|
||||
mockMvc.perform(patch("/heavyresource/1")
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.content(objectMapper.writeValueAsString(updates))
|
||||
).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.web.log.app.Application;
|
||||
import com.baeldung.web.log.data.TaxiRide;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = { Application.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class TaxiFareControllerIntegrationTest {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenFetchTaxiFareRateCard_thanOK() {
|
||||
|
||||
String URL = "http://localhost:" + port + "/spring-rest";
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
TaxiRide taxiRide = new TaxiRide(true, 10l);
|
||||
String fare = testRestTemplate.postForObject(
|
||||
URL + "/taxifare/calculate/",
|
||||
taxiRide, String.class);
|
||||
|
||||
assertThat(fare, equalTo("200"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user