/** * Test updateStatus * * @throws NoSuchFieldException * @throws IllegalArgumentException * @throws IllegalAccessException */ public void testCase01_updateStatus() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Logger.d(TAG, "testCase01_updateStatus"); Field fieldmIsRead = Utils.getPrivateField(mReceivedChatMessage.getClass(), "mIsRead"); assertFalse(fieldmIsRead.getBoolean(mReceivedChatMessage)); mReceivedChatMessage.updateStatus(true); assertTrue(fieldmIsRead.getBoolean(mReceivedChatMessage)); }
@SuppressWarnings("unchecked") private ConcurrentHashMap<IChatWindow, IChatWindowMessage> getChatWindowMapFiled() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Field fieldmChatWindowMap = Utils.getPrivateField(mReceivedChatMessage.getClass().getSuperclass(), "mChatWindowMap"); return (ConcurrentHashMap<IChatWindow, IChatWindowMessage>) fieldmChatWindowMap.get(mReceivedChatMessage); }
/** Use reflect to get GroupChatWindowAdapter instance */ private GroupChatWindowAdapter getGroupChatWindowAdapter() throws Throwable { Logger.v(TAG, "getGroupChatWindowAdapter()"); // Add GroupChatWindow mRemoteChatWindowManager.addGroupChatWindow(MOCK_TAG2, getParticipantList()); // Get WindowBinder#chatWindowManagerAdapters[0] ChatWindowManagerAdapter chatWindowManagerAdapter = mChatWindowManagerAdapters.get(0); // Get ChatWindowManagerAdapter#mRemoteChatWindows Field fieldRemoteChatWindows = Utils.getPrivateField(ChatWindowManagerAdapter.class, "mRemoteChatWindows"); List<BaseChatWindow> mRemoteChatWindows = (List<BaseChatWindow>) fieldRemoteChatWindows.get(chatWindowManagerAdapter); // Get GroupChatWindowAdapter GroupChatWindowAdapter groupChatWindowAdapter = (GroupChatWindowAdapter) mRemoteChatWindows.get(0); assertNotNull(groupChatWindowAdapter); return groupChatWindowAdapter; }
/** Use reflect to get One2OneChatWindowAdapter instance */ private One2OneChatWindowAdapter getOne2OneChatWindowAdapter() throws Throwable { Logger.v(TAG, "getGroupChatWindowAdapter()"); // Add One2OneChatWindow mRemoteChatWindowManager.addOne2OneChatWindow( MOCK_TAG, new Participant(MOCK_NUMBER, MOCK_NAME)); // Get WindowBinder#chatWindowManagerAdapters[0] ChatWindowManagerAdapter chatWindowManagerAdapter = mChatWindowManagerAdapters.get(0); // Get ChatWindowManagerAdapter#mRemoteChatWindows Field fieldRemoteChatWindows = Utils.getPrivateField(ChatWindowManagerAdapter.class, "mRemoteChatWindows"); List<BaseChatWindow> mRemoteChatWindows = (List<BaseChatWindow>) fieldRemoteChatWindows.get(chatWindowManagerAdapter); // Get GroupChatWindowAdapter One2OneChatWindowAdapter one2OneChatWindowAdapter = (One2OneChatWindowAdapter) mRemoteChatWindows.get(0); assertNotNull(one2OneChatWindowAdapter); return one2OneChatWindowAdapter; }
@Override public void setUp() throws Exception { Logger.v(TAG, "setUp()"); super.setUp(); // Get WindowBinder from ApiService Intent intent = new Intent(getSystemContext(), ApiService.class); intent.setAction(IRemoteWindowBinder.class.getName()); IBinder service = bindService(intent); assertTrue(service.isBinderAlive()); mBinder = (WindowBinder) IRemoteWindowBinder.Stub.asInterface(service); assertNotNull(mBinder); mMockRemoteChatWindowManager = new MockRemoteChatWindowManager(); Field fieldRemoteChatWindowManagers = Utils.getPrivateField(WindowBinder.class, "mChatWindowManagerAdapters"); mChatWindowManagerAdapters = (List<ChatWindowManagerAdapter>) fieldRemoteChatWindowManagers.get(mBinder); // Add RemoteChatWindowManager to binder int startSize = mChatWindowManagerAdapters.size(); mBinder.addChatWindowManager(mMockRemoteChatWindowManager, false); assertEquals(startSize + 1, mChatWindowManagerAdapters.size()); mRemoteChatWindowManager = mChatWindowManagerAdapters.get(0); assertNotNull(mRemoteChatWindowManager); }