Skip to content

Commit

Permalink
refactor: initialise filestore in unit tests
Browse files Browse the repository at this point in the history
initialises a filestore directly in unit tests, rather than relying on the client. this should
reduce side effects (e.g. error flushing on launch) which may have led to flakiness
  • Loading branch information
fractalwrench committed Apr 26, 2018
1 parent 0672281 commit 761cb3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public class ErrorStoreTest {
*/
@Before
public void setUp() throws Exception {
Client client = new Client(InstrumentationRegistry.getContext(), "api-key");
config = client.config;
errorStore = client.errorStore;
config = new Configuration("api-key");
errorStore = new ErrorStore(config, InstrumentationRegistry.getContext());
assertNotNull(errorStore.storeDirectory);
errorStorageDir = new File(errorStore.storeDirectory);
FileUtils.clearFilesInDir(errorStorageDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
Expand All @@ -29,8 +30,9 @@ public class SessionStoreTest {
*/
@Before
public void setUp() throws Exception {
Client client = new Client(InstrumentationRegistry.getContext(), "api-key");
SessionStore sessionStore = client.sessionStore;
Configuration config = new Configuration("api-key");
Context context = InstrumentationRegistry.getContext();
SessionStore sessionStore = new SessionStore(config, context);
assertNotNull(sessionStore.storeDirectory);
storageDir = new File(sessionStore.storeDirectory);
FileUtils.clearFilesInDir(storageDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public class SessionTrackingPayloadTest {
@Before
public void setUp() throws Exception {
Context context = InstrumentationRegistry.getContext();
Client client = new Client(context, "api-key");
sessionStore = client.sessionStore;
Configuration config = new Configuration("api-key");
sessionStore = new SessionStore(config, context);

Assert.assertNotNull(sessionStore.storeDirectory);
storageDir = new File(sessionStore.storeDirectory);
FileUtils.clearFilesInDir(storageDir);
Expand Down

0 comments on commit 761cb3d

Please sign in to comment.