-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b51a2d
commit 7cd8661
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
FlashCards_Service/src/test/java/org/robbins/flashcards/auditing/AuditingAwareUserUT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.robbins.flashcards.auditing; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.mockito.Mock; | ||
import org.robbins.flashcards.model.User; | ||
import org.robbins.tests.BaseMockingTest; | ||
import org.robbins.tests.UnitTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
@Category(UnitTest.class) | ||
public class AuditingAwareUserUT extends BaseMockingTest { | ||
|
||
AuditingAwareUser auditingAwareUser; | ||
|
||
@Mock | ||
User mockUser; | ||
|
||
@Mock | ||
private ApplicationContext mockContext; | ||
|
||
@Before | ||
public void before() { | ||
auditingAwareUser = new AuditingAwareUser(); | ||
ReflectionTestUtils.setField(auditingAwareUser, "context", mockContext); | ||
} | ||
|
||
@Test | ||
public void getCurrentAuditor() { | ||
when(mockContext.getBean("loggedInUser")).thenReturn(mockUser); | ||
when(mockUser.getId()).thenReturn(1L); | ||
|
||
User result = auditingAwareUser.getCurrentAuditor(); | ||
|
||
verify(mockContext).getBean("loggedInUser"); | ||
assertThat(result, is(User.class)); | ||
assertThat(result.getId(), is(1L)); | ||
} | ||
} |