Skip to content

Commit

Permalink
Merge pull request #827 from mixpanel/zihe-fix-mpconfig
Browse files Browse the repository at this point in the history
Passing down the 'MPConfig' instance from the MixpanelAPI instance
  • Loading branch information
zihejia committed Feb 2, 2024
2 parents c61224d + f7b115b commit f5632a4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
};

InstrumentationRegistry.getInstrumentation().getContext().deleteDatabase("mixpanel");
mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext()) {
mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {
@Override
public void cleanupEvents(String last_id, Table table, String token) {
if (token.equalsIgnoreCase(TOKEN)) {
Expand All @@ -102,7 +102,7 @@ public int addJSON(JSONObject j, String token, Table table) {
}
};

final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext()) {
final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {

@Override
protected RemoteService getPoster() {
Expand Down Expand Up @@ -228,7 +228,7 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
}
};

final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext()) {
final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {
@Override
public void cleanupEvents(String last_id, Table table, String token) {
if (token.equalsIgnoreCase(SECOND_TOKEN)) {
Expand All @@ -247,7 +247,7 @@ public int addJSON(JSONObject j, String token, Table table) {
}
};

final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext()) {
final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {
@Override
protected RemoteService getPoster() {
return mpSecondPoster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public int getFlushInterval() {
}
};

final MPDbAdapter mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext()) {
final MPDbAdapter mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext(), config) {
@Override
public void cleanupEvents(String last_id, Table table, String token) {
mCleanupCalls.add("called");
Expand All @@ -124,7 +124,7 @@ protected boolean aboveMemThreshold() {
}
};

final AnalyticsMessages listener = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext()) {
final AnalyticsMessages listener = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext(), config) {
@Override
protected MPDbAdapter makeDbAdapter(Context context) {
return mockAdapter;
Expand All @@ -135,10 +135,6 @@ protected RemoteService getPoster() {
return mockPoster;
}

@Override
protected MPConfig getConfig(Context context) {
return config;
}
};

mMetrics = new TestUtils.CleanMixpanelAPI(InstrumentationRegistry.getInstrumentation().getContext(), mMockPreferences, "Test Message Queuing") {
Expand Down
Loading

0 comments on commit f5632a4

Please sign in to comment.