ã¦ããããã¹ãã§Userã®ã¤ã³ã¹ã¿ã³ã¹ãåå¾ãã
ãã¼ã«ã«ã®ã¦ããããã¹ãã§ãcom.google.appengine.api.users.Userã®ã¤ã³ã¹ã¿ã³ã¹ãåå¾ãããã¨ãã¦ããããã©ã«ãã»ã³ã³ã¹ãã©ã¯ã¿ã¯ãã©ã¤ãã¼ãã§ããããUserServiceã®getCurrentUser()ã¡ã½ãããnullãè¿ããããç°¡åã§ã¯ãªãã
以ä¸ã®ãªã³ã¯ãåèã«ããã°ãgetCurrentUser()ã¡ã½ããã§ä»»æã®userIdãæã¤Userã®ã¤ã³ã¹ã¿ã³ã¹ãåå¾ãããã¨ãå¯è½ã
Local Unit Testing with UserService: userId==null problem
ã¾ããslim3ãå©ç¨ããå ´åã¯ãä¸è¨ã®ããã«tester.environmentããorg.slim3.tester.TestEnvironmentãå©ç¨ãããããã
public class UserTest extends AppEngineTestCase { @Before @Override public void setUp() throws Exception { super.setUp(); Map<String, Object> envAttributes = new HashMap<String, Object>(); envAttributes.put( "com.google.appengine.api.users.UserService.user_id_key", "42"); tester.environment.setEmail("[email protected]"); tester.environment.setAttributes(envAttributes); } @Test public void instantiateUser() { UserService service = UserServiceFactory.getUserService(); User user = service.getCurrentUser(); assertThat(user, is(notNullValue())); assertThat(user.getUserId(), equalTo("42")); assertThat(user.getEmail(), equalTo("[email protected]")); } }