Skip to content

Commit

Permalink
Fix SDK compat issues in 4.12
Browse files Browse the repository at this point in the history
Update several shadows to use `isInAndroidSdk=false`, which disables
shadowOf method generation. This fixes compile issues for apps that have
compileSdkVersion < Q.
  • Loading branch information
hoisie committed Apr 29, 2024
1 parent e2a8e26 commit f9dc1da
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 8 deletions.
Expand Up @@ -6,6 +6,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;

/**
* Test class for Java's class resolve compatibility test. We must keep it with Java instead of
Expand All @@ -21,8 +23,6 @@ public void sdkIs29() {
@Test
public void shadowOf() {
// https://github.com/robolectric/robolectric/issues/7095
// Enable this assertion when resolving all shadowOf compatibility problem
// assertThat(Shadows.shadowOf((Application) ApplicationProvider.getApplicationContext()))
// .isNotNull();
assertThat(Shadows.shadowOf(RuntimeEnvironment.getApplication())).isNotNull();
}
}
@@ -1,7 +1,6 @@
package org.robolectric.shadows;

import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;

import android.content.Intent;
import android.net.Ikev2VpnProfile;
Expand All @@ -15,6 +14,7 @@
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;

@RunWith(AndroidJUnit4.class)
@Config(minSdk = VERSION_CODES.R)
Expand All @@ -25,7 +25,7 @@ public class ShadowVpnManagerTest {
@Before
public void setUp() throws Exception {
vpnManager = ApplicationProvider.getApplicationContext().getSystemService(VpnManager.class);
shadowVpnManager = shadowOf(vpnManager);
shadowVpnManager = Shadow.extract(vpnManager);
}

@Test
Expand Down
Expand Up @@ -5,7 +5,10 @@
import org.robolectric.annotation.Implements;

/** Shadow for {@link android.net.wifi.ScanResult.InformationElement}. */
@Implements(value = ScanResult.InformationElement.class, minSdk = VERSION_CODES.R)
@Implements(
value = ScanResult.InformationElement.class,
minSdk = VERSION_CODES.R,
isInAndroidSdk = false)
public class ShadowInformationElement {
/**
* A builder for creating ShadowInformationElement objects. Use build() to return the
Expand Down
Expand Up @@ -15,6 +15,7 @@
value = PositionedGlyphs.class,
minSdk = S.SDK_INT,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativePositionedGlyphs {
/**
Expand Down
Expand Up @@ -16,6 +16,7 @@
value = RenderEffect.class,
minSdk = O,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativeRenderEffect {
static {
Expand Down
Expand Up @@ -22,6 +22,7 @@
value = RuntimeShader.class,
minSdk = O,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativeRuntimeShader {

Expand Down
Expand Up @@ -14,6 +14,7 @@
value = TextRunShaper.class,
minSdk = S.SDK_INT,
shadowPicker = Picker.class,
isInAndroidSdk = false,
callNativeMethodsByDefault = true)
public class ShadowNativeTextRunShaper {

Expand Down
Expand Up @@ -11,7 +11,7 @@
import org.robolectric.annotation.Implements;

/** Shadow for {@link TranslationManager}. */
@Implements(value = TranslationManager.class, minSdk = VERSION_CODES.S)
@Implements(value = TranslationManager.class, minSdk = VERSION_CODES.S, isInAndroidSdk = false)
public class ShadowTranslationManager {
private final Table<Integer, Integer, ImmutableSet<TranslationCapability>>
onDeviceTranslationCapabilities = HashBasedTable.create();
Expand Down
Expand Up @@ -11,7 +11,7 @@
import org.robolectric.annotation.Implements;

/** Shadow for {@link VpnManager}. */
@Implements(value = VpnManager.class, minSdk = VERSION_CODES.R)
@Implements(value = VpnManager.class, minSdk = VERSION_CODES.R, isInAndroidSdk = false)
public class ShadowVpnManager {

private VpnProfileState vpnProfileState;
Expand Down

0 comments on commit f9dc1da

Please sign in to comment.