Skip to content

Commit

Permalink
Fix tests and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Jul 10, 2022
1 parent e9a4654 commit 4036b8e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
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;
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

0 comments on commit 4036b8e

Please sign in to comment.