Search in sources :

Example 16 with Application

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

the class PresenterManagerTest method putNullPresenterThrowsNullPointerExceptino.

@Test
public void putNullPresenterThrowsNullPointerExceptino() {
    MvpPresenter presenter = Mockito.mock(MvpPresenter.class);
    Activity activity = Mockito.mock(Activity.class);
    Application application = Mockito.mock(Application.class);
    Mockito.when(activity.getApplication()).thenReturn(application);
    try {
        PresenterManager.putPresenter(null, "123", presenter);
        Assert.fail("Exception expected");
    } catch (NullPointerException e) {
    }
    try {
        PresenterManager.putPresenter(activity, null, presenter);
        Assert.fail("Exception expected");
    } catch (NullPointerException e) {
    }
    try {
        PresenterManager.putPresenter(activity, "123", null);
        Assert.fail("Exception expected");
    } catch (NullPointerException e) {
    }
}
Also used : MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with Application

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

the class PresenterManagerTest method getViewStateReturnsNull.

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

Example 18 with Application

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

the class PresenterManagerTest method getActivityScopeReturnsExistingOne.

@Test
public void getActivityScopeReturnsExistingOne() {
    Activity activity = Mockito.mock(Activity.class);
    Application application = Mockito.mock(Application.class);
    Mockito.when(activity.getApplication()).thenReturn(application);
    ActivityScopedCache scope1 = PresenterManager.getOrCreateActivityScopedCache(activity);
    Assert.assertNotNull(scope1);
    Assert.assertEquals(scope1, PresenterManager.getActivityScope(activity));
}
Also used : Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with Application

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

the class ActivityMvpViewStateDelegateImplTestNew method initComponents.

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

Example 20 with Application

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

the class ViewGroupMvpViewStateDelegateImplTest method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    viewState = Mockito.mock(ViewState.class);
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.mock(PartialViewGroupMvpViewStateDelegateCallbackImpl.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    Mockito.doCallRealMethod().when(callback).setViewState(viewState);
    Mockito.doCallRealMethod().when(callback).getViewState();
    activity = Mockito.mock(FragmentActivity.class);
    application = Mockito.mock(Application.class);
    Mockito.when(callback.getMvpView()).thenReturn(view);
    Mockito.when(callback.getContext()).thenReturn(activity);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Mockito.when(callback.createPresenter()).thenReturn(presenter);
    Mockito.when(callback.createViewState()).thenReturn(viewState);
    delegate = new ViewGroupMvpViewStateDelegateImpl<>(callback, 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) Application(android.app.Application) Before(org.junit.Before)

Aggregations

Application (android.app.Application)123 Test (org.junit.Test)26 Context (android.content.Context)24 Activity (android.app.Activity)22 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 MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)7 ShadowApplication (org.robolectric.shadows.ShadowApplication)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 PrintWriter (java.io.PrintWriter)6 Date (java.util.Date)6 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 BackgroundColorSpan (android.text.style.BackgroundColorSpan)5 CharacterStyle (android.text.style.CharacterStyle)5