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
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 { |
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
install(StatusPages) { | |
exception<Throwable> { ... } | |
status( | |
// any number of status codes can be mentioned | |
HttpStatusCode.InternalServerError, | |
HttpStatusCode.BadGateway, | |
) { call, statusCode -> | |
when(statusCode) { |
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
install(StatusPages) { | |
exception<Throwable> { call, throwable -> | |
when(throwable) { | |
is ValidationException -> { | |
call.respond( | |
HttpStatusCode.BadRequest, | |
ExceptionResponse("${throwable.message}", HttpStatusCode.BadRequest.value) | |
) | |
} | |
is ParsingException -> { |
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
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") | |
} |
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
interface DBManager { | |
fun addUser(user: User): User | |
fun getAllUsers(): List<User> | |
fun getById(id: Int): User? | |
fun delete(id: Int): Boolean | |
} |
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
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() ?: "" |
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
-DDB_URL=jdbc:mysql://127.0.0.1:3306/user_testing_db | |
-DDB_USER=root | |
-DDB_PWD=password | |
-DPORT=8080 |
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
@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") | |
} |
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
@Test | |
fun counterValue_with_emptyInput_displays_InvalidEntry() { | |
composeTestRule.onNodeWithText("Copy").performClick() | |
composeTestRule.onNodeWithTag("Counter Display").assertTextEquals("Invalid entry") | |
} |
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
@Test | |
fun verify_if_all_views_exists() { | |
composeTestRule.onNodeWithTag("Counter Display").assertExists() | |
composeTestRule.onNodeWithTag("Input").assertExists() | |
composeTestRule.onNodeWithText("Copy").assertExists() | |
} |