forked from sockeqwe/mosby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for MvpNullObjectBasePresenter
- Loading branch information
Showing
6 changed files
with
159 additions
and
9 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
mvp-common/src/main/java/com/hannesdorfmann/mosby/mvp/Defaults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
93 changes: 93 additions & 0 deletions
93
mvp-common/src/test/java/com/hannesdorfmann/mosby/mvp/MvpNullObjectBasePresenterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2015. Hannes Dorfmann. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.hannesdorfmann.mosby.mvp; | ||
|
||
import java.util.Date; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Hannes Dorfmann | ||
*/ | ||
public class MvpNullObjectBasePresenterTest { | ||
|
||
public interface TestView extends MvpView { | ||
public void showFoo(TestData data); | ||
|
||
public void showThat(); | ||
} | ||
|
||
public class TestData { | ||
int a; | ||
String b; | ||
Date date = new Date(); | ||
} | ||
|
||
public class TestNullObjectPresenter | ||
extends MvpNullObjectBasePresenter<MvpNullObjectBasePresenterTest.TestView> { | ||
|
||
public void viewShowFoo(TestData data) { | ||
getView().showFoo(data); | ||
} | ||
|
||
public void viewShowThat() { | ||
getView().showThat(); | ||
} | ||
} | ||
|
||
@Test public void testAttachDetach() { | ||
|
||
TestNullObjectPresenter presenter = new TestNullObjectPresenter(); | ||
|
||
try { | ||
// NullPointer exception should be thrown | ||
presenter.getView(); | ||
Assert.fail("Nullpointer Exception should be thrown but haven't"); | ||
} catch (NullPointerException e) { | ||
// Expected exception | ||
} | ||
|
||
TestView view = new TestView() { | ||
@Override public void showFoo(TestData data) { | ||
} | ||
|
||
@Override public void showThat() { | ||
} | ||
}; | ||
|
||
presenter.attachView(view); | ||
Assert.assertNotNull(presenter.getView()); | ||
Assert.assertTrue(presenter.getView() == view); | ||
|
||
// Test with retainInstance == false | ||
presenter.detachView(false); | ||
Assert.assertNotNull(presenter.getView()); | ||
Assert.assertTrue(presenter.getView() != view); // Null Object view | ||
|
||
// Reattach real view | ||
presenter.attachView(view); | ||
Assert.assertNotNull(presenter.getView()); | ||
Assert.assertTrue(presenter.getView() == view); | ||
|
||
// Test with retainInstance == true | ||
presenter.detachView(true); | ||
Assert.assertNotNull(presenter.getView()); | ||
Assert.assertTrue(presenter.getView() != view); // Null Object view | ||
} | ||
|
||
} |