Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: created test for getCommentToUpload fix: upload comment
- Loading branch information
Showing
4 changed files
with
71 additions
and
15 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
55 changes: 55 additions & 0 deletions
55
...src/test/java/openfoodfacts/github/scrachx/openfood/repositories/ProductRepositoryTest.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,55 @@ | ||
package openfoodfacts.github.scrachx.openfood.repositories | ||
|
||
import android.content.Context | ||
import com.google.common.truth.Truth.assertThat | ||
import io.mockk.every | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.mockk | ||
import io.mockk.mockkStatic | ||
import openfoodfacts.github.scrachx.openfood.BuildConfig | ||
import openfoodfacts.github.scrachx.openfood.utils.InstallationService | ||
import openfoodfacts.github.scrachx.openfood.utils.getVersionName | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class ProductRepositoryTest { | ||
|
||
private lateinit var mockContext: Context | ||
private lateinit var mockInstallationService: InstallationService | ||
|
||
@BeforeEach | ||
fun beforeAll() { | ||
mockkStatic("openfoodfacts.github.scrachx.openfood.utils.ContextKt") | ||
mockInstallationService = mockk { | ||
every { id } returns "FAKE_ID" | ||
} | ||
mockContext = mockk { | ||
every { getVersionName() } returns "TEST_VERSION_NAME" | ||
} | ||
} | ||
|
||
@Test | ||
fun `comment to upload with username`() { | ||
// Logged in test | ||
assertThat( | ||
ProductRepository.getCommentToUpload( | ||
mockContext, | ||
mockInstallationService, | ||
"USERNAME" | ||
) | ||
).isEqualTo("Official " + BuildConfig.APP_NAME + " Android app TEST_VERSION_NAME") | ||
} | ||
|
||
@Test | ||
fun `comment to upload without username`() { | ||
assertThat( | ||
ProductRepository.getCommentToUpload( | ||
mockContext, | ||
mockInstallationService, | ||
null | ||
) | ||
).isEqualTo("Official " + BuildConfig.APP_NAME + " Android app TEST_VERSION_NAME (Added by FAKE_ID)") | ||
} | ||
} |
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