Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9789284 authored by Jason Monk's avatar Jason Monk
Browse files

android.provider.Setting test utilities

Add a way to fake values for settings in tests. Since the content
provider is cached in the NameValueCache, there is one static
FakeSettingsProvider that passes through all values to the
real SettingsProvider by default. Values that are required for
the test can be acquired and locked for the duration of the test
easily.

Test: runtest systemui
Change-Id: Ibc31ac8509fb31a22c522358a9c1bae6ec63553b
parent 67387af7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;

import com.android.systemui.statusbar.policy.BatteryController;

public class BatteryMeterDrawable extends Drawable implements
+7 −9
Original line number Diff line number Diff line
@@ -16,26 +16,24 @@

package com.android.keyguard;

import com.android.systemui.SysuiTestCase;
import static junit.framework.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Mockito.mock;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import static junit.framework.Assert.*;
import static org.mockito.Mockito.mock;
import com.android.systemui.SysuiTestCase;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class KeyguardMessageAreaTest extends SysuiTestCase {
    private Context mContext = InstrumentationRegistry.getTargetContext();
    private Handler mHandler = new Handler(Looper.getMainLooper());
    private KeyguardMessageArea mMessageArea;

+3 −6
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.systemui;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyFloat;
import static org.mockito.Mockito.anyString;
@@ -28,27 +28,24 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class BatteryMeterDrawableTest {
public class BatteryMeterDrawableTest extends SysuiTestCase {

    private Context mContext;
    private Resources mResources;
    private BatteryMeterDrawable mBatteryMeter;

    @Before
    public void setUp() throws Exception {
        mContext = InstrumentationRegistry.getTargetContext();
        mResources = mContext.getResources();
        mBatteryMeter = new BatteryMeterDrawable(mContext, 0);
    }
+11 −2
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@ import android.support.test.InstrumentationRegistry;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;

import com.android.systemui.utils.TestableContext;

import org.junit.After;
import org.junit.Before;

/**
@@ -28,11 +32,16 @@ import org.junit.Before;
public class SysuiTestCase {

    private Handler mHandler;
    protected Context mContext;
    protected TestableContext mContext;

    @Before
    public void SysuiSetup() throws Exception {
        mContext = InstrumentationRegistry.getTargetContext();
        mContext = new TestableContext(InstrumentationRegistry.getTargetContext());
    }

    @After
    public void cleanup() throws Exception {
        mContext.getSettingsProvider().clearOverrides(this);
    }

    protected Context getContext() {
+7 −3
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
package com.android.systemui.power;

import static android.test.MoreAsserts.assertNotEqual;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
@@ -29,9 +31,11 @@ import static org.mockito.Mockito.verify;

import android.app.Notification;
import android.app.NotificationManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.systemui.SysuiTestCase;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,7 +43,7 @@ import org.mockito.ArgumentCaptor;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class PowerNotificationWarningsTest {
public class PowerNotificationWarningsTest extends SysuiTestCase {
    private final NotificationManager mMockNotificationManager = mock(NotificationManager.class);
    private PowerNotificationWarnings mPowerNotificationWarnings;

@@ -47,7 +51,7 @@ public class PowerNotificationWarningsTest {
    public void setUp() throws Exception {
        // Test Instance.
        mPowerNotificationWarnings = new PowerNotificationWarnings(
                InstrumentationRegistry.getTargetContext(), mMockNotificationManager, null);
                mContext, mMockNotificationManager, null);
    }

    @Test
Loading