Skip to content

Commit

Permalink
Remove more legacy code following the drop of support for API 19
Browse files Browse the repository at this point in the history
Follow-up PR of #9020 and #9027
  • Loading branch information
MGaetan89 authored and utzcoz committed May 24, 2024
1 parent 98a8644 commit c51c71d
Show file tree
Hide file tree
Showing 74 changed files with 114 additions and 405 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ jobs:
api-level: [ 29, 34 ]

steps:
- name: Free disk space
uses: jlumbroso/free-disk-space@v1.3.1
with:
tool-cache: true
android: false

- uses: actions/checkout@v4

- name: Set up JDK 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
Expand Down Expand Up @@ -141,18 +140,8 @@ public boolean injectString(String str) throws InjectEventSecurityException {

@SuppressLint("InlinedApi")
@VisibleForTesting
@SuppressWarnings("deprecation")
static KeyCharacterMap getKeyCharacterMap() {
KeyCharacterMap keyCharacterMap = null;

// KeyCharacterMap.VIRTUAL_KEYBOARD is present from API11.
// For earlier APIs we use KeyCharacterMap.BUILT_IN_KEYBOARD
if (Build.VERSION.SDK_INT < 11) {
keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
} else {
keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
}
return keyCharacterMap;
return KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import static org.robolectric.Shadows.shadowOf;

import android.hardware.camera2.CameraCharacteristics;
import android.os.Build.VERSION_CODES;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;

/** Tests for {@link ShadowCameraCharacteristics}. */
@Config(minSdk = VERSION_CODES.LOLLIPOP)
@RunWith(AndroidJUnit4.class)
public class ShadowCameraCharacteristicsTest {

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

/** Tests for {@link ShadowCameraDeviceImpl}. */
@Config(minSdk = VERSION_CODES.LOLLIPOP)
@RunWith(AndroidJUnit4.class)
public final class ShadowCameraDeviceImplTest {
private static final String CAMERA_ID_0 = "cameraId0";
Expand Down Expand Up @@ -70,7 +69,7 @@ public void tearDown() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP, maxSdk = VERSION_CODES.Q)
@Config(maxSdk = VERSION_CODES.Q)
public void createCaptureRequest() throws CameraAccessException {
builder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
CaptureRequest request = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.robolectric.annotation.Config;

/** Tests for {@link ShadowCameraManager}. */
@Config(minSdk = VERSION_CODES.LOLLIPOP)
@RunWith(AndroidJUnit4.class)
public class ShadowCameraManagerTest {

Expand Down Expand Up @@ -174,7 +173,6 @@ public void testGetTorchModeCameraTorchModeSet() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void openCamera() throws CameraAccessException {
shadowOf(cameraManager).addCamera(CAMERA_ID_0, characteristics);

Expand All @@ -185,7 +183,6 @@ public void openCamera() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void triggerDisconnect() throws CameraAccessException {
shadowOf(cameraManager).addCamera(CAMERA_ID_0, characteristics);

Expand All @@ -202,7 +199,6 @@ public void triggerDisconnect() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void triggerDisconnect_noCameraOpen() throws CameraAccessException {
shadowOf(cameraManager).addCamera(CAMERA_ID_0, characteristics);
shadowOf(cameraManager).triggerDisconnect();
Expand Down Expand Up @@ -264,7 +260,6 @@ public void resetter_closesCameras() throws Exception {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void registerCallbackAvailable() throws CameraAccessException {
CameraManager.AvailabilityCallback mockCallback =
mock(CameraManager.AvailabilityCallback.class);
Expand All @@ -276,7 +271,6 @@ public void registerCallbackAvailable() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void unregisterCallbackAvailable() throws CameraAccessException {
CameraManager.AvailabilityCallback mockCallback =
mock(CameraManager.AvailabilityCallback.class);
Expand All @@ -292,7 +286,6 @@ public void unregisterCallbackAvailable() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void registerCallbackUnavailable() throws CameraAccessException {
CameraManager.AvailabilityCallback mockCallback =
mock(CameraManager.AvailabilityCallback.class);
Expand All @@ -306,7 +299,6 @@ public void registerCallbackUnavailable() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void unregisterCallbackUnavailable() throws CameraAccessException {
CameraManager.AvailabilityCallback mockCallback =
mock(CameraManager.AvailabilityCallback.class);
Expand All @@ -321,7 +313,6 @@ public void unregisterCallbackUnavailable() throws CameraAccessException {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void registerCallbackUnavailableInvalidCameraId() throws CameraAccessException {
CameraManager.AvailabilityCallback mockCallback =
mock(CameraManager.AvailabilityCallback.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.robolectric.annotation.Config;

/** Tests for {@link ShadowCaptureRequestBuilder}. */
@Config(minSdk = VERSION_CODES.LOLLIPOP)
@RunWith(AndroidJUnit4.class)
public class ShadowCaptureRequestBuilderTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import static org.robolectric.Shadows.shadowOf;

import android.hardware.camera2.CaptureResult;
import android.os.Build.VERSION_CODES;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;

/** Tests for {@link ShadowCaptureResult}. */
@Config(minSdk = VERSION_CODES.LOLLIPOP)
@RunWith(AndroidJUnit4.class)
public class ShadowCaptureResultTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.nfc.cardemulation.CardEmulation;
import android.os.Build;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;

/** Test the shadow implementation of {@link CardEmulation}. */
@RunWith(AndroidJUnit4.class)
Expand All @@ -42,7 +40,6 @@ public void setUp() throws Exception {
}

@Test
@Config(minSdk = Build.VERSION_CODES.LOLLIPOP)
public void isDefaultServiceForCategory_canOverride() {
assertThat(cardEmulation.isDefaultServiceForCategory(service, TEST_CATEGORY)).isFalse();
ShadowCardEmulation.setDefaultServiceForCategory(service, TEST_CATEGORY);
Expand All @@ -52,7 +49,6 @@ public void isDefaultServiceForCategory_canOverride() {
}

@Test
@Config(minSdk = Build.VERSION_CODES.LOLLIPOP)
public void setPreferredService_canCapture() {
assertThat(ShadowCardEmulation.getPreferredService() == null).isTrue();
cardEmulation.setPreferredService(activity, service);
Expand All @@ -62,7 +58,6 @@ public void setPreferredService_canCapture() {
}

@Test
@Config(minSdk = Build.VERSION_CODES.LOLLIPOP)
public void categoryAllowsForegroundPreference_canSet() {
assertThat(cardEmulation.categoryAllowsForegroundPreference(CardEmulation.CATEGORY_PAYMENT))
.isFalse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.N;
import static android.os.Build.VERSION_CODES.Q;
import static android.os.Build.VERSION_CODES.TIRAMISU;
Expand Down Expand Up @@ -225,30 +224,13 @@ public void bindService() {
assertThat(shadowOf(context).getBoundServiceConnections()).hasSize(1);
}

@Test
public void bindService_shouldAllowImplicitIntentPreLollipop() {
context.getApplicationInfo().targetSdkVersion = KITKAT;
Intent serviceIntent = new Intent();
ServiceConnection serviceConnection = buildServiceConnection();
int flags = 0;

assertThat(context.bindService(serviceIntent, serviceConnection, flags)).isTrue();

assertThat(shadowOf(context).getBoundServiceConnections()).hasSize(1);
}

@Test
public void bindService_shouldThrowOnImplicitIntentOnLollipop() {
@Test(expected = IllegalArgumentException.class)
public void bindService_shouldThrowOnImplicitIntent() {
Intent serviceIntent = new Intent();
ServiceConnection serviceConnection = buildServiceConnection();
int flags = 0;

try {
context.bindService(serviceIntent, serviceConnection, flags);
fail("bindService should throw IllegalArgumentException!");
} catch (IllegalArgumentException e) {
// expected
}
context.bindService(serviceIntent, serviceConnection, flags);
}

@Test
Expand Down Expand Up @@ -292,39 +274,16 @@ public void bindService_noSpecifiedExecutor_callsServiceConnectedOnHandler() {
assertThat(serviceConnection.isConnected).isTrue();
}

@Test
public void startService_shouldAllowImplicitIntentPreLollipop() {
context.getApplicationInfo().targetSdkVersion = KITKAT;
@Test(expected = IllegalArgumentException.class)
public void startService_shouldThrowOnImplicitIntent() {
context.startService(new Intent("dummy_action"));
assertThat(shadowOf(context).getNextStartedService().getAction()).isEqualTo("dummy_action");
}

@Test
public void startService_shouldThrowOnImplicitIntentOnLollipop() {
try {
context.startService(new Intent("dummy_action"));
fail("startService should throw IllegalArgumentException!");
} catch (IllegalArgumentException e) {
// expected
}
}

@Test
public void stopService_shouldAllowImplicitIntentPreLollipop() {
context.getApplicationInfo().targetSdkVersion = KITKAT;
@Test(expected = IllegalArgumentException.class)
public void stopService_shouldThrowOnImplicitIntent() {
context.stopService(new Intent("dummy_action"));
}

@Test
public void stopService_shouldThrowOnImplicitIntentOnLollipop() {
try {
context.stopService(new Intent("dummy_action"));
fail("stopService should throw IllegalArgumentException!");
} catch (IllegalArgumentException e) {
// expected
}
}

@Test
public void sendBroadcastAsUser_sendBroadcast() {
UserHandle userHandle = Process.myUserHandle();
Expand Down Expand Up @@ -372,7 +331,7 @@ public void sendOrderedBroadcastAsUser_sendsBroadcast() {
@Test
public void createPackageContext_absent() {
try {
context.createPackageContext("doesnt.exist", 0);
context.createPackageContext("does.not.exist", 0);
fail("Should throw NameNotFoundException");
} catch (NameNotFoundException e) {
// expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ public void configureDefaultDisplay_calledTwice_showsReasonableException() {
.contains("configureDefaultDisplay was called a second time");
}

// because DisplayManagerGlobal don't exist in Jelly Bean,
// and we don't want them resolved as part of the test class.
// because we don't want DisplayManagerGlobal resolved as part of the test class.
static class HideFromJB {
public static DisplayManagerGlobal getGlobal() {
return DisplayManagerGlobal.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.os.Build.VERSION_CODES;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;

/** Unit tests for {@link ShadowEGL14Test} */
@RunWith(AndroidJUnit4.class)
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public final class ShadowEGL14Test {
@Test
public void eglGetCurrentContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void getExternalFilesDirs() throws Exception {
}

@Test
@Config(maxSdk = LOLLIPOP)
@Config(sdk = LOLLIPOP)
public void getExternalStorageStatePreLollipopMR1() {
File storageDir1 = ShadowEnvironment.addExternalDir("dir1");
File storageDir2 = ShadowEnvironment.addExternalDir("dir2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,6 @@ public void testRequestLocationUpdates_Criteria_PendingIntent() {
}

@Test
@Config(minSdk = VERSION_CODES.LOLLIPOP)
public void testRequestLocationUpdates_LocationRequest() {
Location loc1 = createLocation(NETWORK_PROVIDER);
Location loc2 = createLocation(NETWORK_PROVIDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.os.Build;
import android.view.Surface;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.IOException;
Expand Down Expand Up @@ -735,10 +734,6 @@ private static void process(MediaCodec codec, ByteBuffer src, ByteBuffer dst) {
private static void writeToInputBuffer(MediaCodec codec, ByteBuffer src) {
int inputBufferId = codec.dequeueInputBuffer(WITHOUT_TIMEOUT);
ByteBuffer inputBuffer = codec.getInputBuffer(inputBufferId);
// API versions lower than 21 don't clear the buffer before returning it.
if (Build.VERSION.SDK_INT < 21) {
inputBuffer.clear();
}
int srcLimit = src.limit();
int numberOfBytesToWrite = Math.min(src.remaining(), inputBuffer.remaining());
src.limit(src.position() + numberOfBytesToWrite);
Expand Down

0 comments on commit c51c71d

Please sign in to comment.