Skip to content

Commit

Permalink
Merge pull request flutter#9 from bottlepay/android-rework-test-expos…
Browse files Browse the repository at this point in the history
…urelock-feature

Android rework test exposure lock feature
  • Loading branch information
acoutts authored Mar 8, 2021
2 parents 5387727 + 826c7ed commit 866f823
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ExposureLockFeature(CameraProperties cameraProperties) {

@Override
public String getDebugName() {
return "ExposureLock";
return "ExposureLockFeature";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera.types;
package io.flutter.plugins.camera.features.autofocus;

import static org.junit.Assert.assertEquals;

import io.flutter.plugins.camera.features.autofocus.FocusMode;
import org.junit.Test;

public class FocusModeTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.flutter.plugins.camera.features.exposurelock;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.hardware.camera2.CaptureRequest;
import io.flutter.plugins.camera.CameraProperties;
import org.junit.Test;

public class ExposureLockFeatureTest {
@Test
public void getDebugName_should_return_the_name_of_the_feature() {
CameraProperties mockCameraProperties = mock(CameraProperties.class);
ExposureLockFeature exposureLockFeature = new ExposureLockFeature(mockCameraProperties);

assertEquals("ExposureLockFeature", exposureLockFeature.getDebugName());
}

@Test
public void getValue_should_return_auto_if_not_set() {
CameraProperties mockCameraProperties = mock(CameraProperties.class);
ExposureLockFeature exposureLockFeature = new ExposureLockFeature(mockCameraProperties);

assertEquals(ExposureMode.auto, exposureLockFeature.getValue());
}

@Test
public void getValue_should_echo_the_set_value() {
CameraProperties mockCameraProperties = mock(CameraProperties.class);
ExposureLockFeature exposureLockFeature = new ExposureLockFeature(mockCameraProperties);
ExposureMode expectedValue = ExposureMode.locked;

exposureLockFeature.setValue(expectedValue);
ExposureMode actualValue = exposureLockFeature.getValue();

assertEquals(expectedValue, actualValue);
}

@Test
public void checkIsSupported_should_return_true() {
CameraProperties mockCameraProperties = mock(CameraProperties.class);
ExposureLockFeature exposureLockFeature = new ExposureLockFeature(mockCameraProperties);

assertTrue(exposureLockFeature.checkIsSupported());
}

@Test
public void updateBuilder_should_set_control_ae_lock_to_false_when_auto_exposure_is_set_to_auto() {
CameraProperties mockCameraProperties = mock(CameraProperties.class);
CaptureRequest.Builder mockBuilder = mock(CaptureRequest.Builder.class);
ExposureLockFeature exposureLockFeature = new ExposureLockFeature(mockCameraProperties);


exposureLockFeature.setValue(ExposureMode.auto);
exposureLockFeature.updateBuilder(mockBuilder);

verify(mockBuilder, times(1)).set(CaptureRequest.CONTROL_AE_LOCK, false);
}

@Test
public void updateBuilder_should_set_control_ae_lock_to_false_when_auto_exposure_is_set_to_locked() {
CameraProperties mockCameraProperties = mock(CameraProperties.class);
CaptureRequest.Builder mockBuilder = mock(CaptureRequest.Builder.class);
ExposureLockFeature exposureLockFeature = new ExposureLockFeature(mockCameraProperties);


exposureLockFeature.setValue(ExposureMode.locked);
exposureLockFeature.updateBuilder(mockBuilder);

verify(mockBuilder, times(1)).set(CaptureRequest.CONTROL_AE_LOCK, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera.types;
package io.flutter.plugins.camera.features.exposurelock;

import static org.junit.Assert.assertEquals;

import io.flutter.plugins.camera.features.exposurelock.ExposureMode;
import org.junit.Test;

public class ExposureModeTest {
Expand Down

0 comments on commit 866f823

Please sign in to comment.