Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and simplify #332

Merged
merged 2 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ allprojects {
}
ext {
globalMinSdkVersion = 14
globalTargetSdkVersion = 28
globalCompileSdkVersion = 28
globalTargetSdkVersion = 30
globalCompileSdkVersion = 30
timberVersion = '4.7.1'
}
}
4 changes: 2 additions & 2 deletions tracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ dependencies {
testImplementation 'com.squareup.okhttp3:mockwebserver:4.8.0'

// Mocktio
testImplementation 'org.mockito:mockito-core:3.3.3'
testImplementation 'org.mockito:mockito-core:4.5.1'
testImplementation 'org.json:json:20140107'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation 'org.robolectric:robolectric:4.8'
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.matomo.sdk.QueryParams;
import org.matomo.sdk.TrackMe;
import org.matomo.sdk.tools.Connectivity;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
Expand Down Expand Up @@ -85,12 +85,12 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
List<Event> drainTarget = invocation.getArgument(0);
mEventCacheData.drainTo(drainTarget);
return null;
}).when(mEventCache).drainTo(Matchers.anyList());
}).when(mEventCache).drainTo(ArgumentMatchers.anyList());
doAnswer(invocation -> {
List<Event> toRequeue = invocation.getArgument(0);
mEventCacheData.addAll(toRequeue);
return null;
}).when(mEventCache).requeue(Matchers.anyList());
}).when(mEventCache).requeue(ArgumentMatchers.anyList());
doAnswer(invocation -> {
mEventCacheData.clear();
return null;
Expand Down Expand Up @@ -148,14 +148,14 @@ public void testDispatchMode_wifiOnly() throws Exception {
mDispatcher.forceDispatch();

verify(mEventCache, timeout(1000)).updateState(false);
verify(mEventCache, never()).drainTo(Matchers.anyList());
verify(mEventCache, never()).drainTo(ArgumentMatchers.anyList());

when(mConnectivity.getType()).thenReturn(Connectivity.Type.WIFI);
mDispatcher.forceDispatch();
await().atMost(1, TimeUnit.SECONDS).until(() -> dryRunData.size(), is(1));

verify(mEventCache).updateState(true);
verify(mEventCache).drainTo(Matchers.anyList());
verify(mEventCache).drainTo(ArgumentMatchers.anyList());
}

@Test
Expand All @@ -168,7 +168,7 @@ public void testConnectivityChange() throws Exception {
mDispatcher.forceDispatch();

verify(mEventCache, timeout(1000)).add(any());
verify(mEventCache, never()).drainTo(Matchers.anyList());
verify(mEventCache, never()).drainTo(ArgumentMatchers.anyList());
assertThat(dryRunData.size(), is(0));

when(mConnectivity.isConnected()).thenReturn(true);
Expand All @@ -177,7 +177,7 @@ public void testConnectivityChange() throws Exception {
await().atMost(1, TimeUnit.SECONDS).until(() -> dryRunData.size(), is(1));

verify(mEventCache).updateState(true);
verify(mEventCache).drainTo(Matchers.anyList());
verify(mEventCache).drainTo(ArgumentMatchers.anyList());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.matomo.sdk.extra;

import org.apache.maven.artifact.ant.shaded.StringUtils;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to remove this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me2, weird to have that 😁

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
Expand All @@ -10,6 +9,7 @@
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Arrays;
import java.util.Collections;

import testhelpers.BaseTest;

Expand Down Expand Up @@ -77,9 +77,10 @@ public void testToStringJSON() throws Exception {
@Test
public void testTrimLongValue() throws Exception {
CustomVariables cv = new CustomVariables();
String multipleA = String.join("", Collections.nCopies(CustomVariables.MAX_LENGTH + 41, "a"));
String multipleB = String.join("", Collections.nCopies(CustomVariables.MAX_LENGTH + 100, "B"));

cv.put(1, StringUtils.repeat("a", CustomVariables.MAX_LENGTH + 41),
StringUtils.repeat("b", CustomVariables.MAX_LENGTH + 100));
cv.put(1, multipleA, multipleB);

assertEquals(cv.toString().length(), 13 + CustomVariables.MAX_LENGTH * 2); // 13 + 200x2
}
Expand Down