Skip to content

Commit 7216a32

Browse files
hannesa2d4rken
authored andcommitted
Fix tests and simplify
1 parent 838e33a commit 7216a32

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

tracker/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ dependencies {
3434
testImplementation 'com.squareup.okhttp3:mockwebserver:4.8.0'
3535

3636
// Mocktio
37-
testImplementation 'org.mockito:mockito-core:3.3.3'
37+
testImplementation 'org.mockito:mockito-core:4.5.1'
3838
testImplementation 'org.json:json:20140107'
39-
testImplementation 'org.robolectric:robolectric:4.3.1'
39+
testImplementation 'org.robolectric:robolectric:4.8'
4040
}
4141

4242
/**

tracker/src/test/java/org/matomo/sdk/dispatcher/DefaultDispatcherTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.matomo.sdk.QueryParams;
1515
import org.matomo.sdk.TrackMe;
1616
import org.matomo.sdk.tools.Connectivity;
17-
import org.mockito.Matchers;
17+
import org.mockito.ArgumentMatchers;
1818
import org.mockito.Mock;
1919
import org.mockito.MockitoAnnotations;
2020
import org.mockito.invocation.InvocationOnMock;
@@ -85,12 +85,12 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
8585
List<Event> drainTarget = invocation.getArgument(0);
8686
mEventCacheData.drainTo(drainTarget);
8787
return null;
88-
}).when(mEventCache).drainTo(Matchers.anyList());
88+
}).when(mEventCache).drainTo(ArgumentMatchers.anyList());
8989
doAnswer(invocation -> {
9090
List<Event> toRequeue = invocation.getArgument(0);
9191
mEventCacheData.addAll(toRequeue);
9292
return null;
93-
}).when(mEventCache).requeue(Matchers.anyList());
93+
}).when(mEventCache).requeue(ArgumentMatchers.anyList());
9494
doAnswer(invocation -> {
9595
mEventCacheData.clear();
9696
return null;
@@ -148,14 +148,14 @@ public void testDispatchMode_wifiOnly() throws Exception {
148148
mDispatcher.forceDispatch();
149149

150150
verify(mEventCache, timeout(1000)).updateState(false);
151-
verify(mEventCache, never()).drainTo(Matchers.anyList());
151+
verify(mEventCache, never()).drainTo(ArgumentMatchers.anyList());
152152

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

157157
verify(mEventCache).updateState(true);
158-
verify(mEventCache).drainTo(Matchers.anyList());
158+
verify(mEventCache).drainTo(ArgumentMatchers.anyList());
159159
}
160160

161161
@Test
@@ -168,7 +168,7 @@ public void testConnectivityChange() throws Exception {
168168
mDispatcher.forceDispatch();
169169

170170
verify(mEventCache, timeout(1000)).add(any());
171-
verify(mEventCache, never()).drainTo(Matchers.anyList());
171+
verify(mEventCache, never()).drainTo(ArgumentMatchers.anyList());
172172
assertThat(dryRunData.size(), is(0));
173173

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

179179
verify(mEventCache).updateState(true);
180-
verify(mEventCache).drainTo(Matchers.anyList());
180+
verify(mEventCache).drainTo(ArgumentMatchers.anyList());
181181
}
182182

183183
@Test

tracker/src/test/java/org/matomo/sdk/extra/CustomVariablesTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.matomo.sdk.extra;
22

3-
import org.apache.maven.artifact.ant.shaded.StringUtils;
43
import org.json.JSONArray;
54
import org.json.JSONObject;
65
import org.junit.Test;
@@ -10,6 +9,7 @@
109
import org.mockito.junit.MockitoJUnitRunner;
1110

1211
import java.util.Arrays;
12+
import java.util.Collections;
1313

1414
import testhelpers.BaseTest;
1515

@@ -77,9 +77,10 @@ public void testToStringJSON() throws Exception {
7777
@Test
7878
public void testTrimLongValue() throws Exception {
7979
CustomVariables cv = new CustomVariables();
80+
String multipleA = String.join("", Collections.nCopies(CustomVariables.MAX_LENGTH + 41, "a"));
81+
String multipleB = String.join("", Collections.nCopies(CustomVariables.MAX_LENGTH + 100, "B"));
8082

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

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

0 commit comments

Comments
 (0)