I am trying to mock the gae user service for writing unit tests and couldn't get the following code to work.
My test class is as below.
public class AuthenticationTest {
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalUserServiceTestConfig())
.setEnvIsAdmin(true).setEnvIsLoggedIn(true)
.setEnvEmail("test@example.com");
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void testIsAdmin() {
UserService userService = UserServiceFactory.getUserService();
assertTrue(userService.isUserAdmin());
String email = userService.getCurrentUser().getEmail();
assertEquals(email, "test@example.com");
}
}
I find that userService.getCurrentUser() always returns null.
Most of the code is taken from the example in developers.google.com. The only thing I added is call to .setEnvEmail("test@example.com")
Any help would be appreciated.
Thanks,
Sathya