-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94dd919
commit 88357f1
Showing
2 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ "*" ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: gradle | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Build with Gradle | ||
env: | ||
MS_KEY_1: ${{ secrets.MS_KEY_1 }} | ||
run: ./gradlew :main:testDevDebug --tests "tw.firemaples.onscreenocr.MicrosoftAzureAPIServiceTest" |
36 changes: 36 additions & 0 deletions
36
main/src/test/java/tw/firemaples/onscreenocr/MicrosoftAzureAPIServiceTest.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,36 @@ | ||
package tw.firemaples.onscreenocr | ||
|
||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.moshi.MoshiConverterFactory | ||
import tw.firemaples.onscreenocr.translator.azure.MicrosoftAzureAPIService | ||
import tw.firemaples.onscreenocr.translator.azure.TranslateRequest | ||
|
||
class MicrosoftAzureAPIServiceTest { | ||
private val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl("http://localhost/") | ||
.addConverterFactory(MoshiConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
private val apiService: MicrosoftAzureAPIService by lazy { | ||
retrofit.create(MicrosoftAzureAPIService::class.java) | ||
} | ||
|
||
@Test | ||
fun test() = runTest { | ||
val key = System.getenv().getOrDefault("MS_KEY_1", "") | ||
|
||
val result = apiService.translate( | ||
subscriptionKey = key, | ||
to = "fr", | ||
request = TranslateRequest.single("Hello"), | ||
) | ||
|
||
val actual = result.body()?.firstOrNull()?.translations?.firstOrNull()?.text | ||
assertEquals("Bonjour", actual) | ||
} | ||
} |