Added a test with multiple contracts in a file
This commit is contained in:
@@ -15,6 +15,7 @@ import com.example.loan.model.FraudServiceResponse;
|
||||
import com.example.loan.model.LoanApplication;
|
||||
import com.example.loan.model.LoanApplicationResult;
|
||||
import com.example.loan.model.LoanApplicationStatus;
|
||||
import com.example.loan.model.Response;
|
||||
|
||||
@Service
|
||||
public class LoanApplicationService {
|
||||
@@ -67,6 +68,26 @@ public class LoanApplicationService {
|
||||
return new LoanApplicationResult(applicationStatus, response.getRejectionReason());
|
||||
}
|
||||
|
||||
public int countAllFrauds() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
|
||||
ResponseEntity<Response> response =
|
||||
restTemplate.exchange("http://localhost:" + port + "/frauds", HttpMethod.GET,
|
||||
new HttpEntity<>(httpHeaders),
|
||||
Response.class);
|
||||
return response.getBody().getCount();
|
||||
}
|
||||
|
||||
public int countDrunks() {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
|
||||
ResponseEntity<Response> response =
|
||||
restTemplate.exchange("http://localhost:" + port + "/drunks", HttpMethod.GET,
|
||||
new HttpEntity<>(httpHeaders),
|
||||
Response.class);
|
||||
return response.getBody().getCount();
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.example.loan.model;
|
||||
|
||||
public class Response {
|
||||
private int count;
|
||||
|
||||
public Response(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public Response() {
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.example.loan;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -16,6 +14,8 @@ import com.example.loan.model.LoanApplication;
|
||||
import com.example.loan.model.LoanApplicationResult;
|
||||
import com.example.loan.model.LoanApplicationStatus;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
// tag::autoconfigure_stubrunner[]
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
|
||||
@@ -55,4 +55,20 @@ public class LoanApplicationServiceTests {
|
||||
}
|
||||
// end::client_tdd[]
|
||||
|
||||
@Test
|
||||
public void shouldSuccessfullyGetAllFrauds() {
|
||||
// when:
|
||||
int count = service.countAllFrauds();
|
||||
// then:
|
||||
assertThat(count).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSuccessfullyGetAllDrunks() {
|
||||
// when:
|
||||
int count = service.countDrunks();
|
||||
// then:
|
||||
assertThat(count).isEqualTo(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user