forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request flutter#15 from bottlepay/android-rework-test-nois…
…ereduction-feature Added test coverage to noise reduction feature
- Loading branch information
Showing
11 changed files
with
220 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...roid/src/test/java/io/flutter/plugins/camera/features/autofocus/AutoFocusFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...rc/test/java/io/flutter/plugins/camera/features/exposurelock/ExposureLockFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...est/java/io/flutter/plugins/camera/features/exposureoffset/ExposureOffsetFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../test/java/io/flutter/plugins/camera/features/exposurepoint/ExposurePointFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...mera/android/src/test/java/io/flutter/plugins/camera/features/flash/FlashFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...id/src/test/java/io/flutter/plugins/camera/features/focuspoint/FocusPointFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...ndroid/src/test/java/io/flutter/plugins/camera/features/fpsrange/FpsRangeFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
...est/java/io/flutter/plugins/camera/features/noisereduction/NoiseReductionFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// 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.features.noisereduction; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import android.hardware.camera2.CaptureRequest; | ||
import android.os.Build.VERSION; | ||
import io.flutter.plugins.camera.CameraProperties; | ||
import io.flutter.plugins.camera.utils.TestUtils; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class NoiseReductionFeatureTest { | ||
@BeforeClass | ||
public static void beforeClass() { | ||
// Make sure the VERSION.SDK_INT field returns 23, to allow using all available | ||
// noise reduction modes in tests. | ||
try { | ||
TestUtils.setFinalStatic(VERSION.class.getField("SDK_INT"), 23); | ||
} catch (Exception e) { | ||
Assert.fail("Unable to set SDK_INT"); | ||
} | ||
} | ||
|
||
@Test | ||
public void getDebugName_should_return_the_name_of_the_feature() { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
|
||
assertEquals("NoiseReductionFeature", noiseReductionFeature.getDebugName()); | ||
} | ||
|
||
@Test | ||
public void getValue_should_return_fast_if_not_set() { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
|
||
assertEquals(NoiseReductionMode.fast, noiseReductionFeature.getValue()); | ||
} | ||
|
||
@Test | ||
public void getValue_should_echo_the_set_value() { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
NoiseReductionMode expectedValue = NoiseReductionMode.fast; | ||
|
||
noiseReductionFeature.setValue(expectedValue); | ||
NoiseReductionMode actualValue = noiseReductionFeature.getValue(); | ||
|
||
assertEquals(expectedValue, actualValue); | ||
} | ||
|
||
@Test | ||
public void checkIsSupported_should_return_false_when_available_noise_reduction_modes_is_null() { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
|
||
when(mockCameraProperties.getAvailableNoiseReductionModes()).thenReturn(null); | ||
|
||
assertFalse(noiseReductionFeature.checkIsSupported()); | ||
} | ||
|
||
@Test | ||
public void checkIsSupported_should_return_false_when_available_noise_reduction_modes_returns_an_empty_array() { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
|
||
when(mockCameraProperties.getAvailableNoiseReductionModes()).thenReturn(new int[] { }); | ||
|
||
assertFalse(noiseReductionFeature.checkIsSupported()); | ||
} | ||
|
||
@Test | ||
public void checkIsSupported_should_return_true_when_available_noise_reduction_modes_returns_at_least_one_item() { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
|
||
when(mockCameraProperties.getAvailableNoiseReductionModes()).thenReturn(new int[] { 1 }); | ||
|
||
assertTrue(noiseReductionFeature.checkIsSupported()); | ||
} | ||
|
||
@Test | ||
public void updateBuilder_should_return_when_checkIsSupported_is_false() { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
CaptureRequest.Builder mockBuilder = mock(CaptureRequest.Builder.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
|
||
when(mockCameraProperties.getAvailableNoiseReductionModes()).thenReturn(new int[] { }); | ||
|
||
noiseReductionFeature.updateBuilder(mockBuilder); | ||
|
||
verify(mockBuilder, never()).set(any(), any()); | ||
} | ||
|
||
@Test | ||
public void updateBuilder_should_set_noise_reduction_mode_off_when_off() { | ||
testUpdateBuilderWith(NoiseReductionMode.off, CaptureRequest.NOISE_REDUCTION_MODE_OFF); | ||
} | ||
|
||
@Test | ||
public void updateBuilder_should_set_noise_reduction_mode_fast_when_fast() { | ||
testUpdateBuilderWith(NoiseReductionMode.fast, CaptureRequest.NOISE_REDUCTION_MODE_FAST); | ||
} | ||
|
||
@Test | ||
public void updateBuilder_should_set_noise_reduction_mode_high_quality_when_high_quality() { | ||
testUpdateBuilderWith(NoiseReductionMode.highQuality, CaptureRequest.NOISE_REDUCTION_MODE_HIGH_QUALITY); | ||
} | ||
|
||
@Test | ||
public void updateBuilder_should_set_noise_reduction_mode_minimal_when_minimal() { | ||
testUpdateBuilderWith(NoiseReductionMode.minimal, CaptureRequest.NOISE_REDUCTION_MODE_MINIMAL); | ||
} | ||
|
||
@Test | ||
public void updateBuilder_should_set_noise_reduction_mode_zero_shutter_lag_when_zero_shutter_lag() { | ||
testUpdateBuilderWith(NoiseReductionMode.zeroShutterLag, CaptureRequest.NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG); | ||
} | ||
|
||
private static void testUpdateBuilderWith(NoiseReductionMode mode, int expectedResult) { | ||
CameraProperties mockCameraProperties = mock(CameraProperties.class); | ||
CaptureRequest.Builder mockBuilder = mock(CaptureRequest.Builder.class); | ||
NoiseReductionFeature noiseReductionFeature = new NoiseReductionFeature(mockCameraProperties); | ||
|
||
when(mockCameraProperties.getAvailableNoiseReductionModes()).thenReturn(new int[] { 1 }); | ||
|
||
noiseReductionFeature.setValue(mode); | ||
noiseReductionFeature.updateBuilder(mockBuilder); | ||
verify(mockBuilder, times(1)).set(CaptureRequest.NOISE_REDUCTION_MODE, expectedResult); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/utils/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// 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.utils; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
|
||
public class TestUtils { | ||
public static void setFinalStatic(Field field, Object newValue) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
field.setAccessible(true); | ||
|
||
Field modifiersField = Field.class.getDeclaredField("modifiers"); | ||
modifiersField.setAccessible(true); | ||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); | ||
|
||
field.set(null, newValue); | ||
} | ||
} |