Skip to content

Commit

Permalink
TRUNK-3586 Slightly improved and prepared for backporting
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Aug 8, 2014
1 parent 018000e commit bd5a8b0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 0 additions & 2 deletions api/src/test/java/org/openmrs/EncounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
Expand All @@ -35,7 +34,6 @@
import org.mockito.Mock;
import org.openmrs.api.EncounterService;
import org.openmrs.api.ProviderService;
import org.openmrs.api.context.Context;
import org.openmrs.test.BaseContextMockTest;
import org.openmrs.test.Verifies;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* {@link org.openmrs.test.BaseContextSensitiveTest}.
*
* @deprecated Avoid using this by not calling Context.get...Service() in your code.
* @since 1.11
* @since 1.11, 1.10, 1.9.9
*/
@Deprecated
public class ContextMockHelper {
Expand Down Expand Up @@ -118,7 +118,7 @@ public void authenticateMockUser() {
Calendar calendar = Calendar.getInstance();
calendar.set(1980, 01, 01);
person.setBirthdate(calendar.getTime());
person.setGender("male");
person.setGender("M");
user.setPerson(person);

when(userContext.getAuthenticatedUser()).thenReturn(user);
Expand Down Expand Up @@ -252,6 +252,7 @@ public void setUserContext(UserContext userContext) {

Context.setUserContext(userContext);
this.userContext = userContext;
authenticateMockUser();
}

}
6 changes: 2 additions & 4 deletions api/src/test/java/org/openmrs/test/BaseContextMockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.openmrs.module.ModuleUtilTest;

/**
* Tests extending this class have a mocked UserContext and User. In addition you can mock
* Tests extending this class have a mocked authenticated UserContext. In addition you can mock
* Context.get...Service() calls by annotating fields with {@link Mock}.
*
* @see ModuleUtilTest
* @since 1.11
* @since 1.11, 1.10, 1.9.9
*/
public abstract class BaseContextMockTest {

Expand All @@ -43,8 +43,6 @@ public abstract class BaseContextMockTest {
@Before
public void initMocks() {
MockitoAnnotations.initMocks(this);

contextMockHelper.authenticateMockUser();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public abstract class BaseContextSensitiveTest extends AbstractJUnit4SpringConte
/**
* Allows mocking services returned by Context. See {@link ContextMockHelper}
*
* @since 1.11
* @since 1.11, 1.10, 1.9.9
*/
@InjectMocks
protected ContextMockHelper contextMockHelper;
Expand Down Expand Up @@ -186,15 +186,15 @@ public BaseContextSensitiveTest() {
/**
* Initializes fields annotated with {@link Mock}.
*
* @since 1.10
* @since 1.11, 1.10, 1.9.9
*/
@Before
public void initMocks() {
MockitoAnnotations.initMocks(this);
}

/**
* @since 1.10
* @since 1.11, 1.10, 1.9.9
*/
@After
public void revertContextMocks() {
Expand Down

0 comments on commit bd5a8b0

Please sign in to comment.