Created
May 16, 2019 07:24
-
-
Save louis993546/ad112ed89dcb655429a54869c56a30d8 to your computer and use it in GitHub Desktop.
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 PresenterWithDI( | |
private val networking: NetworkWrapper, | |
private val crashReporting: CrashReporting | |
) { | |
fun onSaveClicked() { | |
val (response, error) = networking.callTheApi() | |
if (error != null) | |
crashReporting.log("Oh no") | |
else | |
Log.d("DI", "Yay") | |
} | |
} |
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 PresenterWithDITest { | |
private val mockNetworking = mock<NetworkWrapper>() | |
private val mockCrashReporting = mock<CrashReporting>() | |
private var presenter = PresenterWithDI(mockNetworking, mockCrashReporting) | |
@Test | |
fun networkError_onSaveClicked_logCrash() { | |
//given | |
when(mockNetworking.callTheApi()).thenReturn(null to ApiWentDownException("pretent API wen't down")) | |
//when | |
presenter.onSaveClicked() | |
//then | |
verify(mockCrashReporting).log("Oh no") | |
} | |
} |
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 PresenterWithoutDI { | |
private val networking: NetworkWrapper = NetworkWrapperImpl() | |
private val crashReporting: CrashReporting = CrashReporting.getInstance() | |
fun onSaveClicked() { | |
val (response, error) = networking.callTheApi() | |
if (error != null) | |
crashReporting.log("Oh no") | |
else | |
Log.d("DI", "Yay") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment