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