Search in sources :

Example 86 with Application

use of android.app.Application in project mosby by sockeqwe.

the class PresenterManagerTest method putNullViewStateThrowNullPointerException.

@Test
public void putNullViewStateThrowNullPointerException() {
    Object viewState = new Object();
    Activity activity = Mockito.mock(Activity.class);
    Application application = Mockito.mock(Application.class);
    Mockito.when(activity.getApplication()).thenReturn(application);
    try {
        PresenterManager.putViewState(null, "123", viewState);
        Assert.fail("Exception expected");
    } catch (NullPointerException e) {
    }
    try {
        PresenterManager.putViewState(activity, null, viewState);
        Assert.fail("Exception expected");
    } catch (NullPointerException e) {
    }
    try {
        PresenterManager.putViewState(activity, "123", null);
        Assert.fail("Exception expected");
    } catch (NullPointerException e) {
    }
}
Also used : Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 87 with Application

use of android.app.Application in project mosby by sockeqwe.

the class ActivityMvpDelegateImplTest method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.mock(PartialMvpDelegateCallbackImpl.class);
    activity = Mockito.mock(Activity.class);
    application = Mockito.mock(Application.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    Mockito.when(callback.getMvpView()).thenReturn(view);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Mockito.when(callback.createPresenter()).thenReturn(presenter);
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) Activity(android.app.Activity) Application(android.app.Application) Before(org.junit.Before)

Example 88 with Application

use of android.app.Application in project mosby by sockeqwe.

the class PresenterManagerTest method getPresenterReturnsNull.

@Test
public void getPresenterReturnsNull() {
    Activity activity = Mockito.mock(Activity.class);
    Application application = Mockito.mock(Application.class);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Assert.assertNull(PresenterManager.getPresenter(activity, "viewId123"));
}
Also used : Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 89 with Application

use of android.app.Application in project mosby by sockeqwe.

the class FragmentMvpViewStateDelegateImplTest method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    viewState = Mockito.mock(ViewState.class);
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.spy(PartialMvpViewStateDelegateCallbackImpl.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    Mockito.doCallRealMethod().when(callback).setViewState(viewState);
    Mockito.doCallRealMethod().when(callback).getViewState();
    fragment = PowerMockito.mock(Fragment.class);
    activity = Mockito.mock(FragmentActivity.class);
    application = Mockito.mock(Application.class);
    Mockito.when(callback.getMvpView()).thenReturn(view);
    Mockito.when(fragment.getActivity()).thenReturn(activity);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Mockito.when(callback.createPresenter()).thenReturn(presenter);
    Mockito.when(callback.createViewState()).thenReturn(viewState);
    delegate = new FragmentMvpViewStateDelegateImpl<>(fragment, callback, true, true);
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) ViewState(com.hannesdorfmann.mosby3.mvp.viewstate.ViewState) Fragment(android.support.v4.app.Fragment) Application(android.app.Application) Before(org.junit.Before)

Example 90 with Application

use of android.app.Application in project android by JetBrains.

the class LibUnitTest method mockFinalMethod.

@Test
public void mockFinalMethod() {
    Activity activity = mock(Activity.class);
    Application app = mock(Application.class);
    when(activity.getApplication()).thenReturn(app);
    assertSame(app, activity.getApplication());
    verify(activity).getApplication();
    verifyNoMoreInteractions(activity);
}
Also used : Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test)

Aggregations

Application (android.app.Application)125 Test (org.junit.Test)27 Context (android.content.Context)24 Activity (android.app.Activity)23 ApplicationInfo (android.content.pm.ApplicationInfo)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 File (java.io.File)10 MvpPresenter (com.hannesdorfmann.mosby3.mvp.MvpPresenter)8 Before (org.junit.Before)8 ShadowApplication (org.robolectric.shadows.ShadowApplication)8 MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 PrintWriter (java.io.PrintWriter)6 Date (java.util.Date)6 SuppressLint (android.annotation.SuppressLint)5 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 AndroidRuntimeException (android.util.AndroidRuntimeException)5