Skip to content

Commit

Permalink
Merge pull request #2 from MarcusAdriano/feature/cover_rate
Browse files Browse the repository at this point in the history
Include: coverage limit rate
  • Loading branch information
MarcusAdriano authored Jun 23, 2020
2 parents 8ac6788 + 29ad782 commit 50a9810
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 135 deletions.
64 changes: 52 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,66 @@ repositories {
}

test {
// listen to events in the test execution lifecycle
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}

onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}

useJUnitPlatform()
finalizedBy jacocoTestReport
}

def jacocoExcludes = [
'io/github/marcusadriano/brawlstars/model/**'
]

def jacocoRulesExcludes = [
'io.github.marcusadriano.brawlstars.model.**'
]

jacocoTestCoverageVerification {
violationRules {
rule {
element = 'METHOD'
excludes = jacocoRulesExcludes
limit {
counter = 'BRANCH'
minimum = 0.9
}
}
}
}

jacocoTestReport {
dependsOn test
reports {
xml.enabled true
csv.enabled false
html.enabled true
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: jacocoExcludes)
}))
}
}

check {
dependsOn jacocoTestCoverageVerification
dependsOn jacocoTestReport
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions {
freeCompilerArgs = ["-Xinline-classes", "-Xjvm-default=compatibility"]
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
Expand All @@ -32,17 +81,8 @@ dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'

testImplementation 'com.squareup.retrofit2:retrofit-mock:2.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions {
freeCompilerArgs = ["-Xinline-classes", "-Xjvm-default=compatibility"]
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'BrawlStarsSDK'
rootProject.name = 'BrawlStars-SDK'

30 changes: 0 additions & 30 deletions src/main/java/examples/MainJavaExample.java

This file was deleted.

60 changes: 0 additions & 60 deletions src/main/java/examples/MainKotlinExample.kt

This file was deleted.

24 changes: 22 additions & 2 deletions src/main/kotlin/io/github/marcusadriano/brawlstars/BrawlStars.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
package io.github.marcusadriano.brawlstars

import io.github.marcusadriano.brawlstars.model.BrawlStarsAuthInterceptor
import io.github.marcusadriano.brawlstars.model.BrawlStarsToken
import io.github.marcusadriano.brawlstars.service.BrawlStarsService
import io.github.marcusadriano.brawlstars.service.BrawlStarsServiceApi
import io.github.marcusadriano.brawlstars.service.impl.BrawlStarsServiceImpl
import java.lang.RuntimeException
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object BrawlStars {

private var service: BrawlStarsService? = null

@JvmStatic fun setup(token: String) {
service = BrawlStarsServiceImpl(BrawlStarsToken(token))
val bsToken = BrawlStarsToken(token)

val tokenInterceptor =
BrawlStarsAuthInterceptor(bsToken)

val okHttpClient = OkHttpClient.Builder()
.addInterceptor(tokenInterceptor)
.build()

val retrofit = Retrofit.Builder()
.client(okHttpClient)
.baseUrl("https://api.brawlstars.com/v1/")
.addConverterFactory(GsonConverterFactory.create())
.build()
val api = retrofit.create(BrawlStarsServiceApi::class.java)
service = BrawlStarsServiceImpl(api)
}

@JvmStatic fun service(): BrawlStarsService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.marcusadriano.brawlstars
package io.github.marcusadriano.brawlstars.model

import okhttp3.Interceptor
import okhttp3.Request
Expand All @@ -10,7 +10,6 @@ internal class BrawlStarsAuthInterceptor(val token: BrawlStarsToken) : Intercept
const val AUTHORIZATION = "Authorization"
}


override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.marcusadriano.brawlstars
package io.github.marcusadriano.brawlstars.model

inline class BrawlStarsToken(private val value: String) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
package io.github.marcusadriano.brawlstars.service.impl

import com.google.gson.Gson
import io.github.marcusadriano.brawlstars.BrawlStarsAuthInterceptor
import io.github.marcusadriano.brawlstars.BrawlStarsToken
import io.github.marcusadriano.brawlstars.model.BattleLog
import io.github.marcusadriano.brawlstars.model.Error
import io.github.marcusadriano.brawlstars.model.Player
import io.github.marcusadriano.brawlstars.model.Result
import io.github.marcusadriano.brawlstars.service.BrawlStarsService
import io.github.marcusadriano.brawlstars.service.BrawlStarsServiceApi
import okhttp3.OkHttpClient
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

internal class BrawlStarsServiceImpl(token: BrawlStarsToken) : BrawlStarsService {

private val retrofit: Retrofit
private val api: BrawlStarsServiceApi

init {
val tokenInterceptor = BrawlStarsAuthInterceptor(token)

val okHttpClient = OkHttpClient.Builder()
.addInterceptor(tokenInterceptor)
.build()

retrofit = Retrofit.Builder()
.client(okHttpClient)
.baseUrl("https://api.brawlstars.com/v1/")
.addConverterFactory(GsonConverterFactory.create())
.build()
api = retrofit.create(BrawlStarsServiceApi::class.java)
}
internal class BrawlStarsServiceImpl(private val api: BrawlStarsServiceApi) : BrawlStarsService {

protected fun <T> parseResult(response: Response<T>): Result<T> {
if (response.isSuccessful) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.marcusadriano.brawlstars

import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

internal class BrawlStarsTest {

@Test
fun `should create BsService Instance`() {
BrawlStars.setup("any")
val bs = BrawlStars.service()
assertNotNull(bs)
}

@Test
fun `should throw RuntimeException`() {
assertThrows<RuntimeException> {
BrawlStars.service()
}
}
}
Loading

0 comments on commit 50a9810

Please sign in to comment.