Skip to content

Commit 71280f5

Browse files
rename ActivateNotification to ActivateNotificationListener same with… (#166)
* rename ActivateNotification to ActivateNotificationListener same with TrackNotificationListener * remove unused imports
1 parent 52476f9 commit 71280f5

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

core-api/src/main/java/com/optimizely/ab/notification/ActivateNotification.java core-api/src/main/java/com/optimizely/ab/notification/ActivateNotificationListener.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
import com.optimizely.ab.config.Variation;
2222
import com.optimizely.ab.event.LogEvent;
2323

24+
import javax.annotation.Nonnull;
2425
import java.util.Map;
2526

2627

27-
public abstract class ActivateNotification extends NotificationListener {
28+
public abstract class ActivateNotificationListener extends NotificationListener {
2829

2930
/**
3031
* Base notify called with var args. This method parses the parameters and calls the abstract method.
@@ -54,11 +55,11 @@ public final void notify(Object... args) {
5455
* @param variation - The variation that was returned from activate.
5556
* @param event - The impression event that was triggered.
5657
*/
57-
public abstract void onActivate(@javax.annotation.Nonnull Experiment experiment,
58-
@javax.annotation.Nonnull String userId,
59-
@javax.annotation.Nonnull Map<String, String> attributes,
60-
@javax.annotation.Nonnull Variation variation,
61-
@javax.annotation.Nonnull LogEvent event) ;
58+
public abstract void onActivate(@Nonnull Experiment experiment,
59+
@Nonnull String userId,
60+
@Nonnull Map<String, String> attributes,
61+
@Nonnull Variation variation,
62+
@Nonnull LogEvent event) ;
6263

6364
}
6465

core-api/src/main/java/com/optimizely/ab/notification/NotificationCenter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public class NotificationCenter {
3434
*/
3535
public enum NotificationType {
3636

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

4040
private Class notificationTypeClass;
4141

core-api/src/main/java/com/optimizely/ab/notification/NotificationListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void onExperimentActivated(@Nonnull Experiment experiment,
6969
}
7070

7171
/**
72-
* This is the new method of notification. Implementation classes such as {@link com.optimizely.ab.notification.ActivateNotification}
72+
* This is the new method of notification. Implementation classes such as {@link ActivateNotificationListener}
7373
* will implement this call and provide another method with the correct parameters
7474
* Notify called when a notification is triggered via the {@link com.optimizely.ab.notification.NotificationCenter}
7575
* @param args - variable argument list based on the type of notification.

core-api/src/main/java/com/optimizely/ab/notification/TrackNotification.java core-api/src/main/java/com/optimizely/ab/notification/TrackNotificationListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* This class handles the track event notification.
2626
*/
27-
public abstract class TrackNotification extends NotificationListener {
27+
public abstract class TrackNotificationListener extends NotificationListener {
2828

2929
/**
3030
* Base notify called with var args. This method parses the parameters and calls the abstract method.

core-api/src/test/java/com/optimizely/ab/OptimizelyTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
import com.optimizely.ab.event.LogEvent;
3838
import com.optimizely.ab.event.internal.EventBuilder;
3939
import com.optimizely.ab.internal.LogbackVerifier;
40-
import com.optimizely.ab.notification.ActivateNotification;
40+
import com.optimizely.ab.notification.ActivateNotificationListener;
4141
import com.optimizely.ab.notification.NotificationCenter;
4242
import com.optimizely.ab.notification.NotificationListener;
43-
import com.optimizely.ab.notification.TrackNotification;
43+
import com.optimizely.ab.notification.TrackNotificationListener;
4444
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4545
import org.junit.Rule;
4646
import org.junit.Test;
@@ -2215,7 +2215,7 @@ public void activateWithListener() throws Exception {
22152215

22162216
testUserAttributes.put(testBucketingIdKey, testBucketingId);
22172217

2218-
ActivateNotification activateNotification = new ActivateNotification() {
2218+
ActivateNotificationListener activateNotification = new ActivateNotificationListener() {
22192219
@Override
22202220
public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Variation variation, @Nonnull LogEvent event) {
22212221
assertEquals(experiment.getKey(), activatedExperiment.getKey());
@@ -2283,7 +2283,7 @@ public void activateWithListenerNullAttributes() throws Exception {
22832283
when(mockBucketer.bucket(activatedExperiment, testUserId))
22842284
.thenReturn(bucketedVariation);
22852285

2286-
ActivateNotification activateNotification = new ActivateNotification() {
2286+
ActivateNotificationListener activateNotification = new ActivateNotificationListener() {
22872287
@Override
22882288
public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Variation variation, @Nonnull LogEvent event) {
22892289
assertEquals(experiment.getKey(), activatedExperiment.getKey());
@@ -2608,7 +2608,7 @@ public void addNotificationListenerFromNotificationCenter() throws Exception {
26082608
.thenReturn(bucketedVariation);
26092609

26102610
// Add listener
2611-
ActivateNotification listener = mock(ActivateNotification.class);
2611+
ActivateNotificationListener listener = mock(ActivateNotificationListener.class);
26122612
optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, listener);
26132613

26142614
// Check if listener is notified when experiment is activated
@@ -2636,7 +2636,7 @@ public void addNotificationListenerFromNotificationCenter() throws Exception {
26362636
anyMapOf(String.class, Object.class)))
26372637
.thenReturn(logEventToDispatch);
26382638

2639-
TrackNotification trackNotification = mock(TrackNotification.class);
2639+
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);
26402640

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

@@ -2680,11 +2680,11 @@ public void removeNotificationListenerNotificationCenter() throws Exception {
26802680
.thenReturn(logEventToDispatch);
26812681

26822682
// Add and remove listener
2683-
ActivateNotification activateNotification = mock(ActivateNotification.class);
2683+
ActivateNotificationListener activateNotification = mock(ActivateNotificationListener.class);
26842684
int notificationId = optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, activateNotification);
26852685
assertTrue(optimizely.notificationCenter.removeNotification(notificationId));
26862686

2687-
TrackNotification trackNotification = mock(TrackNotification.class);
2687+
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);
26882688
notificationId = optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Track, trackNotification);
26892689
assertTrue(optimizely.notificationCenter.removeNotification(notificationId));
26902690

@@ -2771,8 +2771,8 @@ public void clearNotificationListenersNotificationCenter() throws Exception {
27712771
attributeCaptor.capture()
27722772
)).thenReturn(logEventToDispatch);
27732773

2774-
ActivateNotification activateNotification = mock(ActivateNotification.class);
2775-
TrackNotification trackNotification = mock(TrackNotification.class);
2774+
ActivateNotificationListener activateNotification = mock(ActivateNotificationListener.class);
2775+
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);
27762776

27772777
optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, activateNotification);
27782778
optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Track, trackNotification);
@@ -2870,7 +2870,7 @@ public void trackEventWithListenerAttributes() throws Exception {
28702870
logbackVerifier.expectMessage(Level.DEBUG, "Dispatching conversion event to URL test_url with params " +
28712871
testParams + " and payload \"\"");
28722872

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

2959-
TrackNotification trackNotification = new TrackNotification() {
2959+
TrackNotificationListener trackNotification = new TrackNotificationListener() {
29602960
@Override
29612961
public void onTrack(@Nonnull String eventKey, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Map<String, ?> eventTags, @Nonnull LogEvent event) {
29622962
assertEquals(eventType.getKey(), eventKey);

core-api/src/test/java/com/optimizely/ab/notification/NotificationCenterTest.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@
55
import org.junit.Before;
66
import org.junit.Rule;
77
import org.junit.Test;
8-
import org.slf4j.Logger;
9-
import org.slf4j.LoggerFactory;
8+
9+
import javax.annotation.Nonnull;
10+
import java.util.Map;
1011

1112
import static org.junit.Assert.assertEquals;
1213
import static org.junit.Assert.assertFalse;
1314
import static org.mockito.Mockito.mock;
1415

1516
public class NotificationCenterTest {
1617
private NotificationCenter notificationCenter;
17-
private ActivateNotification activateNotification;
18-
private TrackNotification trackNotification;
18+
private ActivateNotificationListener activateNotification;
19+
private TrackNotificationListener trackNotification;
1920

2021
@Rule
2122
public LogbackVerifier logbackVerifier = new LogbackVerifier();
2223

2324
@Before
2425
public void initialize() {
2526
notificationCenter = new NotificationCenter();
26-
activateNotification = mock(ActivateNotification.class);
27-
trackNotification = mock(TrackNotification.class);
27+
activateNotification = mock(ActivateNotificationListener.class);
28+
trackNotification = mock(TrackNotificationListener.class);
2829
}
2930

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

3840
@Test

0 commit comments

Comments
 (0)