Skip to content

Commit 65d41d5

Browse files
rename ActivateNotification to ActivateNotificationListener same with… (#166)
* rename ActivateNotification to ActivateNotificationListener same with TrackNotificationListener * remove unused imports
1 parent f508876 commit 65d41d5

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
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

+13-14
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@
4040
import com.optimizely.ab.internal.ExperimentUtils;
4141
import com.optimizely.ab.internal.LogbackVerifier;
4242
import com.optimizely.ab.internal.ReservedEventKey;
43+
import com.optimizely.ab.notification.ActivateNotificationListener;
44+
import com.optimizely.ab.notification.NotificationCenter;
4345
import com.optimizely.ab.notification.NotificationListener;
46+
import com.optimizely.ab.notification.TrackNotificationListener;
4447
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
45-
import com.optimizely.ab.notification.ActivateNotification;
46-
import com.optimizely.ab.notification.NotificationCenter;
47-
import com.optimizely.ab.notification.TrackNotification;
48-
4948
import org.junit.Rule;
5049
import org.junit.Test;
5150
import org.junit.rules.ExpectedException;
@@ -2239,7 +2238,7 @@ public void activateWithListener() throws Exception {
22392238

22402239
testUserAttributes.put(testBucketingIdKey, testBucketingId);
22412240

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

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

26182617
// Add listener
2619-
ActivateNotification listener = mock(ActivateNotification.class);
2618+
ActivateNotificationListener listener = mock(ActivateNotificationListener.class);
26202619
optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, listener);
26212620

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

2647-
TrackNotification trackNotification = mock(TrackNotification.class);
2646+
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);
26482647

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

@@ -2688,11 +2687,11 @@ public void removeNotificationListenerNotificationCenter() throws Exception {
26882687
.thenReturn(logEventToDispatch);
26892688

26902689
// Add and remove listener
2691-
ActivateNotification activateNotification = mock(ActivateNotification.class);
2690+
ActivateNotificationListener activateNotification = mock(ActivateNotificationListener.class);
26922691
int notificationId = optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Activate, activateNotification);
26932692
assertTrue(optimizely.notificationCenter.removeNotification(notificationId));
26942693

2695-
TrackNotification trackNotification = mock(TrackNotification.class);
2694+
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);
26962695
notificationId = optimizely.notificationCenter.addNotification(NotificationCenter.NotificationType.Track, trackNotification);
26972696
assertTrue(optimizely.notificationCenter.removeNotification(notificationId));
26982697

@@ -2774,8 +2773,8 @@ public void clearNotificationListenersNotificationCenter() throws Exception {
27742773
attributeCaptor.capture()
27752774
)).thenReturn(logEventToDispatch);
27762775

2777-
ActivateNotification activateNotification = mock(ActivateNotification.class);
2778-
TrackNotification trackNotification = mock(TrackNotification.class);
2776+
ActivateNotificationListener activateNotification = mock(ActivateNotificationListener.class);
2777+
TrackNotificationListener trackNotification = mock(TrackNotificationListener.class);
27792778

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

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

2950-
TrackNotification trackNotification = new TrackNotification() {
2949+
TrackNotificationListener trackNotification = new TrackNotificationListener() {
29512950
@Override
29522951
public void onTrack(@Nonnull String eventKey, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Map<String, ?> eventTags, @Nonnull LogEvent event) {
29532952
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)