* Handle events - BAEL - 1674

* BAEL -1674 - test

* test - BAEL-1674

* Change system.out to logger

* minor change
This commit is contained in:
raksha-rao
2018-05-25 01:50:47 +05:30
committed by maibin
parent 7dc605f7b0
commit 60cb1d7d49
5 changed files with 135 additions and 0 deletions
@@ -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();
}
}