Skip to content

Commit d4cd4f0

Browse files
authored
[camera_android] Remove TestUtils.java (flutter#6490)
Removes `TestUtils.java`, in favor of using `@VisibileForTesting` instead. I had to change a couple of types from the interface type to the actual implementation type too, to accomplish the removal. fixes flutter#146457
1 parent 8f25520 commit d4cd4f0

File tree

7 files changed

+91
-147
lines changed

7 files changed

+91
-147
lines changed

packages/camera/camera_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.9+1
2+
3+
* Changes the visibility of a number of fields to `@VisibleForTesting` in order simplify testing.
4+
15
## 0.10.9
26

37
* Adds support to control video FPS and bitrate. See `CameraController.withSettings`.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ class Camera
105105
* Takes an input/output surface and orients the recording correctly. This is needed because
106106
* switching cameras while recording causes the wrong orientation.
107107
*/
108-
private VideoRenderer videoRenderer;
108+
@VisibleForTesting VideoRenderer videoRenderer;
109109

110110
/**
111111
* Whether or not the camera aligns with the initial way the camera was facing if the camera was
112112
* flipped.
113113
*/
114-
private int initialCameraFacing;
114+
@VisibleForTesting int initialCameraFacing;
115115

116-
private final SurfaceTextureEntry flutterTexture;
116+
@VisibleForTesting final SurfaceTextureEntry flutterTexture;
117117
private final VideoCaptureSettings videoCaptureSettings;
118118
private final Context applicationContext;
119119
final DartMessenger dartMessenger;
@@ -130,16 +130,16 @@ class Camera
130130

131131
CameraDeviceWrapper cameraDevice;
132132
CameraCaptureSession captureSession;
133-
private ImageReader pictureImageReader;
133+
@VisibleForTesting ImageReader pictureImageReader;
134134
ImageStreamReader imageStreamReader;
135135
/** {@link CaptureRequest.Builder} for the camera preview */
136136
CaptureRequest.Builder previewRequestBuilder;
137137

138-
private MediaRecorder mediaRecorder;
138+
@VisibleForTesting MediaRecorder mediaRecorder;
139139
/** True when recording video. */
140140
boolean recordingVideo;
141141
/** True when the preview is paused. */
142-
private boolean pausedPreview;
142+
@VisibleForTesting boolean pausedPreview;
143143

144144
private File captureFile;
145145

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.os.Looper;
1111
import androidx.annotation.NonNull;
1212
import androidx.annotation.Nullable;
13+
import androidx.annotation.VisibleForTesting;
1314
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
1415
import io.flutter.plugin.common.BinaryMessenger;
1516
import io.flutter.plugin.common.EventChannel;
@@ -36,7 +37,7 @@ final class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
3637
private final TextureRegistry textureRegistry;
3738
private final MethodChannel methodChannel;
3839
private final EventChannel imageStreamChannel;
39-
private @Nullable Camera camera;
40+
@VisibleForTesting @Nullable Camera camera;
4041

4142
MethodCallHandlerImpl(
4243
Activity activity,

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

Lines changed: 76 additions & 105 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
import io.flutter.plugin.common.BinaryMessenger;
1717
import io.flutter.plugin.common.MethodCall;
1818
import io.flutter.plugin.common.MethodChannel;
19-
import io.flutter.plugins.camera.utils.TestUtils;
2019
import io.flutter.view.TextureRegistry;
2120
import org.junit.Before;
2221
import org.junit.Test;
2322

2423
public class MethodCallHandlerImplTest {
2524

26-
MethodChannel.MethodCallHandler handler;
25+
MethodCallHandlerImpl handler;
2726
MethodChannel.Result mockResult;
2827
Camera mockCamera;
2928

@@ -38,7 +37,7 @@ public void setUp() {
3837
mock(TextureRegistry.class));
3938
mockResult = mock(MethodChannel.Result.class);
4039
mockCamera = mock(Camera.class);
41-
TestUtils.setPrivateField(handler, "camera", mockCamera);
40+
handler.camera = mockCamera;
4241
}
4342

4443
@Test

packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/utils/TestUtils.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/camera/camera_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
55

6-
version: 0.10.9
6+
version: 0.10.9+1
77

88
environment:
99
sdk: ^3.1.0

0 commit comments

Comments
 (0)