-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
254 additions
and
17 deletions.
There are no files selected for viewing
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
56 changes: 56 additions & 0 deletions
56
moxy/src/test/java/com/arellomobile/mvp/inheritance_test/InheritanceTest.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,56 @@ | ||
package com.arellomobile.mvp.inheritance_test; | ||
|
||
import android.os.Bundle; | ||
|
||
import com.arellomobile.mvp.MvpDelegate; | ||
import com.arellomobile.mvp.inheritance_test.resources.ChildViewWithoutInject; | ||
import com.arellomobile.mvp.inheritance_test.resources.SuperViewWithInject; | ||
import com.arellomobile.mvp.inheritance_test.resources.ViewWithoutInject; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
/** | ||
* Date: 30.12.2016 | ||
* Time: 00:29 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(manifest = Config.NONE) | ||
public class InheritanceTest { | ||
|
||
@Test | ||
public void testWithoutInject() { | ||
ViewWithoutInject view = new ViewWithoutInject(); | ||
|
||
view.delegate = new MvpDelegate<>(view); | ||
|
||
view.delegate.onCreate(new Bundle()); | ||
} | ||
|
||
@Test | ||
public void testInjectInInherited() { | ||
SuperViewWithInject view = new SuperViewWithInject(); | ||
|
||
view.delegate = new MvpDelegate<>(view); | ||
|
||
view.delegate.onCreate(new Bundle()); | ||
|
||
Assert.assertNotNull(view.presenter); | ||
} | ||
|
||
@Test | ||
public void testInjectOnlyInSuper() { | ||
ChildViewWithoutInject view = new ChildViewWithoutInject(); | ||
|
||
view.delegate = new MvpDelegate<>(view); | ||
|
||
view.delegate.onCreate(); | ||
|
||
Assert.assertNotNull(view.presenter); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...src/test/java/com/arellomobile/mvp/inheritance_test/resources/ChildViewWithoutInject.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,10 @@ | ||
package com.arellomobile.mvp.inheritance_test.resources; | ||
|
||
/** | ||
* Date: 30.12.2016 | ||
* Time: 00:13 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
public class ChildViewWithoutInject extends SuperViewWithInject implements TestView { | ||
} |
14 changes: 14 additions & 0 deletions
14
moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/SuperViewWithInject.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,14 @@ | ||
package com.arellomobile.mvp.inheritance_test.resources; | ||
|
||
import com.arellomobile.mvp.presenter.InjectPresenter; | ||
|
||
/** | ||
* Date: 30.12.2016 | ||
* Time: 00:11 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
public class SuperViewWithInject extends ViewWithoutInject implements TestView { | ||
@InjectPresenter | ||
public TestPresenter presenter; | ||
} |
13 changes: 13 additions & 0 deletions
13
moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestPresenter.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,13 @@ | ||
package com.arellomobile.mvp.inheritance_test.resources; | ||
|
||
import com.arellomobile.mvp.MvpPresenter; | ||
|
||
/** | ||
* Date: 29.12.2016 | ||
* Time: 14:32 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
@SuppressWarnings("WeakerAccess") | ||
public class TestPresenter extends MvpPresenter<TestView> { | ||
} |
12 changes: 12 additions & 0 deletions
12
moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestView.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,12 @@ | ||
package com.arellomobile.mvp.inheritance_test.resources; | ||
|
||
import com.arellomobile.mvp.MvpView; | ||
|
||
/** | ||
* Date: 29.12.2016 | ||
* Time: 14:31 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
public interface TestView extends MvpView { | ||
} |
13 changes: 13 additions & 0 deletions
13
moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ViewWithoutInject.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,13 @@ | ||
package com.arellomobile.mvp.inheritance_test.resources; | ||
|
||
import com.arellomobile.mvp.MvpDelegate; | ||
|
||
/** | ||
* Date: 30.12.2016 | ||
* Time: 00:09 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
public class ViewWithoutInject { | ||
public MvpDelegate<? extends ViewWithoutInject> delegate; | ||
} |
67 changes: 67 additions & 0 deletions
67
moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.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,67 @@ | ||
package com.arellomobile.mvp.memory_leak_test; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import android.os.Bundle; | ||
|
||
import com.arellomobile.mvp.MvpDelegate; | ||
import com.arellomobile.mvp.memory_leak_test.resources.TestViewImplementation; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Date: 29.12.2016 | ||
* Time: 14:29 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(manifest = Config.NONE) | ||
public class MemoryLeakTest { | ||
@Test | ||
public void test() { | ||
TestViewImplementation viewImplementation = new TestViewImplementation(); | ||
|
||
viewImplementation.delegate = new MvpDelegate<>(viewImplementation); | ||
|
||
viewImplementation.delegate.onCreate(new Bundle()); | ||
|
||
viewImplementation.delegate.onDestroy(); | ||
|
||
WeakReference viewImplementationReference = new WeakReference(viewImplementation); | ||
WeakReference presenterReference = new WeakReference(viewImplementation.presenter); | ||
|
||
/** | ||
* Remove local reference to this object. Test will been failed if reference to the implemented view or | ||
* to presenter was being saved in Moxy | ||
*/ | ||
//noinspection UnusedAssignment | ||
viewImplementation = null; | ||
|
||
long delay = 0; | ||
|
||
while (delay < TimeUnit.SECONDS.toMillis(2)) { | ||
System.gc(); | ||
|
||
if (viewImplementationReference.get() == null && presenterReference.get() == null) { | ||
return; | ||
} | ||
|
||
try { | ||
TimeUnit.MILLISECONDS.sleep(100); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
delay += 100; | ||
} | ||
|
||
assertTrue(false); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestPresenter.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,12 @@ | ||
package com.arellomobile.mvp.memory_leak_test.resources; | ||
|
||
import com.arellomobile.mvp.MvpPresenter; | ||
|
||
/** | ||
* Date: 29.12.2016 | ||
* Time: 14:32 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
public class TestPresenter extends MvpPresenter<TestView> { | ||
} |
12 changes: 12 additions & 0 deletions
12
moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestView.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,12 @@ | ||
package com.arellomobile.mvp.memory_leak_test.resources; | ||
|
||
import com.arellomobile.mvp.MvpView; | ||
|
||
/** | ||
* Date: 29.12.2016 | ||
* Time: 14:31 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
public interface TestView extends MvpView { | ||
} |
18 changes: 18 additions & 0 deletions
18
...src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestViewImplementation.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,18 @@ | ||
package com.arellomobile.mvp.memory_leak_test.resources; | ||
|
||
import com.arellomobile.mvp.MvpDelegate; | ||
import com.arellomobile.mvp.presenter.InjectPresenter; | ||
|
||
/** | ||
* Date: 29.12.2016 | ||
* Time: 14:33 | ||
* | ||
* @author Yuri Shmakov | ||
*/ | ||
|
||
public class TestViewImplementation implements TestView { | ||
@InjectPresenter | ||
public TestPresenter presenter; | ||
|
||
public MvpDelegate<TestViewImplementation> delegate; | ||
} |
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