-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from adidas/enhancement/Replace-mockk-with-Test…
…-doubles Enhancement/replace mockk with test doubles
- Loading branch information
Showing
7 changed files
with
187 additions
and
84 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
23 changes: 23 additions & 0 deletions
23
mvi/src/test/kotlin/com/adidas/mvi/reducer/logger/LoggerMatchers.kt
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,23 @@ | ||
package com.adidas.mvi.reducer.logger | ||
|
||
import io.kotest.matchers.string.shouldContainInOrder | ||
|
||
infix fun String?.shouldContainSuccessfulIntent(substr: String): String? { | ||
this.shouldContainInOrder(SUCCESSFUL_INTENT, substr) | ||
return this | ||
} | ||
|
||
infix fun String?.shouldContainFailingIntent(substr: String): String? { | ||
this.shouldContainInOrder(FAILED_INTENT, substr) | ||
return this | ||
} | ||
|
||
infix fun String?.shouldContainSuccessfulTransform(substr: String): String? { | ||
this.shouldContainInOrder(SUCCESSFUL_TRANSFORM, substr) | ||
return this | ||
} | ||
|
||
infix fun String?.shouldContainFailingTransform(substr: String): String? { | ||
this.shouldContainInOrder(FAILED_TRANSFORM, substr) | ||
return this | ||
} |
67 changes: 67 additions & 0 deletions
67
mvi/src/test/kotlin/com/adidas/mvi/reducer/logger/SpyLogger.kt
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.adidas.mvi.reducer.logger | ||
|
||
import com.adidas.mvi.Loggable | ||
import com.adidas.mvi.Logger | ||
import java.lang.StringBuilder | ||
|
||
private const val SPACE = " " | ||
internal const val SUCCESSFUL_INTENT = "SuccessfulIntent:" | ||
internal const val FAILED_INTENT = "FailedIntent:" | ||
internal const val SUCCESSFUL_TRANSFORM = "SuccessfulTransform:" | ||
internal const val FAILED_TRANSFORM = "FailedTransform:" | ||
|
||
class SpyLogger : Logger { | ||
|
||
var history = mutableListOf<String>() | ||
|
||
override fun logIntent(intent: Loggable) { | ||
log(intent.toString()) | ||
log( | ||
StringBuilder().apply { | ||
append(SUCCESSFUL_INTENT) | ||
append(intent.toString()) | ||
}.toString() | ||
) | ||
} | ||
|
||
override fun logFailedIntent(intent: Loggable, throwable: Throwable) { | ||
log( | ||
StringBuilder().apply { | ||
append(FAILED_INTENT) | ||
append(intent.toString()) | ||
append(SPACE) | ||
append(throwable) | ||
}.toString() | ||
) | ||
} | ||
|
||
override fun logTransformedNewState(transform: Loggable, previousState: Loggable, newState: Loggable) { | ||
log( | ||
StringBuilder().apply { | ||
append(SUCCESSFUL_TRANSFORM) | ||
append(transform.toString()) | ||
append(SPACE) | ||
append(previousState.toString()) | ||
append(SPACE) | ||
append(newState.toString()) | ||
}.toString() | ||
) | ||
} | ||
|
||
override fun logFailedTransformNewState(transform: Loggable, state: Loggable, throwable: Throwable) { | ||
log( | ||
StringBuilder().apply { | ||
append(FAILED_TRANSFORM) | ||
append(transform.toString()) | ||
append(SPACE) | ||
append(state.toString()) | ||
append(SPACE) | ||
append(throwable) | ||
}.toString() | ||
) | ||
} | ||
|
||
private fun log(message: String) { | ||
history.add(message) | ||
} | ||
} |
Oops, something went wrong.