Search in sources :

Example 6 with Application

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

the class PresenterManagerTest method returnsSameScopedCacheAndRegisterLifecycleListener.

@Test
public void returnsSameScopedCacheAndRegisterLifecycleListener() {
    Activity activity = Mockito.mock(Activity.class);
    Application application = Mockito.mock(Application.class);
    Mockito.when(activity.getApplication()).thenReturn(application);
    ActivityScopedCache scopedCache1 = PresenterManager.getOrCreateActivityScopedCache(activity);
    ActivityScopedCache scopedCache2 = PresenterManager.getOrCreateActivityScopedCache(activity);
    Assert.assertTrue(scopedCache1 == scopedCache2);
    Mockito.verify(application, Mockito.times(1)).registerActivityLifecycleCallbacks(PresenterManager.activityLifecycleCallbacks);
}
Also used : Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with Application

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

the class PresenterManagerTest method putGetRemoveViewState.

@Test
public void putGetRemoveViewState() {
    Activity activity = Mockito.mock(Activity.class);
    Application application = Mockito.mock(Application.class);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Object viewState = new Object();
    String viewId = "123";
    Assert.assertNull(PresenterManager.getViewState(activity, viewId));
    PresenterManager.putViewState(activity, viewId, viewState);
    Assert.assertTrue(viewState == PresenterManager.getViewState(activity, viewId));
    PresenterManager.remove(activity, viewId);
    Assert.assertNull(PresenterManager.getPresenter(activity, viewId));
}
Also used : Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 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 9 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 10 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)

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