Skip to content

Commit

Permalink
refactor: check if sessionsEndpoint is null rather than extra boolean…
Browse files Browse the repository at this point in the history
… flag when checking whether to
  • Loading branch information
fractalwrench committed May 11, 2018
1 parent 3334063 commit 66ce062
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import android.support.test.filters.SmallTest;
Expand Down Expand Up @@ -52,12 +53,15 @@ public void testInvalidSessionEndpoint() {
//noinspection ConstantConditions
config.setEndpoints("http://example.com", null);
assertFalse(config.shouldAutoCaptureSessions());
assertNull(config.getSessionEndpoint());

config.setEndpoints("http://example.com", "");
assertFalse(config.shouldAutoCaptureSessions());
assertNull(config.getSessionEndpoint());

config.setEndpoints("http://example.com", "http://sessions.example.com");
assertTrue(config.shouldAutoCaptureSessions());
assertEquals("http://sessions.example.com", config.getSessionEndpoint());
}

@Test
Expand Down
21 changes: 12 additions & 9 deletions sdk/src/main/java/com/bugsnag/android/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class Configuration extends Observable implements Observer {
private String buildUuid;
private String appVersion;
private String context;
private String endpoint = "https://notify.bugsnag.com";
private String sessionEndpoint = "https://sessions.bugsnag.com";
private volatile String endpoint = "https://notify.bugsnag.com";
private volatile String sessionEndpoint = "https://sessions.bugsnag.com";

private String[] ignoreClasses;
@Nullable
Expand All @@ -56,7 +56,6 @@ public class Configuration extends Observable implements Observer {
= new ConcurrentLinkedQueue<>();
private String codeBundleId;
private String notifierType;
volatile boolean invalidSessionsEndpoint;

/**
* Construct a new Bugsnag configuration object
Expand Down Expand Up @@ -160,20 +159,24 @@ public void setEndpoint(String endpoint) {
@SuppressWarnings("ConstantConditions")
public void setEndpoints(@NonNull String notify, @NonNull String sessions)
throws IllegalArgumentException {
boolean invalidNotify = TextUtils.isEmpty(notify);
invalidSessionsEndpoint = TextUtils.isEmpty(sessions);

if (invalidNotify) {
if (TextUtils.isEmpty(notify)) {
throw new IllegalArgumentException("Notify endpoint cannot be empty or null.");
} else {
this.endpoint = notify;
}

boolean invalidSessionsEndpoint = TextUtils.isEmpty(sessions);

if (invalidSessionsEndpoint) {
Logger.warn("The session tracking endpoint has not been set. "
+ "Session tracking is disabled");
autoCaptureSessions = false;
this.sessionEndpoint = null;
} else {
this.sessionEndpoint = sessions;
}
this.endpoint = notify;
this.sessionEndpoint = sessions;
this.autoCaptureSessions = !invalidNotify && !invalidSessionsEndpoint;
this.autoCaptureSessions = !invalidSessionsEndpoint;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/bugsnag/android/SessionTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SessionTracker implements Application.ActivityLifecycleCallbacks {
* @param user the session user (if any)
*/
void startNewSession(@NonNull Date date, @Nullable User user, boolean autoCaptured) {
if (configuration.invalidSessionsEndpoint) {
if (configuration.getSessionEndpoint() == null) {
Logger.warn("The session tracking endpoint has not been set. "
+ "Session tracking is disabled");
return;
Expand Down

0 comments on commit 66ce062

Please sign in to comment.