Skip to content

Commit

Permalink
[camera_android] Remove TestUtils.java (#6490)
Browse files Browse the repository at this point in the history
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/flutter#146457
  • Loading branch information
gmackall authored Apr 8, 2024
1 parent 8f25520 commit d4cd4f0
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 147 deletions.
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.9+1

* Changes the visibility of a number of fields to `@VisibleForTesting` in order simplify testing.

## 0.10.9

* Adds support to control video FPS and bitrate. See `CameraController.withSettings`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ class Camera
* Takes an input/output surface and orients the recording correctly. This is needed because
* switching cameras while recording causes the wrong orientation.
*/
private VideoRenderer videoRenderer;
@VisibleForTesting VideoRenderer videoRenderer;

/**
* Whether or not the camera aligns with the initial way the camera was facing if the camera was
* flipped.
*/
private int initialCameraFacing;
@VisibleForTesting int initialCameraFacing;

private final SurfaceTextureEntry flutterTexture;
@VisibleForTesting final SurfaceTextureEntry flutterTexture;
private final VideoCaptureSettings videoCaptureSettings;
private final Context applicationContext;
final DartMessenger dartMessenger;
Expand All @@ -130,16 +130,16 @@ class Camera

CameraDeviceWrapper cameraDevice;
CameraCaptureSession captureSession;
private ImageReader pictureImageReader;
@VisibleForTesting ImageReader pictureImageReader;
ImageStreamReader imageStreamReader;
/** {@link CaptureRequest.Builder} for the camera preview */
CaptureRequest.Builder previewRequestBuilder;

private MediaRecorder mediaRecorder;
@VisibleForTesting MediaRecorder mediaRecorder;
/** True when recording video. */
boolean recordingVideo;
/** True when the preview is paused. */
private boolean pausedPreview;
@VisibleForTesting boolean pausedPreview;

private File captureFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
Expand All @@ -36,7 +37,7 @@ final class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
private final TextureRegistry textureRegistry;
private final MethodChannel methodChannel;
private final EventChannel imageStreamChannel;
private @Nullable Camera camera;
@VisibleForTesting @Nullable Camera camera;

MethodCallHandlerImpl(
Activity activity,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.camera.utils.TestUtils;
import io.flutter.view.TextureRegistry;
import org.junit.Before;
import org.junit.Test;

public class MethodCallHandlerImplTest {

MethodChannel.MethodCallHandler handler;
MethodCallHandlerImpl handler;
MethodChannel.Result mockResult;
Camera mockCamera;

Expand All @@ -38,7 +37,7 @@ public void setUp() {
mock(TextureRegistry.class));
mockResult = mock(MethodChannel.Result.class);
mockCamera = mock(Camera.class);
TestUtils.setPrivateField(handler, "camera", mockCamera);
handler.camera = mockCamera;
}

@Test
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22

version: 0.10.9
version: 0.10.9+1

environment:
sdk: ^3.1.0
Expand Down

0 comments on commit d4cd4f0

Please sign in to comment.