BAEL-11: Minor refactorings
This commit is contained in:
parent
38eb1a5f45
commit
499d51e610
@ -10,7 +10,7 @@ import feign.slf4j.Slf4jLogger;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Controller {
|
public class BookControllerFeignClientBuilder {
|
||||||
private BookClient bookClient = createClient(BookClient.class,
|
private BookClient bookClient = createClient(BookClient.class,
|
||||||
"http://localhost:8081/api/books");
|
"http://localhost:8081/api/books");
|
||||||
|
|
@ -1,9 +1,10 @@
|
|||||||
package com.baeldung.feign.clients;
|
package com.baeldung.feign.clients;
|
||||||
|
|
||||||
import com.baeldung.feign.Controller;
|
import com.baeldung.feign.BookControllerFeignClientBuilder;
|
||||||
import com.baeldung.feign.models.Book;
|
import com.baeldung.feign.models.Book;
|
||||||
import com.baeldung.feign.models.BookResource;
|
import com.baeldung.feign.models.BookResource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
@ -20,11 +21,16 @@ import static org.junit.Assert.assertTrue;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class BookClientTest {
|
public class BookClientTest {
|
||||||
private Controller controller = new Controller();
|
private BookControllerFeignClientBuilder feignClientBuilder;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
feignClientBuilder = new BookControllerFeignClientBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenBookClient_shouldRunSuccessfully() throws Exception {
|
public void givenBookClient_shouldRunSuccessfully() throws Exception {
|
||||||
BookClient bookClient = controller.getBookClient();
|
BookClient bookClient = feignClientBuilder.getBookClient();
|
||||||
List<Book> books = bookClient.findAll().stream()
|
List<Book> books = bookClient.findAll().stream()
|
||||||
.map(BookResource::getBook)
|
.map(BookResource::getBook)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -34,7 +40,7 @@ public class BookClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenBookClient_shouldFindOneBook() throws Exception {
|
public void givenBookClient_shouldFindOneBook() throws Exception {
|
||||||
BookClient bookClient = controller.getBookClient();
|
BookClient bookClient = feignClientBuilder.getBookClient();
|
||||||
Book book = bookClient.findByIsbn("0151072558").getBook();
|
Book book = bookClient.findByIsbn("0151072558").getBook();
|
||||||
assertThat(book.getAuthor(), containsString("Orwell"));
|
assertThat(book.getAuthor(), containsString("Orwell"));
|
||||||
log.info("{}", book);
|
log.info("{}", book);
|
||||||
@ -42,7 +48,7 @@ public class BookClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenBookClient_shouldPostBook() throws Exception {
|
public void givenBookClient_shouldPostBook() throws Exception {
|
||||||
BookClient bookClient = controller.getBookClient();
|
BookClient bookClient = feignClientBuilder.getBookClient();
|
||||||
String isbn = UUID.randomUUID().toString();
|
String isbn = UUID.randomUUID().toString();
|
||||||
Book book = new Book(isbn, "Me", "It's me!", null, null);
|
Book book = new Book(isbn, "Me", "It's me!", null, null);
|
||||||
bookClient.create(book);
|
bookClient.create(book);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user