Appease checkstyle for test code.
Like PMD, we also had to add a concession to allow static imports. This time, it was achieved by moving the assertions to a more generally named `Assert` class, and then allowing static imports from that.
This commit is contained in:
parent
4e73d1e5e6
commit
53e74dcdbd
@ -1,4 +1,4 @@
|
||||
package org.fdroid.fdroid.data;
|
||||
package org.fdroid.fdroid;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
@ -6,6 +6,9 @@ import android.net.Uri;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.InstalledAppProvider;
|
||||
import org.robolectric.shadows.ShadowContentResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -17,7 +20,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class ProviderTestUtils {
|
||||
public class Assert {
|
||||
|
||||
public static <T extends Comparable> void assertContainsOnly(List<T> actualList, T[] expectedArray) {
|
||||
List<T> expectedList = new ArrayList<>(expectedArray.length);
|
@ -20,12 +20,12 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.fdroid.fdroid.TestUtils.copyResourceToTempFile;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = "AcceptableMultiRepoUpdaterTest"; // NOPMD
|
||||
|
||||
protected static final String REPO_MAIN = "Test F-Droid repo";
|
||||
@ -187,7 +187,7 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||
}
|
||||
|
||||
private boolean updateRepo(RepoUpdater updater, String indexJarPath) throws UpdateException {
|
||||
File indexJar = copyResourceToTempFile(indexJarPath);
|
||||
File indexJar = TestUtils.copyResourceToTempFile(indexJarPath);
|
||||
try {
|
||||
updater.processDownloadedFile(indexJar);
|
||||
} finally {
|
||||
|
@ -8,4 +8,6 @@ import android.app.Application;
|
||||
* {@link Application} instead of {@link FDroidApp}. It intentionally doesn't extends {@link FDroidApp}
|
||||
* so that the static initialization in {@link FDroidApp#onCreate()} is not executed.
|
||||
*/
|
||||
public class TestFDroidApp extends Application {}
|
||||
public class TestFDroidApp extends Application {
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.fdroid.fdroid.Assert;
|
||||
import org.fdroid.fdroid.BuildConfig;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.mock.MockApk;
|
||||
@ -20,9 +21,9 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertCantDelete;
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertContainsOnly;
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertResultCount;
|
||||
import static org.fdroid.fdroid.Assert.assertCantDelete;
|
||||
import static org.fdroid.fdroid.Assert.assertContainsOnly;
|
||||
import static org.fdroid.fdroid.Assert.assertResultCount;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@ -37,8 +38,8 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
@Test
|
||||
public void testAppApks() {
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.fdroid.fdroid", i);
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.example", i);
|
||||
Assert.insertApk(contentResolver, "org.fdroid.fdroid", i);
|
||||
Assert.insertApk(contentResolver, "com.example", i);
|
||||
}
|
||||
|
||||
assertTotalApkCount(20);
|
||||
@ -186,7 +187,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
Apk apk = new MockApk("org.fdroid.fdroid", 13);
|
||||
|
||||
// Insert a new record...
|
||||
Uri newUri = ProviderTestUtils.insertApk(contentResolver, apk.packageName, apk.versionCode);
|
||||
Uri newUri = Assert.insertApk(contentResolver, apk.packageName, apk.versionCode);
|
||||
assertEquals(ApkProvider.getContentUri(apk).toString(), newUri.toString());
|
||||
cursor = queryAllApks();
|
||||
assertNotNull(cursor);
|
||||
@ -204,7 +205,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCursorMustMoveToFirst() {
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.example.test", 12);
|
||||
Assert.insertApk(contentResolver, "org.example.test", 12);
|
||||
Cursor cursor = queryAllApks();
|
||||
new Apk(cursor);
|
||||
}
|
||||
@ -214,7 +215,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
String[] projectionCount = new String[] {ApkProvider.DataColumns._COUNT};
|
||||
|
||||
for (int i = 0; i < 13; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.example", i);
|
||||
Assert.insertApk(contentResolver, "com.example", i);
|
||||
}
|
||||
|
||||
Uri all = ApkProvider.getContentUri();
|
||||
@ -259,7 +260,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
public void assertInvalidExtraField(String field) {
|
||||
ContentValues invalidRepo = new ContentValues();
|
||||
invalidRepo.put(field, "Test data");
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.fdroid.fdroid", 10, invalidRepo);
|
||||
Assert.insertApk(contentResolver, "org.fdroid.fdroid", 10, invalidRepo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -272,7 +273,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
values.put(ApkProvider.DataColumns.REPO_ADDRESS, "http://example.com");
|
||||
values.put(ApkProvider.DataColumns.REPO_VERSION, 3);
|
||||
values.put(ApkProvider.DataColumns.FEATURES, "Some features");
|
||||
Uri uri = ProviderTestUtils.insertApk(contentResolver, "com.example.com", 1, values);
|
||||
Uri uri = Assert.insertApk(contentResolver, "com.example.com", 1, values);
|
||||
|
||||
assertResultCount(1, queryAllApks());
|
||||
|
||||
@ -298,18 +299,18 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
public void testKnownApks() {
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.fdroid.fdroid", i);
|
||||
Assert.insertApk(contentResolver, "org.fdroid.fdroid", i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.example", i);
|
||||
Assert.insertApk(contentResolver, "org.example", i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.example", i);
|
||||
Assert.insertApk(contentResolver, "com.example", i);
|
||||
}
|
||||
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.apk.thingo", 1);
|
||||
Assert.insertApk(contentResolver, "com.apk.thingo", 1);
|
||||
|
||||
Apk[] known = {
|
||||
new MockApk("org.fdroid.fdroid", 1),
|
||||
@ -356,18 +357,18 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
public void testFindByApp() {
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.fdroid.fdroid", i);
|
||||
Assert.insertApk(contentResolver, "org.fdroid.fdroid", i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.example", i);
|
||||
Assert.insertApk(contentResolver, "org.example", i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.example", i);
|
||||
Assert.insertApk(contentResolver, "com.example", i);
|
||||
}
|
||||
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.apk.thingo", 1);
|
||||
Assert.insertApk(contentResolver, "com.apk.thingo", 1);
|
||||
|
||||
assertTotalApkCount(7 + 9 + 3 + 1);
|
||||
|
||||
@ -391,7 +392,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
|
||||
Uri apkUri = ProviderTestUtils.insertApk(contentResolver, "com.example", 10);
|
||||
Uri apkUri = Assert.insertApk(contentResolver, "com.example", 10);
|
||||
|
||||
String[] allFields = ApkProvider.DataColumns.ALL;
|
||||
Cursor cursor = contentResolver.query(apkUri, allFields, null, null, null);
|
||||
@ -447,18 +448,18 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
// the Helper.find() method doesn't stumble upon the app we are interested
|
||||
// in by shear dumb luck...
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "org.fdroid.apk." + i, i);
|
||||
Assert.insertApk(contentResolver, "org.fdroid.apk." + i, i);
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ApkProvider.DataColumns.VERSION_NAME, "v1.1");
|
||||
values.put(ApkProvider.DataColumns.HASH, "xxxxyyyy");
|
||||
values.put(ApkProvider.DataColumns.HASH_TYPE, "a hash type");
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.example", 11, values);
|
||||
Assert.insertApk(contentResolver, "com.example", 11, values);
|
||||
|
||||
// ...and a few more for good measure...
|
||||
for (int i = 15; i < 20; i++) {
|
||||
ProviderTestUtils.insertApk(contentResolver, "com.other.thing." + i, i);
|
||||
Assert.insertApk(contentResolver, "com.other.thing." + i, i);
|
||||
}
|
||||
|
||||
Apk apk = ApkProvider.Helper.find(context, "com.example", 11);
|
||||
@ -507,7 +508,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
fail("Apk [" + apk + "] not found in " + ProviderTestUtils.listToString(apks));
|
||||
fail("Apk [" + apk + "] not found in " + Assert.listToString(apks));
|
||||
}
|
||||
}
|
||||
|
||||
@ -534,7 +535,7 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
protected Apk insertApkForRepo(String id, int versionCode, long repoId) {
|
||||
ContentValues additionalValues = new ContentValues();
|
||||
additionalValues.put(ApkProvider.DataColumns.REPO_ID, repoId);
|
||||
Uri uri = ProviderTestUtils.insertApk(contentResolver, id, versionCode, additionalValues);
|
||||
Uri uri = Assert.insertApk(contentResolver, id, versionCode, additionalValues);
|
||||
return ApkProvider.Helper.get(context, uri);
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ import org.robolectric.shadows.ShadowContentResolver;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertContainsOnly;
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertResultCount;
|
||||
import static org.fdroid.fdroid.Assert.assertContainsOnly;
|
||||
import static org.fdroid.fdroid.Assert.assertResultCount;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@ -253,7 +253,7 @@ public class AppProviderTest extends FDroidProviderTest {
|
||||
String[] projection = new String[] {
|
||||
AppProvider.DataColumns._ID,
|
||||
AppProvider.DataColumns.NAME,
|
||||
AppProvider.DataColumns.PACKAGE_NAME
|
||||
AppProvider.DataColumns.PACKAGE_NAME,
|
||||
};
|
||||
return contentResolver.query(AppProvider.getContentUri(), projection, null, null, null);
|
||||
}
|
||||
@ -366,8 +366,4 @@ public class AppProviderTest extends FDroidProviderTest {
|
||||
|
||||
contentResolver.insert(uri, values);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// https://github.com/robolectric/robolectric/wiki/2.4-to-3.0-Upgrade-Guide
|
||||
|
@ -35,5 +35,4 @@ public abstract class FDroidProviderTest {
|
||||
FDroidProvider.clearDbHelperSingleton();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowContentResolver;
|
||||
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertIsInstalledVersionInDb;
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertResultCount;
|
||||
import static org.fdroid.fdroid.Assert.assertIsInstalledVersionInDb;
|
||||
import static org.fdroid.fdroid.Assert.assertResultCount;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -15,8 +15,8 @@ import org.robolectric.shadows.ShadowContentResolver;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertInvalidUri;
|
||||
import static org.fdroid.fdroid.data.ProviderTestUtils.assertValidUri;
|
||||
import static org.fdroid.fdroid.Assert.assertInvalidUri;
|
||||
import static org.fdroid.fdroid.Assert.assertValidUri;
|
||||
|
||||
@Config(constants = BuildConfig.class)
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
|
@ -33,7 +33,7 @@
|
||||
<module name="AvoidStarImport" />
|
||||
<module name="AvoidStaticImport">
|
||||
<property name="excludes"
|
||||
value="org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo" />
|
||||
value="org.fdroid.fdroid.Assert.*, org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo" />
|
||||
</module>
|
||||
<module name="RedundantImport" />
|
||||
<module name="UnusedImports" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user