Skip to content

Commit 2913d26

Browse files
author
Mike Davis
committed
Address coverage changes.
1 parent aaa70a9 commit 2913d26

File tree

4 files changed

+88
-16
lines changed

4 files changed

+88
-16
lines changed

core-api/src/main/java/com/optimizely/ab/Optimizely.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,11 +1080,6 @@ protected Builder withDecisionService(DecisionService decisionService) {
10801080
return this;
10811081
}
10821082

1083-
protected Builder withEventFactory(EventFactory eventFactory) {
1084-
this.eventFactory = eventFactory;
1085-
return this;
1086-
}
1087-
10881083
public Optimizely build() {
10891084

10901085
if (clientEngine == null) {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
*
3+
* Copyright 2019, Optimizely and contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.optimizely.ab.event;
18+
19+
import com.optimizely.ab.event.internal.payload.EventBatch;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
import java.util.Collections;
24+
import java.util.Map;
25+
26+
import static org.junit.Assert.*;
27+
28+
public class LogEventTest {
29+
30+
private static final LogEvent.RequestMethod REQUEST_METHOD = LogEvent.RequestMethod.POST;
31+
private static final String ENDPOINT_URL = "endpoint";
32+
private static final Map<String, String> REQUEST_PARAMS = Collections.singletonMap("KEY", "VALUE");
33+
private static final EventBatch EVENT_BATCH = new EventBatch();
34+
35+
private LogEvent logEvent;
36+
37+
@Before
38+
public void setUp() throws Exception {
39+
logEvent = new LogEvent(REQUEST_METHOD, ENDPOINT_URL, REQUEST_PARAMS, EVENT_BATCH);
40+
}
41+
42+
@Test
43+
public void testGetRequestMethod() {
44+
assertEquals(REQUEST_METHOD, logEvent.getRequestMethod());
45+
}
46+
47+
@Test
48+
public void testGetEndpointUrl() {
49+
assertEquals(ENDPOINT_URL, logEvent.getEndpointUrl());
50+
}
51+
52+
@Test
53+
public void testGetRequestParams() {
54+
assertEquals(REQUEST_PARAMS, logEvent.getRequestParams());
55+
}
56+
57+
@Test
58+
public void testGetBody() {
59+
assertEquals("{}", logEvent.getBody());
60+
}
61+
62+
@Test
63+
public void testGetEventBatch() {
64+
assertEquals(EVENT_BATCH, logEvent.getEventBatch());
65+
}
66+
67+
@Test
68+
public void testToString() {
69+
assertEquals("LogEvent{requestMethod=POST, endpointUrl='endpoint', requestParams={KEY=VALUE}, body='{}'}", logEvent.toString());
70+
}
71+
72+
@Test
73+
public void testEquals() {
74+
LogEvent otherLogEvent = new LogEvent(REQUEST_METHOD, ENDPOINT_URL, REQUEST_PARAMS, EVENT_BATCH);
75+
assertTrue(logEvent.equals(logEvent));
76+
assertTrue(logEvent.equals(otherLogEvent));
77+
}
78+
}

core-api/src/test/java/com/optimizely/ab/event/NoopEventHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016-2017, Optimizely and contributors
3+
* Copyright 2016-2017, 2019 Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.annotation.Nonnull;
3131
import java.util.List;
3232
import java.util.Map;
33+
import java.util.concurrent.atomic.AtomicBoolean;
3334

3435
import static junit.framework.TestCase.assertNotSame;
3536
import static junit.framework.TestCase.assertTrue;
@@ -142,13 +143,12 @@ public void testNotificationTypeClasses() {
142143

143144
@Test
144145
public void testAddTrackNotificationInterface() {
145-
int notificationId = notificationCenter.addTrackNotificationListener(new TrackNotificationListenerInterface() {
146-
@Override
147-
public void onTrack(@Nonnull String eventKey, @Nonnull String userId, @Nonnull Map<String, ?> attributes, @Nonnull Map<String, ?> eventTags, @Nonnull LogEvent event) {
146+
final AtomicBoolean triggered = new AtomicBoolean();
147+
int notificationId = notificationCenter.addTrackNotificationListener((eventKey, userId, attributes, eventTags, event) -> triggered.set(true));
148+
notificationCenter.send(new TrackNotification());
148149

149-
}
150-
});
151150
assertNotSame(-1, notificationId);
151+
assertTrue(triggered.get());
152152
assertTrue(notificationCenter.removeNotificationListener(notificationId));
153153
}
154154

@@ -162,13 +162,12 @@ public void testAddDecisionNotificationInterface() {
162162

163163
@Test
164164
public void testAddActivateNotificationInterface() {
165-
int notificationId = notificationCenter.addActivateNotificationListener(new ActivateNotificationListenerInterface() {
166-
@Override
167-
public void onActivate(@Nonnull Experiment experiment, @Nonnull String userId, @Nonnull Map<String, ?> attributes, @Nonnull Variation variation, @Nonnull LogEvent event) {
165+
final AtomicBoolean triggered = new AtomicBoolean();
166+
int notificationId = notificationCenter.addActivateNotificationListener((experiment, userId, attributes, variation, event) -> triggered.set(true));
167+
notificationCenter.send(new ActivateNotification());
168168

169-
}
170-
});
171169
assertNotSame(-1, notificationId);
170+
assertTrue(triggered.get());
172171
assertTrue(notificationCenter.removeNotificationListener(notificationId));
173172
}
174173

0 commit comments

Comments
 (0)