@Test public void testNotifyDataSetActionSelected() { final DataSet mockDataSet = mock(DataSet.class); final DataSetListeners listeners = new DataSetListeners(mockDataSet); final OnDataSetActionListener mockListener = mock(OnDataSetActionListener.class); listeners.registerOnDataSetActionListener(mockListener); for (int i = 0; i < 20; i++) { when(mockDataSet.getItemId(i)).thenReturn(i + 1L); when(mockListener.onDataSetActionSelected(DATA_SET_ACTION, i, i + 1L, null)).thenReturn(i % 2 == 0); assertThat(listeners.notifyDataSetActionSelected(DATA_SET_ACTION, i, null), is(i % 2 == 0)); verify(mockListener).onDataSetActionSelected(DATA_SET_ACTION, i, i + 1L, null); } verifyNoMoreInteractions(mockListener); }
public boolean notifyDataSetActionSelected(final int action, final int position, final Object payload) { if (actionListeners != null && !actionListeners.isEmpty()) { final long itemId = dataSet.getItemId(position); for (final OnDataSetActionListener listener : actionListeners) { if (listener.onDataSetActionSelected(action, position, itemId, payload)) { return true; } } } return false; }
DataSetListeners { public boolean notifyDataSetActionSelected(final int action, final int position, final Object payload) { if (actionListeners != null && !actionListeners.isEmpty()) { final long itemId = dataSet.getItemId(position); for (final OnDataSetActionListener listener : actionListeners) { if (listener.onDataSetActionSelected(action, position, itemId, payload)) { return true; } } } return false; } }
DataSetListeners { public boolean notifyDataSetActionSelected(final int action, final int position, final Object payload) { if (actionListeners != null && !actionListeners.isEmpty()) { final long itemId = dataSet.getItemId(position); for (final OnDataSetActionListener listener : actionListeners) { if (listener.onDataSetActionSelected(action, position, itemId, payload)) { return true; } } } return false; } DataSetListeners(@NonNull final DataSet dataSet); }
DataSetListeners { public boolean notifyDataSetActionSelected(final int action, final int position, final Object payload) { if (actionListeners != null && !actionListeners.isEmpty()) { final long itemId = dataSet.getItemId(position); for (final OnDataSetActionListener listener : actionListeners) { if (listener.onDataSetActionSelected(action, position, itemId, payload)) { return true; } } } return false; } DataSetListeners(@NonNull final DataSet dataSet); void registerOnDataSetListener(@NonNull final OnDataSetListener listener); void notifyDataSetChanged(); void notifyDataSetInvalidated(); void unregisterOnDataSetListener(@NonNull final OnDataSetListener listener); void registerOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); boolean notifyDataSetActionSelected(final int action, final int position, final Object payload); void unregisterOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); boolean isEmpty(); }
DataSetListeners { public boolean notifyDataSetActionSelected(final int action, final int position, final Object payload) { if (actionListeners != null && !actionListeners.isEmpty()) { final long itemId = dataSet.getItemId(position); for (final OnDataSetActionListener listener : actionListeners) { if (listener.onDataSetActionSelected(action, position, itemId, payload)) { return true; } } } return false; } DataSetListeners(@NonNull final DataSet dataSet); void registerOnDataSetListener(@NonNull final OnDataSetListener listener); void notifyDataSetChanged(); void notifyDataSetInvalidated(); void unregisterOnDataSetListener(@NonNull final OnDataSetListener listener); void registerOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); boolean notifyDataSetActionSelected(final int action, final int position, final Object payload); void unregisterOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); boolean isEmpty();  }