Skip to content

Commit

Permalink
Code coverage improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanarodr committed May 5, 2024
1 parent b962f73 commit c283838
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package br.com.stonks.common.formatters

import org.junit.Assert.assertEquals
import org.junit.Test
import kotlin.test.assertEquals

class DatePatternTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import br.com.stonks.feature.home.domain.model.TransactionModel
import br.com.stonks.feature.home.domain.types.TransactionType
import br.com.stonks.feature.home.repository.remote.response.DailyTransactionResponse
import br.com.stonks.feature.home.repository.remote.response.TransactionResponse
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.Date
import kotlin.test.assertEquals

class DailyTransactionResponseToModelMapperTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import br.com.stonks.feature.home.domain.model.WalletModel
import br.com.stonks.feature.home.domain.types.PortfolioType
import br.com.stonks.feature.home.repository.remote.response.PortfolioResponse
import br.com.stonks.feature.home.repository.remote.response.WalletResponse
import org.junit.Assert.assertEquals
import org.junit.Test
import kotlin.test.assertEquals

class WalletResponseToModelMapperTest {

Expand Down
3 changes: 2 additions & 1 deletion feature/stocks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ dependencies {
implementation(projects.designSystem)
implementation(projects.infrastructure.network)

implementation(libs.retrofit.core)
implementation(libs.androidx.room.core)
implementation(libs.androidx.room.runtime)
ksp(libs.androidx.room.compiler)

implementation(libs.retrofit.core)
testImplementation(libs.bundles.test.jvm)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package br.com.stonks.feature.stocks.domain.mapper

import br.com.stonks.feature.stocks.domain.model.StockAlertModel
import br.com.stonks.feature.stocks.domain.types.StockAlertType
import br.com.stonks.feature.stocks.domain.types.StockStatusType
import br.com.stonks.feature.stocks.ui.model.AlertUiModel
import org.junit.Assert.assertEquals
import org.junit.Test

class AlertUiToModelMapperTest {

private val sut = AlertUiToModelMapper()

@Test
fun `given ui data when call mapper then convert to model`() {
val expected = createExpectedData()
val result = sut.mapper(createInputData())

assertEquals(expected, result)
}

private fun createInputData() = AlertUiModel(
id = 1L,
ticket = "lorem",
alertValue = 5.0,
status = StockStatusType.AVAILABLE,
alert = StockAlertType.LOW_PRICE,
)

private fun createExpectedData() = StockAlertModel(
id = 1L,
ticket = "lorem",
alertValue = 5.0,
status = StockStatusType.AVAILABLE,
notificationTrigger = StockAlertType.LOW_PRICE,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package br.com.stonks.feature.stocks.domain.mapper

import br.com.stonks.feature.stocks.domain.types.StockAlertType
import br.com.stonks.feature.stocks.domain.types.StockStatusType
import br.com.stonks.feature.stocks.repository.local.StockAlertEntity
import br.com.stonks.feature.stocks.repository.remote.response.StockAlertResponse
import org.junit.Assert.assertEquals
import org.junit.Test

class StockAlertEntityToResponseMapperTest {

private val sut = StockAlertEntityToResponseMapper()

@Test
fun `given entity data when call mapper then convert to response`() {
val expected = createExpectedData()
val result = sut.mapper(createInputData())

assertEquals(expected, result)
}

private fun createInputData() = StockAlertEntity(
id = 1L,
ticket = "lorem",
alertValue = 1.5,
status = StockStatusType.AVAILABLE.status,
notificationTrigger = StockAlertType.LOW_PRICE.status,
)

private fun createExpectedData() = StockAlertResponse(
id = 1L,
stockTicket = "lorem",
alertValue = 1.5,
status = "available",
notificationTrigger = "low",
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package br.com.stonks.feature.stocks.domain.mapper

import br.com.stonks.feature.stocks.domain.model.StockAlertModel
import br.com.stonks.feature.stocks.domain.types.StockAlertType
import br.com.stonks.feature.stocks.domain.types.StockStatusType
import br.com.stonks.feature.stocks.repository.remote.response.StockAlertResponse
import org.junit.Assert.assertEquals
import org.junit.Test

class StockAlertModelToResponseMapperTest {

private val sut = StockAlertModelToResponseMapper()

@Test
fun `given model when call mapper then convert to response`() {
val expected = createExpectedData()
val result = sut.mapper(createInputData())

assertEquals(expected, result)
}

private fun createInputData() = StockAlertModel(
id = 1L,
ticket = "lorem",
alertValue = 5.0,
status = StockStatusType.AVAILABLE,
notificationTrigger = StockAlertType.LOW_PRICE,
)

private fun createExpectedData() = StockAlertResponse(
id = 1L,
stockTicket = "lorem",
alertValue = 5.0,
status = "available",
notificationTrigger = "low",
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package br.com.stonks.feature.stocks.domain.mapper

import br.com.stonks.designsystem.tokens.ColorToken
import br.com.stonks.feature.stocks.domain.model.StockAlertModel
import br.com.stonks.feature.stocks.domain.types.StockAlertType
import br.com.stonks.feature.stocks.domain.types.StockStatusType
import br.com.stonks.feature.stocks.ui.model.AlertUiModel
import br.com.stonks.feature.stocks.ui.model.StockAlertUiModel
import org.junit.Assert.assertEquals
import org.junit.Test

class StockAlertModelToUiMapperTest {

private val sut = StockAlertModelToUiMapper()

@Test
fun `given model when call mapper then convert to ui model`() {
val expected = createResultData()
val result = sut.mapper(createInputData())

assertEquals(expected, result)
}

private fun createInputData() = listOf(
StockAlertModel(
id = 1L,
ticket = "lorem",
alertValue = 1.5,
status = StockStatusType.AVAILABLE,
notificationTrigger = StockAlertType.HIGH_PRICE,
)
)

private fun createResultData() = StockAlertUiModel(
totalAssets = 1.5,
stockAlerts = listOf(
AlertUiModel(
id = 1L,
ticket = "lorem",
alertValue = 1.5,
status = StockStatusType.AVAILABLE,
alert = StockAlertType.HIGH_PRICE,
tagColor = ColorToken.HighlightGreen,
)
),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package br.com.stonks.feature.stocks.domain.mapper

import br.com.stonks.feature.stocks.repository.local.StockAlertEntity
import br.com.stonks.feature.stocks.repository.remote.response.StockAlertResponse
import org.junit.Assert.assertEquals
import org.junit.Test

class StockAlertResponseToEntityMapperTest {

private val sut = StockAlertResponseToEntityMapper()

@Test
fun `given response data when call mapper then convert to entity`() {
val expected = createExpectedData()
val result = sut.mapper(createInputData())

assertEquals(expected, result)
}

private fun createInputData() = StockAlertResponse(
id = 1L,
stockTicket = "lorem",
alertValue = 8.0,
status = "available",
notificationTrigger = "high",
)

private fun createExpectedData() = StockAlertEntity(
id = 1L,
ticket = "lorem",
alertValue = 8.0,
status = "available",
notificationTrigger = "high",
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package br.com.stonks.feature.stocks.domain.mapper

import br.com.stonks.feature.stocks.domain.model.StockAlertModel
import br.com.stonks.feature.stocks.domain.types.StockAlertType
import br.com.stonks.feature.stocks.domain.types.StockStatusType
import br.com.stonks.feature.stocks.repository.remote.response.StockAlertResponse
import org.junit.Assert.assertEquals
import org.junit.Test

class StockAlertResponseToModelMapperTest {

private val sut = StockAlertResponseToModelMapper()

@Test
fun `given response data when call mapper then convert to model`() {
val expected = createExpectedData()
val result = sut.mapper(createInputData())

assertEquals(expected, result)
}

private fun createInputData() = listOf(
StockAlertResponse(
id = 1L,
stockTicket = "lorem",
alertValue = 5.0,
status = "available",
notificationTrigger = "low",
)
)

private fun createExpectedData() = listOf(
StockAlertModel(
id = 1L,
ticket = "lorem",
alertValue = 5.0,
status = StockStatusType.AVAILABLE,
notificationTrigger = StockAlertType.LOW_PRICE,
)
)
}
2 changes: 2 additions & 0 deletions infrastructure/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ dependencies {
implementation(libs.okhttp.logging)
implementation(libs.retrofit.core)
implementation(libs.retrofit.converter)

testImplementation(libs.bundles.test.jvm)
}

0 comments on commit c283838

Please sign in to comment.