@UsesMocks({ NotificationAuthenticator.class, ActivitySystem.class, SocializeSession.class, SocializeAction.class, User.class, NotificationMessage.class }) public void test_translate() throws SocializeException { NotificationAuthenticator notificationAuthenticator = AndroidMock.createMock(NotificationAuthenticator.class); ActivitySystem activitySystem = AndroidMock.createMock(ActivitySystem.class); SocializeSession session = AndroidMock.createMock(SocializeSession.class); SocializeAction action = AndroidMock.createMock(SocializeAction.class); User user = AndroidMock.createMock(User.class); NotificationMessage message = AndroidMock.createMock(NotificationMessage.class); final long actionId = 69L; final long userId = 1001L; final ActionType type = ActionType.COMMENT; final Context context = getContext(); AndroidMock.expect(message.getActionId()).andReturn(actionId).anyTimes(); AndroidMock.expect(message.getActionType()).andReturn(type).anyTimes(); AndroidMock.expect(notificationAuthenticator.authenticate(context)).andReturn(session); AndroidMock.expect(activitySystem.getAction(session, actionId, type)).andReturn(action); AndroidMock.expect(action.getUser()).andReturn(user); AndroidMock.expect(user.getId()).andReturn(userId).anyTimes(); AndroidMock.replay(notificationAuthenticator, activitySystem, session, action, user, message); SocializeActionMessageTranslator translator = new SocializeActionMessageTranslator(); Bundle data = new Bundle(); translator.setActivitySystem(activitySystem); translator.setNotificationAuthenticator(notificationAuthenticator); SocializeAction translated = translator.translate(context, data, message); AndroidMock.verify(notificationAuthenticator, activitySystem, session, action, user, message); assertNotNull(translated); assertSame(action, translated); assertNotNull(data.getString(Socialize.ACTION_ID)); assertNotNull(data.getString(Socialize.USER_ID)); assertEquals(String.valueOf(actionId), data.getString(Socialize.ACTION_ID)); assertEquals(String.valueOf(userId), data.getString(Socialize.USER_ID)); }
/* (non-Javadoc) * @see com.socialize.launcher.Launcher#launch(android.app.Activity, android.os.Bundle) */ @Override public boolean launch(final Activity context, Bundle data) { if (entityLoaderUtils != null) { SocializeEntityLoader entityLoader = entityLoaderUtils.initEntityLoader(); if (entityLoader != null) { Object idObj = data.get(Socialize.ENTITY_ID); if (idObj != null) { long id = Long.parseLong(idObj.toString()); try { SocializeSession session = notificationAuthenticator.authenticate(context); Entity entity = entitySystem.getEntity(session, id); return loadEntity(context, entityLoader, entity); } catch (SocializeException e) { handleError("Failed to load entity", e); } } else { handleWarn("No entity id found. Entity based notification cannot be handled"); } } else { handleWarn("No entity loader found. Entity based notification cannot be handled"); } } return false; }