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

Use checkstyle to forbid JUnit 3 and some other internal packages. #114

Merged
merged 4 commits into from
Sep 3, 2014
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
16 changes: 15 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,23 @@
<!-- Checks for imports. -->
<!-- See http://checkstyle.sourceforge.net/config_imports.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!-- Default sun.* packages -->
<module name="IllegalImport">
<property name="illegalPkgs" value="sun" />
<message key="import.illegal" value="Import from illegal package - {0}. Programs that contain direct calls to the sun.* packages are not 100% Pure Java." />
</module>
<!-- Prevent importing JUnit 3 classes and Assert methods -->
<module name="IllegalImport">
<property name="illegalPkgs" value="junit" />
<message key="import.illegal" value="Import from illegal package - {0}. Tests are written in JUnit 4, use org.junit.* equivalents." />
</module>
<!-- Prevent importing Mockito matchers directly -->
<module name="IllegalImport">
<property name="illegalPkgs" value="org.mockito.internal" />
<message key="import.illegal" value="Import from illegal package - {0}. Use org.mockito.Matchers to instantiate argument matchers; or org.hamcrest.Matchers for assertThat." />
</module>

<!-- Checks for whitespace. -->
<!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
compile project(':third_party:disklrucache')
compile 'com.android.support:support-v4:19.1.+'
androidTestCompile 'org.hamcrest:hamcrest-core:1.3'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'junit:junit:4.11'
androidTestCompile 'org.mockito:mockito-all:1.9.5'
androidTestCompile 'org.robolectric:robolectric:2.4-SNAPSHOT'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

@RunWith(RobolectricTestRunner.class)
Expand Down Expand Up @@ -73,7 +75,7 @@ public void testGetItemsIsCalledDecreasing() {
protected List<Object> getItems(int start, int end) {
// Ignore the preload caused from us starting at the end
if (start == 40) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
called.set(true);
assertEquals(19, start);
Expand Down Expand Up @@ -104,7 +106,7 @@ protected int[] getDimensions(Object item) {
@Override
protected List getItems(int start, int end) {
if (start == 40) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
return objects;
}
Expand Down Expand Up @@ -144,7 +146,7 @@ public void testGetItemsIsNeverCalledWithStartLessThanZero() {
@Override
protected List<Object> getItems(int start, int end) {
if (start == 17) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
called.set(true);
assertEquals(0, start);
Expand Down Expand Up @@ -188,7 +190,7 @@ public void testDontPreloadItemsRepeatedlyWhileDecreasing() {
@Override
protected List<Object> getItems(int start, int end) {
if (start == 30) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
final int current = called.getAndIncrement();
if (current == 0) {
Expand Down Expand Up @@ -229,10 +231,7 @@ protected GenericRequestBuilder getRequestBuilder(Object item) {

preloader.onScroll(null, 1, 10, 30);

assertEquals(objects.size(), loadedObjects.size());
for (Object object : objects) {
assertTrue(loadedObjects.contains(object));
}
assertThat(loadedObjects, containsInAnyOrder(objects.toArray()));
}

private static class ListPreloaderAdapter extends ListPreloader<Object> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import java.net.URL;

import static com.bumptech.glide.tests.BackgroundUtil.testInBackground;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.ArrayList;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
Expand Down Expand Up @@ -87,10 +88,10 @@ public void testDoesNotThrowIfCleanupWithNullInputStream() {
@Test
public void testContainsAllRelevantPartsInId() {
String id = harness.get().getId();
assertTrue(id.contains(harness.uri.toString()));
assertTrue(id.contains(harness.mimeType));
assertTrue(id.contains(String.valueOf(harness.dateModified)));
assertTrue(id.contains(String.valueOf(harness.orientation)));
assertThat(id, containsString(harness.uri.toString()));
assertThat(id, containsString(harness.mimeType));
assertThat(id, containsString(String.valueOf(harness.dateModified)));
assertThat(id, containsString(String.valueOf(harness.orientation)));
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.io.InputStream;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;

public class ByteArrayFetcherTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.io.InputStream;

import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertNotNull;

@RunWith(RobolectricTestRunner.class)
public class StreamLocalUriFetcherTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.io.File;
import java.io.IOException;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.File;
import java.util.concurrent.ExecutorService;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;

@RunWith(RobolectricTestRunner.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bumptech.glide.load.engine;

import com.bumptech.glide.load.Key;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -10,6 +9,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void run() {
} catch (IllegalThreadStateException e) {
return;
}
Assert.fail("Failed to receive expected IllegalThreadStateException");
fail("Failed to receive expected IllegalThreadStateException");
}
});
otherThread.start();
Expand All @@ -121,7 +121,7 @@ public void run() {
} catch (IllegalThreadStateException e) {
return;
}
Assert.fail("Failed to receive expected IllegalThreadStateException");
fail("Failed to receive expected IllegalThreadStateException");
}
});
otherThread.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
import java.util.Map;
import java.util.concurrent.ExecutorService;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
Expand Down Expand Up @@ -89,7 +93,7 @@ public void testEngineJobReceivesRemoveCallbackFromLoadStatus() {
public void testNewRunnerIsAddedToRunnersMap() {
harness.doLoad();

assertTrue(harness.runners.containsKey(harness.cacheKey));
assertThat(harness.runners, hasKey((Key) harness.cacheKey));
}

@Test
Expand Down Expand Up @@ -135,7 +139,7 @@ public void testResourceIsNotReturnedFromActiveResourcesIfRefIsCleared() {

harness.doLoad();

verify(harness.cb, never()).onResourceReady((Resource) isNull());
verify(harness.cb, never()).onResourceReady(isNull(Resource.class));
}

@Test
Expand All @@ -144,7 +148,7 @@ public void testKeyIsRemovedFromActiveResourcesIfRefIsCleared() {

harness.doLoad();

assertFalse(harness.activeResources.containsKey(harness.cacheKey));
assertThat(harness.activeResources, not(hasKey((Key) harness.cacheKey)));
}

@Test
Expand Down Expand Up @@ -244,7 +248,7 @@ public void testRunnerIsRemovedFromRunnersOnEngineNotifiedJobComplete() {

harness.engine.onEngineJobComplete(harness.cacheKey, harness.resource);

assertFalse(harness.runners.containsKey(harness.cacheKey));
assertThat(harness.runners, not(hasKey((Key) harness.cacheKey)));
}

@Test
Expand Down Expand Up @@ -283,7 +287,7 @@ public void testResourceIsAddedToActiveResourcesOnEngineComplete() {
@Test
public void testDoesNotPutNullResourceInActiveResourcesOnEngineComplete() {
harness.engine.onEngineJobComplete(harness.cacheKey, null);
assertFalse(harness.activeResources.containsKey(harness.cacheKey));
assertThat(harness.activeResources, not(hasKey((Key) harness.cacheKey)));
}

@Test
Expand All @@ -292,7 +296,7 @@ public void testRunnerIsRemovedFromRunnersOnEngineNotifiedJobCancel() {

harness.engine.onEngineJobCancelled(harness.job, harness.cacheKey);

assertFalse(harness.runners.containsKey(harness.cacheKey));
assertThat(harness.runners, not(hasKey((Key) harness.cacheKey)));
}

@Test
Expand Down Expand Up @@ -354,7 +358,7 @@ public void testResourceIsRemovedFromActiveResourcesWhenReleased() {

harness.engine.onResourceReleased(harness.cacheKey, harness.resource);

assertFalse(harness.activeResources.containsKey(harness.cacheKey));
assertThat(harness.activeResources, not(hasKey((Key) harness.cacheKey)));
}

@Test
Expand All @@ -377,7 +381,7 @@ public void testResourceIsRecycledWhenRemovedFromCache() {
public void testRunnerIsPutInRunnersWithCacheKeyWithRelevantIds() {
harness.doLoad();

assertNotNull(harness.runners.get(harness.cacheKey));
assertThat(harness.runners, hasEntry(equalTo((Key) harness.cacheKey), notNullValue(ResourceRunner.class)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class OriginalEngineKeyTest {

Expand Down Expand Up @@ -43,6 +42,6 @@ public void testUpdatesDigestWithGivenId() throws NoSuchAlgorithmException, Unsu
secondKey.updateDiskCacheKey(secondDigest);
byte[] secondBytes = secondDigest.digest();

assertTrue(Arrays.equals(firstBytes, secondBytes));
assertArrayEquals(firstBytes, secondBytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowBitmap;

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

@RunWith(RobolectricTestRunner.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import static android.content.ComponentCallbacks2.TRIM_MEMORY_BACKGROUND;
import static android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE;
import static android.content.ComponentCallbacks2.TRIM_MEMORY_MODERATE;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(RobolectricTestRunner.class)
public class LruBitmapPoolTest {
Expand All @@ -43,7 +45,7 @@ public void testImmutableBitmapsAreNotAdded() {
Bitmap bitmap = createMutableBitmap();
Robolectric.shadowOf(bitmap).setMutable(false);
pool.put(bitmap);
assertEquals(0, strategy.bitmaps.size());
assertThat(strategy.bitmaps, empty());
}

@Test
Expand Down
Loading