Skip to content

[camera_android] Upgrading roboelectric from 4.5 to 4.10.3 #4018

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

Merged
merged 20 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

* Fixes unawaited_futures violations.
* Removes duplicate line in `MediaRecorderBuilder.java`.

## 0.10.8+2

Expand Down
3 changes: 2 additions & 1 deletion packages/camera/camera_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ android {
unitTests.includeAndroidResources = true
unitTests.returnDefaultValues = true
unitTests.all {
jvmArgs "-Xmx1g"
Copy link
Contributor

Choose a reason for hiding this comment

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

Bumped to fix OOM errors.

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
Expand All @@ -65,5 +66,5 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:5.0.0'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'org.robolectric:robolectric:4.5'
testImplementation 'org.robolectric:robolectric:4.10.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public MediaRecorder build() throws IOException, NullPointerException, IndexOutO
mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate());
mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate());
mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight());
mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight());
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated fix: remove duplicate line

} else if (camcorderProfile != null) {
mediaRecorder.setOutputFormat(camcorderProfile.fileFormat);
if (enableAudio) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public void beforeLegacy() {
public void before() {
mockProfileLow = mock(EncoderProfiles.class);
EncoderProfiles mockProfile = mock(EncoderProfiles.class);
EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class);
List<EncoderProfiles.VideoProfile> mockVideoProfilesList = List.of(mockVideoProfile);
List<EncoderProfiles.VideoProfile> mockVideoProfilesList =
new ArrayList<EncoderProfiles.VideoProfile>();
mockVideoProfilesList.add(null);
Copy link
Contributor

@camsim99 camsim99 Jun 7, 2023

Choose a reason for hiding this comment

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

The EncoderProfiles.VideoProfile class is final static so it cannot be mocked. It's not actually tested in this test so I just set it to null so that the tests run properly.


mockedStaticProfile
.when(() -> CamcorderProfile.getAll("1", CamcorderProfile.QUALITY_HIGH))
Expand All @@ -117,8 +118,6 @@ public void before() {
.thenReturn(mockProfileLow);

when(mockProfile.getVideoProfiles()).thenReturn(mockVideoProfilesList);
when(mockVideoProfile.getHeight()).thenReturn(100);
when(mockVideoProfile.getWidth()).thenReturn(100);
}

@After
Expand Down Expand Up @@ -386,7 +385,7 @@ public void computeBestPreviewSize_shouldUseLegacyBehaviorWhenEncoderProfilesNul
@Config(minSdk = 31)
@Test
public void resolutionFeatureShouldUseLegacyBehaviorWhenEncoderProfilesNull() {
beforeLegacy();
before();
Copy link
Contributor

Choose a reason for hiding this comment

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

This tests non-legacy code so this was incorrect I think.

try (MockedStatic<ResolutionFeature> mockedResolutionFeature =
mockStatic(ResolutionFeature.class)) {
mockedResolutionFeature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledLegacy() throw
public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOException {
EncoderProfiles recorderProfile = mock(EncoderProfiles.class);
List<EncoderProfiles.VideoProfile> mockVideoProfiles =
List.of(mock(EncoderProfiles.VideoProfile.class));
List.of(getEmptyEncoderProfilesVideoProfile());
List<EncoderProfiles.AudioProfile> mockAudioProfiles =
List.of(mock(EncoderProfiles.AudioProfile.class));
List.of(getEmptyEncoderProfilesAudioProfile());
MediaRecorderBuilder.MediaRecorderFactory mockFactory =
mock(MediaRecorderBuilder.MediaRecorderFactory.class);
MediaRecorder mockMediaRecorder = mock(MediaRecorder.class);
Expand Down Expand Up @@ -172,9 +172,9 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabledLegacy() throws
public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOException {
EncoderProfiles recorderProfile = mock(EncoderProfiles.class);
List<EncoderProfiles.VideoProfile> mockVideoProfiles =
List.of(mock(EncoderProfiles.VideoProfile.class));
List.of(getEmptyEncoderProfilesVideoProfile());
List<EncoderProfiles.AudioProfile> mockAudioProfiles =
List.of(mock(EncoderProfiles.AudioProfile.class));
List.of(getEmptyEncoderProfilesAudioProfile());
MediaRecorderBuilder.MediaRecorderFactory mockFactory =
mock(MediaRecorderBuilder.MediaRecorderFactory.class);
MediaRecorder mockMediaRecorder = mock(MediaRecorder.class);
Expand Down Expand Up @@ -224,4 +224,32 @@ private CamcorderProfile getEmptyCamcorderProfile() {

return null;
}

private EncoderProfiles.VideoProfile getEmptyEncoderProfilesVideoProfile() {
try {
Constructor<EncoderProfiles.VideoProfile> constructor =
EncoderProfiles.VideoProfile.class.getDeclaredConstructor(
int.class, int.class, int.class, int.class, int.class, int.class);

constructor.setAccessible(true);
return constructor.newInstance(0, 0, 0, 0, 0, 0);
} catch (Exception ignored) {
}

return null;
}

private EncoderProfiles.AudioProfile getEmptyEncoderProfilesAudioProfile() {
try {
Constructor<EncoderProfiles.AudioProfile> constructor =
EncoderProfiles.AudioProfile.class.getDeclaredConstructor(
int.class, int.class, int.class, int.class, int.class);

constructor.setAccessible(true);
return constructor.newInstance(0, 0, 0, 0, 0);
} catch (Exception ignored) {
}

return null;
}
}