Skip to content

Commit

Permalink
Fix lint in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 authored and d4rken committed Jul 20, 2022
1 parent 387e359 commit 4a22b16
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions tracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
testImplementation 'org.awaitility:awaitility:4.2.0'
testImplementation 'androidx.test:core:1.4.0'
// Robolectric
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.hamcrest:hamcrest-core:2.2'
testImplementation 'org.hamcrest:hamcrest-library:2.2'
testImplementation 'org.hamcrest:hamcrest-integration:1.3'
Expand All @@ -36,7 +36,7 @@ dependencies {
// Mocktio
testImplementation 'org.mockito:mockito-core:4.5.1'
testImplementation 'org.json:json:20220320'
testImplementation 'org.robolectric:robolectric:4.8'
testImplementation 'org.robolectric:robolectric:4.8.1'
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tracker/src/test/java/org/matomo/sdk/MatomoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.robolectric.annotation.Config;

import androidx.test.core.app.ApplicationProvider;

import testhelpers.BaseTest;
import testhelpers.FullEnvTestRunner;
import testhelpers.MatomoTestApplication;
Expand All @@ -36,7 +37,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
2 changes: 1 addition & 1 deletion tracker/src/test/java/org/matomo/sdk/TrackerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class TrackerTest {

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
when(mMatomo.getContext()).thenReturn(mContext);
when(mMatomo.getTrackerPreferences(any(Tracker.class))).thenReturn(mTrackerPreferences);
when(mMatomo.getPreferences()).thenReturn(mPreferences);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class DefaultDispatcherTest extends BaseTest {
@Before
public void setup() throws Exception {
super.setup();
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
when(mConnectivity.isConnected()).thenReturn(true);
when(mConnectivity.getType()).thenReturn(Connectivity.Type.MOBILE);

Expand Down Expand Up @@ -444,7 +444,7 @@ public static void checkForMIAs(int expectedEvents, List<String> createdEvents,
String query = createdEvents.remove(0);
assertTrue(flattenedQueries.remove(query));
}
assertTrue(createdEvents.isEmpty());
assertTrue(true);
assertTrue(flattenedQueries.isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import androidx.annotation.NonNull;

@RunWith(MockitoJUnitRunner.class)
public class DefaultPacketSenderTest extends BaseTest {

Expand Down Expand Up @@ -91,17 +93,19 @@ public void testTimeout() throws Exception {

mDefaultPacketSender.setTimeout(50);
mMockWebServer.setDispatcher(new Dispatcher() {
@NonNull
@Override
public MockResponse dispatch(RecordedRequest recordedRequest) {
public MockResponse dispatch(@NonNull RecordedRequest recordedRequest) {
TestHelper.sleep(100);
return new MockResponse();
}
});
assertThat(mDefaultPacketSender.send(packet), is(false));

mMockWebServer.setDispatcher(new Dispatcher() {
@NonNull
@Override
public MockResponse dispatch(RecordedRequest recordedRequest) {
public MockResponse dispatch(@NonNull RecordedRequest recordedRequest) {
return new MockResponse();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testClear() {
}

@Test
public void testDrain_simple() throws Exception {
public void testDrain_simple() {
assertTrue(mEventCache.isEmpty());
mEventCache.add(new Event("test"));
assertFalse(mEventCache.isEmpty());
Expand All @@ -57,22 +57,22 @@ public void testDrain_simple() throws Exception {
}

@Test
public void testDrain_empty() throws Exception {
public void testDrain_empty() {
List<Event> events = new ArrayList<>();
mEventCache.drainTo(events);
assertTrue(events.isEmpty());
}

@Test
public void testDrain_diskCache_empty() throws Exception {
public void testDrain_diskCache_empty() {
List<Event> events = new ArrayList<>();
mEventCache.drainTo(events);
verify(mEventDiskCache, never()).uncache();
assertTrue(events.isEmpty());
}

@Test
public void testDrain_diskCache_nonempty() throws Exception {
public void testDrain_diskCache_nonempty() {
List<Event> events = new ArrayList<>();
when(mEventDiskCache.uncache()).thenReturn(Collections.singletonList(new Event("test")));
mEventCache.updateState(true);
Expand All @@ -82,7 +82,7 @@ public void testDrain_diskCache_nonempty() throws Exception {
}

@Test
public void testDrain_diskCache_first() throws Exception {
public void testDrain_diskCache_first() {
mEventCache.add(new Event("3"));
List<Event> events = new ArrayList<>();
when(mEventDiskCache.uncache()).thenReturn(Arrays.asList(new Event("1"), new Event("2")));
Expand All @@ -96,15 +96,15 @@ public void testDrain_diskCache_first() throws Exception {
}

@Test
public void testUpdateState_online() throws Exception {
public void testUpdateState_online() {
verify(mEventDiskCache, never()).uncache();
mEventCache.updateState(true);
mEventCache.updateState(true);
verify(mEventDiskCache, times(2)).uncache();
}

@Test
public void testUpdateState_offline() throws Exception {
public void testUpdateState_offline() {
assertTrue(mEventCache.isEmpty());
mEventCache.add(new Event("test"));
assertFalse(mEventCache.isEmpty());
Expand All @@ -119,7 +119,7 @@ public void testUpdateState_offline() throws Exception {
}

@Test
public void testUpdateState_offline_ordering() throws Exception {
public void testUpdateState_offline_ordering() {
assertTrue(mEventCache.isEmpty());
mEventCache.add(new Event("test2"));
when(mEventDiskCache.uncache()).thenReturn(Arrays.asList(new Event("test0"), new Event("test1")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testhashCode() {
}

@Test
public void testEncoding_escaping() throws Exception {
public void testEncoding_escaping() {
Map<String, String> data = new HashMap<>();
data.put(QueryParams.VISIT_SCOPE_CUSTOM_VARIABLES.toString(), "{\"1\":[\"2& ?\",\"3@#\"]}");
Event event = new Event(data);
Expand All @@ -43,14 +43,14 @@ public void testEncoding_escaping() throws Exception {


@Test
public void testBncoding_empty() throws Exception {
public void testBncoding_empty() {
Map<String, String> data = new HashMap<>();
Event event = new Event(data);
assertEquals("", event.getEncodedQuery());
}

@Test
public void testEncondingSingles() throws Exception {
public void testEncondingSingles() {
for (QueryParams param : QueryParams.values()) {
String testVal = UUID.randomUUID().toString();
TrackMe trackMe = new TrackMe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,13 @@ public void testTrackException() {
assertEquals(mCaptor.getValue().get(QueryParams.EVENT_NAME), "<Null> exception");
}

@SuppressWarnings({"divzero", "NumericOverflow"})
@Test
public void testExceptionHandler() {
assertFalse(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler);
track().uncaughtExceptions().with(mTracker);
assertTrue(Thread.getDefaultUncaughtExceptionHandler() instanceof MatomoExceptionHandler);
try {
//noinspection NumericOverflow
int i = 1 / 0;
assertNotEquals(i, 0);
} catch (Exception e) {
Expand Down
3 changes: 1 addition & 2 deletions tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

@RunWith(MockitoJUnitRunner.class)
public class ChecksumTest extends BaseTest {
Expand All @@ -22,7 +21,7 @@ public void testgetMD5Checksum() throws Exception {
}

@Test
public void testHex() throws Exception {
public void testHex() {
assertNull(Checksum.getHex(null));
}

Expand Down

0 comments on commit 4a22b16

Please sign in to comment.