From b4aac521569a933a6e7789e9dc25014bdd82d57c Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Sat, 25 Oct 2014 19:04:04 -0700 Subject: Fix NPEs in ActionBarControllerTest Create a MockActionBar that to prevent NPEs. For this an ActivityInstrumentationTestCase is needed. Bug: 17487016 Change-Id: Ieca95bec22c075ad64a1167e57f6b85f913bcf7e --- .../dialer/widget/ActionBarControllerTest.java | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/src/com/android/dialer/widget/ActionBarControllerTest.java b/tests/src/com/android/dialer/widget/ActionBarControllerTest.java index cafa747f2..2e388380f 100644 --- a/tests/src/com/android/dialer/widget/ActionBarControllerTest.java +++ b/tests/src/com/android/dialer/widget/ActionBarControllerTest.java @@ -17,25 +17,53 @@ package com.android.dialer.widget; import android.app.ActionBar; +import android.app.Activity; import android.content.Context; +import android.test.ActivityInstrumentationTestCase2; +import android.test.AndroidTestCase; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.SmallTest; +import android.view.View; +import com.android.dialer.DialtactsActivity; import com.android.dialer.widget.ActionBarController.ActivityUi; +import com.android.internal.app.WindowDecorActionBar; @SmallTest -public class ActionBarControllerTest extends InstrumentationTestCase { +public class ActionBarControllerTest extends ActivityInstrumentationTestCase2 { private static final int ACTION_BAR_HEIGHT = 100; private ActionBarController mActionBarController; private SearchEditTextLayout mSearchBox; private MockActivityUi mActivityUi; + private class MockActionBar extends WindowDecorActionBar { + private int mHideOffset = 0; + + public MockActionBar(Activity activity) { + super(activity); + } + + @Override + public void setHideOffset(int offset) { + mHideOffset = offset; + } + + @Override + public int getHideOffset() { + return mHideOffset; + } + } + private class MockActivityUi implements ActivityUi { boolean isInSearchUi; boolean hasSearchQuery; boolean shouldShowActionBar; - int actionBarHideOffset; + private ActionBar mActionBar; + + public MockActivityUi() { + mActionBar = new MockActionBar(getActivity()); + } @Override public boolean isInSearchUi() { @@ -59,7 +87,7 @@ public class ActionBarControllerTest extends InstrumentationTestCase { @Override public ActionBar getActionBar() { - return null; + return mActionBar; } } @@ -83,6 +111,11 @@ public class ActionBarControllerTest extends InstrumentationTestCase { } } + public ActionBarControllerTest() { + super(DialtactsActivity.class); + } + + @Override protected void setUp() { mActivityUi = new MockActivityUi(); -- cgit v1.2.3