Merge "Log visibility change for all fragments."
This commit is contained in:
committed by
Android (Google) Code Review
commit
b0e8f67389
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.core.instrumentation;
|
||||
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class MetricsFactoryTest {
|
||||
|
||||
@Test
|
||||
public void factoryShouldReuseCachedInstance() {
|
||||
MetricsFactory factory1 = MetricsFactory.get();
|
||||
MetricsFactory factory2 = MetricsFactory.get();
|
||||
assertTrue(factory1 == factory2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryShouldCacheLogger() {
|
||||
MetricsFactory factory = MetricsFactory.get();
|
||||
EventLogWriter logger1 = factory.getLogger();
|
||||
EventLogWriter logger2 = factory.getLogger();
|
||||
assertTrue(logger1 == logger2);
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.core.instrumentation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class VisibilityLoggerMixinTest {
|
||||
|
||||
@Mock
|
||||
private EventLogWriter mLogger;
|
||||
private VisibilityLoggerMixin mMixin;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mMixin = new VisibilityLoggerMixin(new TestInstrumentable(), mLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogVisibleOnResume() {
|
||||
mMixin.onResume(null);
|
||||
verify(mLogger, times(1))
|
||||
.visible(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogHideOnPause() {
|
||||
mMixin.onPause(null);
|
||||
verify(mLogger, times(1))
|
||||
.hidden(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
|
||||
}
|
||||
|
||||
private final class TestInstrumentable implements Instrumentable {
|
||||
|
||||
public static final int TEST_METRIC = 12345;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return TEST_METRIC;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user