コード例 #1
0
  protected void doGetUserProfile(final long userId, final SocializeAction action) {

    if (userId >= 0 && (currentUser == null || !currentUser.getId().equals(userId))) {
      UserUtils.getUser(
          getActivity(),
          userId,
          new UserGetListener() {

            @Override
            public void onGet(User user) {
              // Set the user details into the view elements
              currentUser = user;
              setUserDetails(user, action);
              countdown();
            }

            @Override
            public void onError(SocializeException error) {
              countdown();
              showError(getContext(), error);
            }
          });
    } else {
      countdown();
    }
  }
  @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));
  }