Skip to content

Instantly share code, notes, and snippets.

object RetrofitHelper {
/**
* as dependency injection is not used in this project for brevity,
* static object initialization is done for demo purpose.
*
* @param url: Base url for apis
* @return TestApis: Instance of the test api retrofit interface
**/
fun testApiInstance(url: String): TestApis {
install(StatusPages) {
exception<Throwable> { ... }
status(
// any number of status codes can be mentioned
HttpStatusCode.InternalServerError,
HttpStatusCode.BadGateway,
) { call, statusCode ->
when(statusCode) {
install(StatusPages) {
exception<Throwable> { call, throwable ->
when(throwable) {
is ValidationException -> {
call.respond(
HttpStatusCode.BadRequest,
ExceptionResponse("${throwable.message}", HttpStatusCode.BadRequest.value)
)
}
is ParsingException -> {
object UserTable: Table<Nothing>(TABLE_USER_DETAIL) {
val id = int("id").primaryKey()
val first_name = varchar("first_name")
val last_name = varchar("last_name")
val age = int("age")
}
interface DBManager {
fun addUser(user: User): User
fun getAllUsers(): List<User>
fun getById(id: Int): User?
fun delete(id: Int): Boolean
}
object DBHelper {
private var dbUrl = ""
private var dbUser = ""
private var dbPwd = ""
fun Application.configureDbVariables() {
dbUrl = environment.config.propertyOrNull(KEY_DB_URL)?.getString() ?: ""
dbUser = environment.config.propertyOrNull(KEY_DB_USER)?.getString() ?: ""
dbPwd = environment.config.propertyOrNull(KEY_DB_PWD)?.getString() ?: ""
-DDB_URL=jdbc:mysql://127.0.0.1:3306/user_testing_db
-DDB_USER=root
-DDB_PWD=password
-DPORT=8080
@Test
fun withInput_as_1_onButtonClick_displayOnTop() {
// mimic the user inputting the text
composeTestRule.onNodeWithTag("Input").performTextInput("1")
// mimic if the user clicked on the button
composeTestRule.onNodeWithText("Copy").performClick()
// mimic if the user is shown the desired text on UI
composeTestRule.onNodeWithTag("Counter Display").assertTextContains("Counter = 1")
}
@Test
fun counterValue_with_emptyInput_displays_InvalidEntry() {
composeTestRule.onNodeWithText("Copy").performClick()
composeTestRule.onNodeWithTag("Counter Display").assertTextEquals("Invalid entry")
}
@Test
fun verify_if_all_views_exists() {
composeTestRule.onNodeWithTag("Counter Display").assertExists()
composeTestRule.onNodeWithTag("Input").assertExists()
composeTestRule.onNodeWithText("Copy").assertExists()
}