2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.android.settings.core.instrumentation;
18 import android.content.Context;
20 import com.android.settings.TestConfig;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.robolectric.RobolectricTestRunner;
28 import org.robolectric.annotation.Config;
30 import static org.mockito.Matchers.any;
31 import static org.mockito.Matchers.anyInt;
32 import static org.mockito.Matchers.eq;
33 import static org.mockito.Mockito.never;
34 import static org.mockito.Mockito.times;
35 import static org.mockito.Mockito.verify;
38 @RunWith(RobolectricTestRunner.class)
39 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
40 public class VisibilityLoggerMixinTest {
43 private MetricsFeatureProvider mMetricsFeature;
45 private VisibilityLoggerMixin mMixin;
49 MockitoAnnotations.initMocks(this);
50 mMixin = new VisibilityLoggerMixin(TestInstrumentable.TEST_METRIC, mMetricsFeature);
54 public void shouldLogVisibleOnResume() {
57 verify(mMetricsFeature, times(1))
58 .visible(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
62 public void shouldLogHideOnPause() {
65 verify(mMetricsFeature, times(1))
66 .hidden(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
70 public void shouldNotLogIfMetricsFeatureIsNull() {
71 mMixin = new VisibilityLoggerMixin(TestInstrumentable.TEST_METRIC);
75 verify(mMetricsFeature, never())
76 .hidden(any(Context.class), anyInt());
79 private final class TestInstrumentable implements Instrumentable {
81 public static final int TEST_METRIC = 12345;
84 public int getMetricsCategory() {