blob: e2135b3945b0b37c40d5711fd18c36804de5f90f [file] [log] [blame]
// Copyright 2013 The Flutter 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.camerax;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import androidx.camera.core.Camera;
import io.flutter.plugin.common.BinaryMessenger;
import java.util.Objects;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
public class CameraTest {
@Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock public BinaryMessenger mockBinaryMessenger;
@Mock public Camera camera;
InstanceManager testInstanceManager;
@Before
public void setUp() {
testInstanceManager = InstanceManager.open(identifier -> {});
}
@After
public void tearDown() {
testInstanceManager.close();
}
@Test
public void flutterApiCreateTest() {
final CameraFlutterApiImpl spyFlutterApi =
spy(new CameraFlutterApiImpl(mockBinaryMessenger, testInstanceManager));
spyFlutterApi.create(camera, reply -> {});
final long identifier =
Objects.requireNonNull(testInstanceManager.getIdentifierForStrongReference(camera));
verify(spyFlutterApi).create(eq(identifier), any());
}
}