Skip to content

Commit 94706c8

Browse files
authored
[camera_android] Upgrading roboelectric from 4.5 to 4.10.3 (flutter#4018)
flutter#119752 Upgrades to allow configurations of sdk >= 31 (4.8.1 was chosen as it is the most common version used in other packages).
1 parent cda21a8 commit 94706c8

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

packages/camera/camera_android/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## NEXT
22

33
* Fixes unawaited_futures violations.
4+
* Removes duplicate line in `MediaRecorderBuilder.java`.
45

56
## 0.10.8+2
67

packages/camera/camera_android/android/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ android {
5151
unitTests.includeAndroidResources = true
5252
unitTests.returnDefaultValues = true
5353
unitTests.all {
54+
jvmArgs "-Xmx1g"
5455
testLogging {
5556
events "passed", "skipped", "failed", "standardOut", "standardError"
5657
outputs.upToDateWhen {false}
@@ -65,5 +66,5 @@ dependencies {
6566
testImplementation 'junit:junit:4.13.2'
6667
testImplementation 'org.mockito:mockito-inline:5.0.0'
6768
testImplementation 'androidx.test:core:1.4.0'
68-
testImplementation 'org.robolectric:robolectric:4.5'
69+
testImplementation 'org.robolectric:robolectric:4.10.3'
6970
}

packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public MediaRecorder build() throws IOException, NullPointerException, IndexOutO
9292
mediaRecorder.setVideoEncodingBitRate(videoProfile.getBitrate());
9393
mediaRecorder.setVideoFrameRate(videoProfile.getFrameRate());
9494
mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight());
95-
mediaRecorder.setVideoSize(videoProfile.getWidth(), videoProfile.getHeight());
9695
} else if (camcorderProfile != null) {
9796
mediaRecorder.setOutputFormat(camcorderProfile.fileFormat);
9897
if (enableAudio) {

packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/features/resolution/ResolutionFeatureTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ public void beforeLegacy() {
9191
public void before() {
9292
mockProfileLow = mock(EncoderProfiles.class);
9393
EncoderProfiles mockProfile = mock(EncoderProfiles.class);
94-
EncoderProfiles.VideoProfile mockVideoProfile = mock(EncoderProfiles.VideoProfile.class);
95-
List<EncoderProfiles.VideoProfile> mockVideoProfilesList = List.of(mockVideoProfile);
94+
List<EncoderProfiles.VideoProfile> mockVideoProfilesList =
95+
new ArrayList<EncoderProfiles.VideoProfile>();
96+
mockVideoProfilesList.add(null);
9697

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

119120
when(mockProfile.getVideoProfiles()).thenReturn(mockVideoProfilesList);
120-
when(mockVideoProfile.getHeight()).thenReturn(100);
121-
when(mockVideoProfile.getWidth()).thenReturn(100);
122121
}
123122

124123
@After
@@ -386,7 +385,7 @@ public void computeBestPreviewSize_shouldUseLegacyBehaviorWhenEncoderProfilesNul
386385
@Config(minSdk = 31)
387386
@Test
388387
public void resolutionFeatureShouldUseLegacyBehaviorWhenEncoderProfilesNull() {
389-
beforeLegacy();
388+
before();
390389
try (MockedStatic<ResolutionFeature> mockedResolutionFeature =
391390
mockStatic(ResolutionFeature.class)) {
392391
mockedResolutionFeature

packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/media/MediaRecorderBuilderTest.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabledLegacy() throw
7878
public void build_shouldSetValuesInCorrectOrderWhenAudioIsDisabled() throws IOException {
7979
EncoderProfiles recorderProfile = mock(EncoderProfiles.class);
8080
List<EncoderProfiles.VideoProfile> mockVideoProfiles =
81-
List.of(mock(EncoderProfiles.VideoProfile.class));
81+
List.of(getEmptyEncoderProfilesVideoProfile());
8282
List<EncoderProfiles.AudioProfile> mockAudioProfiles =
83-
List.of(mock(EncoderProfiles.AudioProfile.class));
83+
List.of(getEmptyEncoderProfilesAudioProfile());
8484
MediaRecorderBuilder.MediaRecorderFactory mockFactory =
8585
mock(MediaRecorderBuilder.MediaRecorderFactory.class);
8686
MediaRecorder mockMediaRecorder = mock(MediaRecorder.class);
@@ -172,9 +172,9 @@ public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabledLegacy() throws
172172
public void build_shouldSetValuesInCorrectOrderWhenAudioIsEnabled() throws IOException {
173173
EncoderProfiles recorderProfile = mock(EncoderProfiles.class);
174174
List<EncoderProfiles.VideoProfile> mockVideoProfiles =
175-
List.of(mock(EncoderProfiles.VideoProfile.class));
175+
List.of(getEmptyEncoderProfilesVideoProfile());
176176
List<EncoderProfiles.AudioProfile> mockAudioProfiles =
177-
List.of(mock(EncoderProfiles.AudioProfile.class));
177+
List.of(getEmptyEncoderProfilesAudioProfile());
178178
MediaRecorderBuilder.MediaRecorderFactory mockFactory =
179179
mock(MediaRecorderBuilder.MediaRecorderFactory.class);
180180
MediaRecorder mockMediaRecorder = mock(MediaRecorder.class);
@@ -224,4 +224,32 @@ private CamcorderProfile getEmptyCamcorderProfile() {
224224

225225
return null;
226226
}
227+
228+
private EncoderProfiles.VideoProfile getEmptyEncoderProfilesVideoProfile() {
229+
try {
230+
Constructor<EncoderProfiles.VideoProfile> constructor =
231+
EncoderProfiles.VideoProfile.class.getDeclaredConstructor(
232+
int.class, int.class, int.class, int.class, int.class, int.class);
233+
234+
constructor.setAccessible(true);
235+
return constructor.newInstance(0, 0, 0, 0, 0, 0);
236+
} catch (Exception ignored) {
237+
}
238+
239+
return null;
240+
}
241+
242+
private EncoderProfiles.AudioProfile getEmptyEncoderProfilesAudioProfile() {
243+
try {
244+
Constructor<EncoderProfiles.AudioProfile> constructor =
245+
EncoderProfiles.AudioProfile.class.getDeclaredConstructor(
246+
int.class, int.class, int.class, int.class, int.class);
247+
248+
constructor.setAccessible(true);
249+
return constructor.newInstance(0, 0, 0, 0, 0);
250+
} catch (Exception ignored) {
251+
}
252+
253+
return null;
254+
}
227255
}

0 commit comments

Comments
 (0)