Skip to content

Commit 0ec532b

Browse files
committed
Added unit tests for default package
1 parent 957eac5 commit 0ec532b

File tree

3 files changed

+347
-14
lines changed

3 files changed

+347
-14
lines changed

src/main/java/com/exceptionless/exceptionlessclient/ExceptionlessClient.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.exceptionless.exceptionlessclient.models.enums.EventType;
1111
import com.exceptionless.exceptionlessclient.models.submission.SubmissionResponse;
1212
import com.exceptionless.exceptionlessclient.plugins.EventPluginRunner;
13+
import com.exceptionless.exceptionlessclient.utils.VisibleForTesting;
1314
import lombok.Builder;
1415
import lombok.Getter;
1516
import org.slf4j.Logger;
@@ -34,10 +35,20 @@ public ExceptionlessClient(ConfigurationManager configurationManager) {
3435
this.eventPluginRunner =
3536
EventPluginRunner.builder().configurationManager(this.configurationManager).build();
3637
this.updateSettingsTimer = new Timer(UPDATE_SETTINGS_TIMER_NAME);
37-
init();
38+
init(UPDATE_SETTINGS_TIMER_INITIAL_DELAY);
3839
}
3940

40-
private void init() {
41+
@VisibleForTesting
42+
ExceptionlessClient(
43+
ConfigurationManager configurationManager, long updateSettingsTimerInitialDelay) {
44+
this.configurationManager = configurationManager;
45+
this.eventPluginRunner =
46+
EventPluginRunner.builder().configurationManager(this.configurationManager).build();
47+
this.updateSettingsTimer = new Timer(UPDATE_SETTINGS_TIMER_NAME);
48+
init(updateSettingsTimerInitialDelay);
49+
}
50+
51+
private void init(long delay) {
4152
updateSettingsTimer.schedule(
4253
new TimerTask() {
4354
@Override
@@ -49,16 +60,15 @@ public void run() {
4960
}
5061
}
5162
},
52-
UPDATE_SETTINGS_TIMER_INITIAL_DELAY,
63+
delay,
5364
configurationManager.getConfiguration().getUpdateSettingsWhenIdleInterval());
5465

5566
configurationManager.onChanged(
5667
ignored -> configurationManager.getSettingsManager().updateSettings());
5768
configurationManager
5869
.getQueue()
5970
.onEventsPosted(
60-
(ignored1, ignored2) ->
61-
configurationManager.getSettingsManager().updateSettings());
71+
(ignored1, ignored2) -> configurationManager.getSettingsManager().updateSettings());
6272
}
6373

6474
public static ExceptionlessClient from(String apiKey, String serverUrl) {
@@ -76,7 +86,7 @@ public void submitException(Exception exception) {
7686
submitEvent(EventPluginContext.builder().event(event).context(pluginContext).build());
7787
}
7888

79-
private Event.EventBuilder createException() {
89+
public Event.EventBuilder createException() {
8090
return createEvent().type(EventType.ERROR.value());
8191
}
8292

@@ -96,7 +106,7 @@ public void submitFeatureUsage(String feature) {
96106
submitEvent(EventPluginContext.from(event));
97107
}
98108

99-
private Event.EventBuilder createFeatureUsage(String feature) {
109+
public Event.EventBuilder createFeatureUsage(String feature) {
100110
return createEvent().type(EventType.USAGE.value()).source(feature);
101111
}
102112

@@ -113,10 +123,23 @@ public void submitLog(String message, String source, String level) {
113123
submitEvent(EventPluginContext.from(event));
114124
}
115125

116-
private Event.EventBuilder createLog(String message, String source, String level) {
126+
public Event.EventBuilder createLog(String message) {
127+
return createLog(message, null, null);
128+
}
129+
130+
public Event.EventBuilder createLog(String message, String source) {
131+
return createLog(message, source, null);
132+
}
133+
134+
public Event.EventBuilder createLog(String message, String source, String level) {
117135
if (source == null) {
118136
// Calling method
119-
source = Thread.currentThread().getStackTrace()[2].getMethodName();
137+
StackTraceElement[] traceElements = Thread.currentThread().getStackTrace();
138+
source = traceElements[2].getMethodName();
139+
// Came from the overrided method
140+
if (source.equals("createLog")) {
141+
source = traceElements[3].getMethodName();
142+
}
120143
}
121144

122145
Event.EventBuilder builder =
@@ -133,7 +156,7 @@ public void submitNotFound(String resource) {
133156
submitEvent(EventPluginContext.from(event));
134157
}
135158

136-
private Event.EventBuilder createNotFound(String resource) {
159+
public Event.EventBuilder createNotFound(String resource) {
137160
return createEvent().type(EventType.NOT_FOUND.value()).source(resource);
138161
}
139162

@@ -142,11 +165,11 @@ public void submitSessionStart() {
142165
submitEvent(EventPluginContext.from(event));
143166
}
144167

145-
private Event.EventBuilder createSessionStart() {
168+
public Event.EventBuilder createSessionStart() {
146169
return createEvent().type(EventType.SESSION.value());
147170
}
148171

149-
private Event.EventBuilder createEvent() {
172+
public Event.EventBuilder createEvent() {
150173
return Event.builder()
151174
.dataExclusions(configurationManager.getDataExclusions())
152175
.date(LocalDate.now());

src/main/java/com/exceptionless/exceptionlessclient/configuration/Configuration.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ public Configuration(
3232
this.apiKey = apiKey;
3333
this.serverUrl = serverUrl == null ? "https://collector.exceptionless.io" : serverUrl;
3434
this.configServerUrl =
35-
configServerUrl == null ? "https://config.exceptionless.io" : configServerUrl;
35+
configServerUrl == null
36+
? (serverUrl == null ? "https://config.exceptionless.io" : serverUrl)
37+
: configServerUrl;
3638
this.heartbeatServerUrl =
37-
heartbeatServerUrl == null ? "https://heartbeat.exceptionless.io" : heartbeatServerUrl;
39+
heartbeatServerUrl == null
40+
? (serverUrl == null ? "https://heartbeat.exceptionless.io" : serverUrl)
41+
: heartbeatServerUrl;
3842
this.updateSettingsWhenIdleInterval =
3943
updateSettingsWhenIdleInterval == null ? 12000L : updateSettingsWhenIdleInterval;
4044
this.submissionBatchSize = submissionBatchSize == null ? 50 : submissionBatchSize;

0 commit comments

Comments
 (0)