This file contains hidden or 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
class ExamplePresenterTest { | |
//Setup code... | |
@Test | |
fun `test_fetchProfileName_calles_onProfileNameReceived_on_positive_response`() { | |
Mockito.`when`(presenter.fetchProfileNameFromRepository())) | |
.thenReturn("Gil Goldzweig") | |
This file contains hidden or 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
@RunWith(MockitoJUnitRunner::class) | |
class ExamplePresenterTest { | |
@Mock | |
private lateinit var view: ExampleContract.View | |
@Spy | |
private var presenter: ExamplePresenter = ExamplePresenter() | |
@Before |
This file contains hidden or 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
class ExampleActivity : AppCompatActivity(), ExampleContract.View { | |
lateinit var presenter: ExampleContract.Presenter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
//Inject the presenter using Dependecy injection | |
This file contains hidden or 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
open class ExamplePresenter : ExampleContract.Presenter { | |
var view: ExampleContract.View? = null | |
override fun attach(view: ExampleContract.View) { | |
this.view = view | |
} | |
override fun fetchProfileName() { |
This file contains hidden or 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
interface ExampleContract : BaseContract { | |
interface View : BaseContract.View { | |
fun onProfileNameReceived(name: String) | |
fun onProfileNameRequestFailed(exception: Exception) | |
} | |
interface Presenter : BaseContract.Presenter<View> { |
This file contains hidden or 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
@RunWith(MockitoJUnitRunner::class) | |
class ExamplePresenterTest { | |
@Mock | |
private lateinit var view: ExampleContract.View | |
@Spy | |
private var presenter: ExamplePresenter = ExamplePresenter() | |
This file contains hidden or 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
interface ExampleContract : BaseContract { | |
interface View : BaseContract.View { | |
/** | |
* example of successful response | |
*/ | |
fun onProfileNameReceived(name: String) | |
/** | |
* example of a failure response |
This file contains hidden or 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
/** | |
* A base presenter class that include some functionality and helping | |
*/ | |
abstract class BasePresenter<V : BaseContract.View> : | |
CoroutineScope, LifecycleObserver, BaseContract.Presenter<V> { | |
open var job: Job = Job() | |
var lifecycle: Lifecycle? = null |
This file contains hidden or 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
interface BaseContract { | |
@UiThread | |
interface View | |
interface Presenter<V : View> { | |
fun attach(view: V) | |
fun detach() |