Skip to content

rename ActivateNotification to ActivateNotificationListener same with… #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 12 additions & 12 deletions core-api/src/test/java/com/optimizely/ab/OptimizelyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import com.optimizely.ab.event.LogEvent;
import com.optimizely.ab.event.internal.EventBuilder;
import com.optimizely.ab.internal.LogbackVerifier;
import com.optimizely.ab.notification.ActivateNotification;
import com.optimizely.ab.notification.ActivateNotificationListener;
import com.optimizely.ab.notification.NotificationCenter;
import com.optimizely.ab.notification.NotificationListener;
import com.optimizely.ab.notification.TrackNotification;
import com.optimizely.ab.notification.TrackNotificationListener;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -2215,7 +2215,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 @@ -2283,7 +2283,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 @@ -2608,7 +2608,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 @@ -2636,7 +2636,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 @@ -2680,11 +2680,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 @@ -2771,8 +2771,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 @@ -2870,7 +2870,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 @@ -2956,7 +2956,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