Skip to content

Commit

Permalink
rename ActivateNotification to ActivateNotificationListener same with… (
Browse files Browse the repository at this point in the history
#166)

* rename ActivateNotification to ActivateNotificationListener same with TrackNotificationListener

* remove unused imports
  • Loading branch information
thomaszurkan-optimizely committed Jan 31, 2018
1 parent f508876 commit 65d41d5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import com.optimizely.ab.config.Variation;
import com.optimizely.ab.event.LogEvent;

import javax.annotation.Nonnull;
import java.util.Map;


public abstract class ActivateNotification extends NotificationListener {
public abstract class ActivateNotificationListener extends NotificationListener {

/**
* Base notify called with var args. This method parses the parameters and calls the abstract method.
Expand Down Expand Up @@ -54,11 +55,11 @@ public final void notify(Object... args) {
* @param variation - The variation that was returned from activate.
* @param event - The impression event that was triggered.
*/
public abstract void onActivate(@javax.annotation.Nonnull Experiment experiment,
@javax.annotation.Nonnull String userId,
@javax.annotation.Nonnull Map<String, String> attributes,
@javax.annotation.Nonnull Variation variation,
@javax.annotation.Nonnull LogEvent event) ;
public abstract void onActivate(@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@Nonnull Variation variation,
@Nonnull LogEvent event) ;

}

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class NotificationCenter {
*/
public enum NotificationType {

Activate(ActivateNotification.class), // Activate was called. Track an impression event
Track(TrackNotification.class); // Track was called. Track a conversion event
Activate(ActivateNotificationListener.class), // Activate was called. Track an impression event
Track(TrackNotificationListener.class); // Track was called. Track a conversion event

private Class notificationTypeClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onExperimentActivated(@Nonnull Experiment experiment,
}

/**
* This is the new method of notification. Implementation classes such as {@link com.optimizely.ab.notification.ActivateNotification}
* This is the new method of notification. Implementation classes such as {@link ActivateNotificationListener}
* will implement this call and provide another method with the correct parameters
* Notify called when a notification is triggered via the {@link com.optimizely.ab.notification.NotificationCenter}
* @param args - variable argument list based on the type of notification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* This class handles the track event notification.
*/
public abstract class TrackNotification extends NotificationListener {
public abstract class TrackNotificationListener extends NotificationListener {

/**
* Base notify called with var args. This method parses the parameters and calls the abstract method.
Expand Down
27 changes: 13 additions & 14 deletions core-api/src/test/java/com/optimizely/ab/OptimizelyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@
import com.optimizely.ab.internal.ExperimentUtils;
import com.optimizely.ab.internal.LogbackVerifier;
import com.optimizely.ab.internal.ReservedEventKey;
import com.optimizely.ab.notification.ActivateNotificationListener;
import com.optimizely.ab.notification.NotificationCenter;
import com.optimizely.ab.notification.NotificationListener;
import com.optimizely.ab.notification.TrackNotificationListener;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import com.optimizely.ab.notification.ActivateNotification;
import com.optimizely.ab.notification.NotificationCenter;
import com.optimizely.ab.notification.TrackNotification;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -2239,7 +2238,7 @@ public void activateWithListener() throws Exception {

testUserAttributes.put(testBucketingIdKey, testBucketingId);

ActivateNotification activateNotification = new ActivateNotification() {
ActivateNotificationListener activateNotification = new ActivateNotificationListener() {
@Override
public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Variation variation, @Nonnull LogEvent event) {
assertEquals(experiment.getKey(), activatedExperiment.getKey());
Expand Down Expand Up @@ -2307,7 +2306,7 @@ public void activateWithListenerNullAttributes() throws Exception {
when(mockBucketer.bucket(activatedExperiment, testUserId))
.thenReturn(bucketedVariation);

ActivateNotification activateNotification = new ActivateNotification() {
ActivateNotificationListener activateNotification = new ActivateNotificationListener() {
@Override
public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Variation variation, @Nonnull LogEvent event) {
assertEquals(experiment.getKey(), activatedExperiment.getKey());
Expand Down Expand Up @@ -2616,7 +2615,7 @@ public void addNotificationListenerFromNotificationCenter() throws Exception {
.thenReturn(bucketedVariation);

// Add listener
ActivateNotification listener = mock(ActivateNotification.class);
ActivateNotificationListener listener = mock(ActivateNotificationListener.class);
optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, listener);

// Check if listener is notified when experiment is activated
Expand Down Expand Up @@ -2644,7 +2643,7 @@ public void addNotificationListenerFromNotificationCenter() throws Exception {
anyMapOf(String.class, Object.class)))
.thenReturn(logEventToDispatch);

TrackNotification trackNotification = mock(TrackNotification.class);
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);

optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Track, trackNotification);

Expand Down Expand Up @@ -2688,11 +2687,11 @@ public void removeNotificationListenerNotificationCenter() throws Exception {
.thenReturn(logEventToDispatch);

// Add and remove listener
ActivateNotification activateNotification = mock(ActivateNotification.class);
ActivateNotificationListener activateNotification = mock(ActivateNotificationListener.class);
int notificationId = optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, activateNotification);
assertTrue(optimizely.notificationCenter.removeNotification(notificationId));

TrackNotification trackNotification = mock(TrackNotification.class);
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);
notificationId = optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Track, trackNotification);
assertTrue(optimizely.notificationCenter.removeNotification(notificationId));

Expand Down Expand Up @@ -2774,8 +2773,8 @@ public void clearNotificationListenersNotificationCenter() throws Exception {
attributeCaptor.capture()
)).thenReturn(logEventToDispatch);

ActivateNotification activateNotification = mock(ActivateNotification.class);
TrackNotification trackNotification = mock(TrackNotification.class);
ActivateNotificationListener activateNotification = mock(ActivateNotificationListener.class);
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);

optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, activateNotification);
optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Track, trackNotification);
Expand Down Expand Up @@ -2867,7 +2866,7 @@ public void trackEventWithListenerAttributes() throws Exception {
logbackVerifier.expectMessage(Level.DEBUG, "Dispatching conversion event to URL test_url with params " +
testParams + " and payload \"\"");

TrackNotification trackNotification = new TrackNotification() {
TrackNotificationListener trackNotification = new TrackNotificationListener() {
@Override
public void onTrack(@Nonnull String eventKey, @Nonnull String userId, @Nonnull Map<String, String> _attributes, @Nonnull Map<String, ?> eventTags, @Nonnull LogEvent event) {
assertEquals(eventType.getKey(), eventKey);
Expand Down Expand Up @@ -2947,7 +2946,7 @@ public void trackEventWithListenerNullAttributes() throws Exception {
logbackVerifier.expectMessage(Level.DEBUG, "Dispatching conversion event to URL test_url with params " +
testParams + " and payload \"\"");

TrackNotification trackNotification = new TrackNotification() {
TrackNotificationListener trackNotification = new TrackNotificationListener() {
@Override
public void onTrack(@Nonnull String eventKey, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Map<String, ?> eventTags, @Nonnull LogEvent event) {
assertEquals(eventType.getKey(), eventKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;

public class NotificationCenterTest {
private NotificationCenter notificationCenter;
private ActivateNotification activateNotification;
private TrackNotification trackNotification;
private ActivateNotificationListener activateNotification;
private TrackNotificationListener trackNotification;

@Rule
public LogbackVerifier logbackVerifier = new LogbackVerifier();

@Before
public void initialize() {
notificationCenter = new NotificationCenter();
activateNotification = mock(ActivateNotification.class);
trackNotification = mock(TrackNotification.class);
activateNotification = mock(ActivateNotificationListener.class);
trackNotification = mock(TrackNotificationListener.class);
}

@Test
Expand All @@ -33,6 +34,7 @@ public void testAddWrongTrackNotificationListener() {
logbackVerifier.expectMessage(Level.WARN,"Notification listener was the wrong type. It was not added to the notification center.");
assertEquals(notificationId, -1);
assertFalse(notificationCenter.removeNotification(notificationId));

}

@Test
Expand Down

0 comments on commit 65d41d5

Please sign in to comment.