Search in sources :

Example 11 with Application

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

the class FragmentMvpDelegateImplTest method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.mock(PartialMvpDelegateCallbackImpl.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    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);
    delegate = new FragmentMvpDelegateImpl<>(fragment, callback, true, true);
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) Fragment(android.support.v4.app.Fragment) Application(android.app.Application) Before(org.junit.Before)

Example 12 with Application

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

the class ViewGroupMvpDelegateImplTest method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.mock(PartialViewGroupMvpDelegateCallbackImpl.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    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);
    delegate = new ViewGroupMvpDelegateImpl<>(callback, true);
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) Application(android.app.Application) Before(org.junit.Before)

Example 13 with Application

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

the class PresenterManagerTest method getViewStateThrowsNullPointerException.

@Test
public void getViewStateThrowsNullPointerException() {
    try {
        PresenterManager.getViewState(null, "123");
        Assert.fail("Exception expected");
    } catch (NullPointerException e) {
    }
    try {
        Activity activity = Mockito.mock(Activity.class);
        Application application = Mockito.mock(Application.class);
        Mockito.when(activity.getApplication()).thenReturn(application);
        PresenterManager.getViewState(activity, 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 14 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 15 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)

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