Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Bump unit test robolectric version to 4.10.3 #42454

Merged
merged 11 commits into from
Jun 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowResources;

@Implements(Resources.class)
public class SplashShadowResources {
public class SplashShadowResources extends ShadowResources {
Copy link
Contributor Author

@camsim99 camsim99 Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robolectric expects to find an extension of ShadowResources when @Implements(Resources.class) is specified, as per the docs.

@RealObject private Resources resources;

public static final int SPLASH_DRAWABLE_ID = 191919;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public void draw(Canvas canvas) {
verify(surface, times(1)).lockHardwareCanvas();
verify(surface, times(1)).unlockCanvasAndPost(canvas);
verifyNoMoreInteractions(surface);
verifyNoMoreInteractions(canvas);
Copy link
Contributor Author

@camsim99 camsim99 Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer can be expected due to robolectric/robolectric#7279; there are now calls to draw that occur on canvas.

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,7 @@ public void disposeNullAndroidView() {
PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
PlatformView platformView = mock(PlatformView.class);

Context context = ApplicationProvider.getApplicationContext();
View androidView = new View(context);
View androidView = mock(View.class);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the ApplicationProvider.getApplicationContext() context to create androidView is problematic because the call to attach in this method creates another View with the exact same context that is already added as a View to the relevant PlatformView, causing an error here.

when(platformView.getView()).thenReturn(androidView);
when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/android/test_runner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ android {
testImplementation "androidx.test:core:1.4.0"
testImplementation "com.google.android.play:core:1.8.0"
testImplementation "com.ibm.icu:icu4j:69.1"
testImplementation "org.robolectric:robolectric:4.7.3"
testImplementation "org.robolectric:robolectric:4.10.3"
testImplementation "junit:junit:4.13.2"
testImplementation "androidx.test.ext:junit:1.1.4-alpha07"

Expand Down