Skip to content

Commit

Permalink
tests: Add coverage for Session class serialisation (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench authored and kattrali committed Apr 23, 2018
1 parent 1546c59 commit bb68c50
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import static com.bugsnag.android.BugsnagTestUtils.generateSessionTracker;
import static com.bugsnag.android.BugsnagTestUtils.streamableToJson;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand All @@ -17,6 +19,7 @@
import org.junit.Test;

import java.io.File;
import java.util.Date;
import java.util.List;

public class SessionTrackingPayloadTest {
Expand All @@ -27,6 +30,7 @@ public class SessionTrackingPayloadTest {

private SessionStore sessionStore;
private File storageDir;
private SessionTrackingPayload payload;

/**
* Configures a session tracking payload and session store, ensuring that 0 files are present
Expand All @@ -41,13 +45,17 @@ public void setUp() throws Exception {
Assert.assertNotNull(sessionStore.storeDirectory);
storageDir = new File(sessionStore.storeDirectory);
FileUtils.clearFilesInDir(storageDir);

session = generateSession();
appData = new AppData(context, new Configuration("a"), generateSessionTracker());
SessionTrackingPayload payload = new SessionTrackingPayload(session, appData);
payload = generatePayloadFromSession(context, generateSession());
rootNode = streamableToJson(payload);
}

private SessionTrackingPayload generatePayloadFromSession(Context context,
Session session) throws Exception {
appData = new AppData(context, new Configuration("a"), generateSessionTracker());
return new SessionTrackingPayload(session, appData);
}

/**
* Deletes any files in the session store created during the test
*
Expand Down Expand Up @@ -93,4 +101,17 @@ public void testMultipleSessionFiles() throws Exception {
assertEquals(2, sessions.length());
}

@Test
public void testAutoCapturedOverride() throws Exception {
session = new Session("id", new Date(), null, false);
Context context = InstrumentationRegistry.getContext();
payload = generatePayloadFromSession(context, session);
assertFalse(session.isAutoCaptured());
session.setAutoCaptured(true);
assertTrue(session.isAutoCaptured());

JSONObject rootNode = streamableToJson(payload);
JSONObject sessionNode = rootNode.getJSONArray("sessions").getJSONObject(0);
assertFalse(sessionNode.has("user"));
}
}

0 comments on commit bb68c50

Please sign in to comment.