Skip to content

Commit

Permalink
Revert "BraveNewPipe: test getAlternativeUrlOnKitkat() instead checkF…
Browse files Browse the repository at this point in the history
…orAlternativeApkUrl()"

This reverts commit bd02dc8.
-> we no longer support KitKat
evermind-zz committed Jun 6, 2023
1 parent bd2655d commit 27194d6
Showing 1 changed file with 9 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package org.schabi.newpipe.brave;

import android.os.Build;

import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import static org.junit.Assert.assertEquals;


@@ -25,61 +21,36 @@ public void setUp() throws Exception {
public void tearDown() throws Exception {
}

private static void setFinalStatic(final Field field, final Object newValue) throws Exception {
field.setAccessible(true);

final Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

field.set(null, newValue);
}

@SuppressWarnings({"checkstyle:LineLength", "checkstyle:MethodName"})
@Test
public void checkJsonDataWith_alternative_apks() throws Exception {
public void checkJsonConfigWith_alternative_apks() throws JsonParserException {
final String stdUrl = "stdUrl";
final String expectedAltUrl = "altUrl";

final String withAltJSON = "{\"flavors\":{\"github\":{\"stable\":{\"apk\":\"" + stdUrl + "\","
final String altConfig = "{\"flavors\":{\"github\":{\"stable\":{\"apk\":\"" + stdUrl + "\","
+ "\"alternative_apks\":[{\"alternative\":\"conscrypt\",\"url\":\"" + expectedAltUrl + "\"}],"
+ "\"version\":\"1\",\"version_code\":1}}}}";

final JsonObject obj = JsonParser.object().from(withAltJSON).getObject("flavors")
final JsonObject obj = JsonParser.object().from(altConfig).getObject("flavors")
.getObject("github").getObject("stable");
final String result = NewVersionHelper.checkForAlternativeApkUrl(obj, stdUrl);

// 1. test simulating running on KitKat
setFinalStatic(Build.VERSION.class.getField("SDK_INT"), 19);
String result = NewVersionHelper.getAlternativeUrlOnKitkat(obj, stdUrl);
assertEquals(expectedAltUrl, result);

// 2. test simulating running > KitKat
setFinalStatic(Build.VERSION.class.getField("SDK_INT"), 21);
result = NewVersionHelper.getAlternativeUrlOnKitkat(obj, stdUrl);
assertEquals(stdUrl, result);
}

@SuppressWarnings({"checkstyle:LineLength", "checkstyle:MethodName"})
@Test
public void checkJsonDataWithout_alternative_apks() throws Exception {
public void checkJsonConfigWithout_alternative_apks() throws JsonParserException {
final String stdUrl = "stdUrl";
final String expectedStdUrl = stdUrl;

final String withoutAltJSON = "{\"flavors\":{\"github\":{\"stable\":{\"apk\":\"" + stdUrl + "\","
final String altConfig = "{\"flavors\":{\"github\":{\"stable\":{\"apk\":\"" + stdUrl + "\","
+ "\"version\":\"1\",\"version_code\":1}}}}";

final JsonObject obj = JsonParser.object().from(withoutAltJSON).getObject("flavors")
final JsonObject obj = JsonParser.object().from(altConfig).getObject("flavors")
.getObject("github").getObject("stable");
final String result = NewVersionHelper.checkForAlternativeApkUrl(obj, stdUrl);


// 1. test simulating running on KitKat
setFinalStatic(Build.VERSION.class.getField("SDK_INT"), 19);
String result = NewVersionHelper.getAlternativeUrlOnKitkat(obj, stdUrl);
assertEquals(expectedStdUrl, result);

// 2. test simulating running > KitKat
setFinalStatic(Build.VERSION.class.getField("SDK_INT"), 21);
result = NewVersionHelper.getAlternativeUrlOnKitkat(obj, stdUrl);
assertEquals(stdUrl, result);
}
}

0 comments on commit 27194d6

Please sign in to comment.