run Android Studio default code formatter with Ctrl-Alt-L
This commit is contained in:
parent
3cb6cc747b
commit
a81140be47
@ -34,7 +34,6 @@ import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable.Cols;
|
||||
import org.fdroid.fdroid.net.TreeUriDownloader;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@ -270,8 +269,7 @@ public class Repo extends ValueObject {
|
||||
return tempName;
|
||||
}
|
||||
|
||||
public String getFileUrl(String... pathElements)
|
||||
{
|
||||
public String getFileUrl(String... pathElements) {
|
||||
/* Each String in pathElements might contain a /, should keep these as path elements */
|
||||
List<String> elements = new ArrayList();
|
||||
for (String element : pathElements) {
|
||||
@ -299,13 +297,12 @@ public class Repo extends ValueObject {
|
||||
} else { // Normal URL
|
||||
Uri.Builder result = Uri.parse(address).buildUpon();
|
||||
for (String element : elements) {
|
||||
result.appendPath((element));
|
||||
result.appendPath(element);
|
||||
}
|
||||
return result.build().toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int toInt(Integer value) {
|
||||
if (value == null) {
|
||||
return 0;
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Senecto Limited
|
||||
* Copyright (C) 2021 Angus Gratton
|
||||
* Copyright (C) 2018 Senecto Limited
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -15,35 +16,26 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.fdroid.fdroid;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.FDroidProviderTest;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
import org.fdroid.fdroid.mock.MockApk;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.fdroid.fdroid.data.Schema.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class RepoUrlsTest extends FDroidProviderTest {
|
||||
private static final String TAG = "RepoUrlsTest";
|
||||
public static final String TAG = "RepoUrlsTest";
|
||||
|
||||
/** Private class describing a repository URL we're going to test, and
|
||||
/**
|
||||
* Private class describing a repository URL we're going to test, and
|
||||
* the file pattern for any files within that URL.
|
||||
*/
|
||||
private static class TestRepo {
|
||||
@ -52,8 +44,7 @@ public class RepoUrlsTest extends FDroidProviderTest {
|
||||
// String format pattern for generating file URLs, should contain a single %s for the filename
|
||||
public String fileUrlPattern;
|
||||
|
||||
public TestRepo(String repoUrl, String fileUrlPattern)
|
||||
{
|
||||
TestRepo(String repoUrl, String fileUrlPattern) {
|
||||
this.repoUrl = repoUrl;
|
||||
this.fileUrlPattern = fileUrlPattern;
|
||||
}
|
||||
@ -61,7 +52,7 @@ public class RepoUrlsTest extends FDroidProviderTest {
|
||||
|
||||
private static final String APK_NAME = "test-v1.apk";
|
||||
|
||||
private static final TestRepo REPOS[] = {
|
||||
private static final TestRepo[] REPOS = {
|
||||
new TestRepo(
|
||||
"https://microg.org/fdroid/repo",
|
||||
"https://microg.org/fdroid/repo/%s"),
|
||||
@ -100,19 +91,20 @@ public class RepoUrlsTest extends FDroidProviderTest {
|
||||
Preferences.setupForTests(context);
|
||||
}
|
||||
|
||||
interface getFileFromRepo {
|
||||
interface GetFileFromRepo {
|
||||
String get(TestRepo tr);
|
||||
}
|
||||
|
||||
/** Utility test function - go through the list of test repos,
|
||||
/**
|
||||
* Utility test function - go through the list of test repos,
|
||||
* using the useOfRepo interface to instantiate a repo from the URL
|
||||
* and return a file of some kind (Apk, index, etc.) and check that
|
||||
* it matches the test repo's expected URL format.
|
||||
*
|
||||
* @param fileName File that 'useOfRepo' will return in the repo, when called
|
||||
* @param useOfRepo Instance of the function that uses the repo to build a file URL
|
||||
*/
|
||||
private void testReposWithFile(String fileName, getFileFromRepo useOfRepo)
|
||||
{
|
||||
private void testReposWithFile(String fileName, GetFileFromRepo useOfRepo) {
|
||||
for (TestRepo tr : REPOS) {
|
||||
String expectedUrl = String.format(tr.fileUrlPattern, fileName);
|
||||
System.out.println("Testing URL " + expectedUrl);
|
||||
@ -122,9 +114,8 @@ public class RepoUrlsTest extends FDroidProviderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexUrls()
|
||||
{
|
||||
testReposWithFile(IndexUpdater.SIGNED_FILE_NAME, new getFileFromRepo() {
|
||||
public void testIndexUrls() {
|
||||
testReposWithFile(IndexUpdater.SIGNED_FILE_NAME, new GetFileFromRepo() {
|
||||
@Override
|
||||
public String get(TestRepo tr) {
|
||||
Repo repo = new Repo();
|
||||
@ -136,9 +127,8 @@ public class RepoUrlsTest extends FDroidProviderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexV1Urls()
|
||||
{
|
||||
testReposWithFile(IndexV1Updater.SIGNED_FILE_NAME, new getFileFromRepo() {
|
||||
public void testIndexV1Urls() {
|
||||
testReposWithFile(IndexV1Updater.SIGNED_FILE_NAME, new GetFileFromRepo() {
|
||||
@Override
|
||||
public String get(TestRepo tr) {
|
||||
Repo repo = new Repo();
|
||||
@ -150,9 +140,8 @@ public class RepoUrlsTest extends FDroidProviderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApkUrls()
|
||||
{
|
||||
testReposWithFile(APK_NAME, new getFileFromRepo() {
|
||||
public void testApkUrls() {
|
||||
testReposWithFile(APK_NAME, new GetFileFromRepo() {
|
||||
@Override
|
||||
public String get(TestRepo tr) {
|
||||
Apk apk = new MockApk(APK_NAME, 1, tr.repoUrl, APK_NAME);
|
||||
|
Loading…
x
Reference in New Issue
Block a user