Bael 1674 (#4335)
* Handle events - BAEL - 1674 * BAEL -1674 - test * test - BAEL-1674 * Change system.out to logger * minor change
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.events;
|
||||
|
||||
import com.baeldung.models.Author;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class AuthorEventHandlerTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateAuthorThenSuccess() {
|
||||
Author author = mock(Author.class);
|
||||
AuthorEventHandler authorEventHandler = new AuthorEventHandler();
|
||||
authorEventHandler.handleAuthorBeforeCreate(author);
|
||||
Mockito.verify(author,Mockito.times(1)).getName();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeleteAuthorThenSuccess() {
|
||||
Author author = mock(Author.class);
|
||||
AuthorEventHandler authorEventHandler = new AuthorEventHandler();
|
||||
authorEventHandler.handleAuthorAfterDelete(author);
|
||||
Mockito.verify(author,Mockito.times(1)).getName();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.events;
|
||||
|
||||
import com.baeldung.models.Author;
|
||||
import com.baeldung.models.Book;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class BookEventHandlerTest {
|
||||
@Test
|
||||
public void whenCreateBookThenSuccess() {
|
||||
Book book = mock(Book.class);
|
||||
BookEventHandler bookEventHandler = new BookEventHandler();
|
||||
bookEventHandler.handleBookBeforeCreate(book);
|
||||
Mockito.verify(book,Mockito.times(1)).getAuthors();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreateAuthorThenSuccess() {
|
||||
Author author = mock(Author.class);
|
||||
BookEventHandler bookEventHandler = new BookEventHandler();
|
||||
bookEventHandler.handleAuthorBeforeCreate(author);
|
||||
Mockito.verify(author,Mockito.times(1)).getBooks();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user