diff options
author | Yorke Lee <yorkelee@google.com> | 2014-10-25 19:04:04 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2014-10-25 19:04:04 -0700 |
commit | b4aac521569a933a6e7789e9dc25014bdd82d57c (patch) | |
tree | 40a9430a0f79f548150403ec510d37e1d0d0b9e2 /tests | |
parent | 152266fb7ae309942e9a67419f104a29f491c0b8 (diff) |
Fix NPEs in ActionBarControllerTest
Create a MockActionBar that to prevent NPEs. For this an
ActivityInstrumentationTestCase is needed.
Bug: 17487016
Change-Id: Ieca95bec22c075ad64a1167e57f6b85f913bcf7e
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/dialer/widget/ActionBarControllerTest.java | 39 |
1 files 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<DialtactsActivity> { 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(); |