@Test public void testAddListener_notifiesAddedListener() { ConstraintListener<Boolean> constraintListener1 = mock(ConstraintListener.class); ConstraintListener<Boolean> constraintListener2 = mock(ConstraintListener.class); mTracker.mInitialState = true; mTracker.addListener(constraintListener1); verify(constraintListener1).onConstraintChanged(true); mTracker.addListener(constraintListener2); verify(constraintListener2).onConstraintChanged(true); verifyNoMoreInteractions(constraintListener1); }
public void addListener(ConstraintListener<T> listener) { if (mListeners.add(listener)) { if (mListeners.size() == 1) { mCurrentState = getInitialState(); Log.d(TAG, String.format("%s: initial state = %s", getClass().getSimpleName(), mCurrentState)); startTracking(); } listener.onConstraintChanged(mCurrentState); } }
ConstraintTracker { public void addListener(ConstraintListener<T> listener) { if (mListeners.add(listener)) { if (mListeners.size() == 1) { mCurrentState = getInitialState(); Log.d(TAG, String.format("%s: initial state = %s", getClass().getSimpleName(), mCurrentState)); startTracking(); } listener.onConstraintChanged(mCurrentState); } } }
ConstraintTracker { public void addListener(ConstraintListener<T> listener) { if (mListeners.add(listener)) { if (mListeners.size() == 1) { mCurrentState = getInitialState(); Log.d(TAG, String.format("%s: initial state = %s", getClass().getSimpleName(), mCurrentState)); startTracking(); } listener.onConstraintChanged(mCurrentState); } } ConstraintTracker(Context context); }
ConstraintTracker { public void addListener(ConstraintListener<T> listener) { if (mListeners.add(listener)) { if (mListeners.size() == 1) { mCurrentState = getInitialState(); Log.d(TAG, String.format("%s: initial state = %s", getClass().getSimpleName(), mCurrentState)); startTracking(); } listener.onConstraintChanged(mCurrentState); } } ConstraintTracker(Context context); void addListener(ConstraintListener<T> listener); void removeListener(ConstraintListener<T> listener); void setState(T newState); abstract T getInitialState(); abstract void startTracking(); abstract void stopTracking(); }
ConstraintTracker { public void addListener(ConstraintListener<T> listener) { if (mListeners.add(listener)) { if (mListeners.size() == 1) { mCurrentState = getInitialState(); Log.d(TAG, String.format("%s: initial state = %s", getClass().getSimpleName(), mCurrentState)); startTracking(); } listener.onConstraintChanged(mCurrentState); } } ConstraintTracker(Context context); void addListener(ConstraintListener<T> listener); void removeListener(ConstraintListener<T> listener); void setState(T newState); abstract T getInitialState(); abstract void startTracking(); abstract void stopTracking();  }