Skip to content

Commit

Permalink
Fix #8 - Migrate Java code to Kotlin
Browse files Browse the repository at this point in the history
=== Details ====
* Add code coverage :) #7
  • Loading branch information
nbentoneves authored and Nuno Bento committed Apr 15, 2020
1 parent cebacd1 commit 5d816d8
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/main/kotlin/com/sesame/core/domain/MethodInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class MethodInfo private constructor(


data class Builder(
var beanIdentification: String? = null,
var packageName: String? = null,
var className: String? = null,
var methodName: String? = null,
var methodDescription: String? = null,
var returnObject: String? = null,
var returnObjectDescription: String? = null,
val paramObjects: MutableMap<Int, ParameterType> = mutableMapOf()) {
private var beanIdentification: String? = null,
private var packageName: String? = null,
private var className: String? = null,
private var methodName: String? = null,
private var methodDescription: String? = null,
private var returnObject: String? = null,
private var returnObjectDescription: String? = null,
private val paramObjects: MutableMap<Int, ParameterType> = mutableMapOf()) {

fun withBeanIdentification(beanIdentification: String) = apply { this.beanIdentification = beanIdentification }
fun withPackageName(packageName: String) = apply { this.packageName = packageName }
Expand Down
13 changes: 12 additions & 1 deletion src/main/kotlin/com/sesame/core/json/domain/AttrDomain.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
package com.sesame.core.json.domain

data class AttrDomain (val isPrimitive : Boolean, val value: Any)
import org.apache.commons.lang3.builder.ToStringBuilder

data class AttrDomain(val isPrimitive: Boolean, val value: Any) {

override fun toString(): String {
return ToStringBuilder(this)
.append("isPrimitive", isPrimitive)
.append("value", value)
.build()
}

}
49 changes: 38 additions & 11 deletions src/test/kotlin/com/sesame/core/InvokerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,34 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method boolean at parameters`() {
fun `verify invoker when return success response from class with method boolean at parameters using reflection`() {

val value: Boolean = true
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.BOOLEAN.internalType.kotlin)))
val expectedParamObjects = mapOf(Pair(1, ParameterType.BOOLEAN))

every { metadata.packageName } returns TestClass::class.java.`package`.name
every { metadata.className } returns TestClass::class.java.simpleName
every { metadata.methodName } returns "method"
every { metadata.paramObjects } returns expectedParamObjects
every { metadata.beanIdentification } returns null

val expectedMethod = TestClass::class.java.getMethod("method", ParameterType.BOOLEAN.internalType)
val expectedParameters: Array<Any> = arrayOf(value)

every { jsonDeserializable.deserialize(eq("JSON_DATA"), eq(expectedParamObjects)) } returns parametersMapping
every { jsonSerializable.serialize(any(), eq(expectedMethod), eq(expectedParameters)) } returns "true"

val result = Invoker(metadata, jsonDeserializable, jsonSerializable, applicationContext).method("JSON_DATA")

assertNotNull(result)
assertTrue(result.isPresent)
assertEquals("true", result.get())

}

@Test
fun `verify invoker when return success response from class with method boolean at parameters using dependency injection`() {

val value: Boolean = true
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.BOOLEAN.internalType.kotlin)))
Expand Down Expand Up @@ -82,9 +109,9 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method char at parameters`() {
fun `verify invoker when return success response from class with method char at parameters using dependency injection`() {

val value: Char = 'a'
val value = 'a'
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.CHAR.internalType.kotlin)))
val expectedParamObjects = mapOf(Pair(1, ParameterType.CHAR))

Expand All @@ -111,7 +138,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method byte at parameters`() {
fun `verify invoker when return success response from class with method byte at parameters using dependency injections`() {

val value: Byte = 1
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.BYTE.internalType.kotlin)))
Expand Down Expand Up @@ -140,7 +167,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method short at parameters`() {
fun `verify invoker when return success response from class with method short at parameters using dependency injection`() {

val value: Short = 10
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.SHORT.internalType.kotlin)))
Expand Down Expand Up @@ -169,7 +196,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method int at parameters`() {
fun `verify invoker when return success response from class with method int at parameters using dependency injection`() {

val value: Int = 10
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.INT.internalType.kotlin)))
Expand Down Expand Up @@ -198,7 +225,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method long at parameters`() {
fun `verify invoker when return success response from class with method long at parameters using dependency injection`() {

val value: Long = 1000
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.LONG.internalType.kotlin)))
Expand Down Expand Up @@ -228,7 +255,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method float at parameters`() {
fun `verify invoker when return success response from class with method float at parameters using dependency injection`() {

val value: Float = 20.5F
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.FLOAT.internalType.kotlin)))
Expand Down Expand Up @@ -258,7 +285,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method double at parameters`() {
fun `verify invoker when return success response from class with method double at parameters using dependency injection`() {

val value: Double = 200000000.5
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.FLOAT.internalType.kotlin)))
Expand Down Expand Up @@ -288,7 +315,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method String at parameters`() {
fun `verify invoker when return success response from class with method String at parameters using dependency injection`() {

val value: String = "Hello World"
val parametersMapping = mapOf(Pair(1, Pair(value, ParameterType.STRING.internalType.kotlin)))
Expand Down Expand Up @@ -318,7 +345,7 @@ class InvokerTest {
}

@Test
fun `verify invoker when return success response from class with method int at parameters with more than one parameter`() {
fun `verify invoker when return success response from class with method int at parameters with more than one parameter using dependency injection`() {

val value1: Int = 10
val value2: Int = 20
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.sesame.core

import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.context.ApplicationContext

//FIXME: Find a way to tests this post processor
class SesameBeanPostProcessorConfigTest {

private lateinit var sesameBeanPostProcessorConfiguration: SesameBeanPostProcessorConfiguration

@MockK
private lateinit var applicationContext: ApplicationContext

@MockK
private lateinit var registry: BeanDefinitionRegistry

@Before
fun before() {
MockKAnnotations.init(this)
sesameBeanPostProcessorConfiguration = SesameBeanPostProcessorConfiguration(applicationContext)
}

@Ignore
@Test
fun `should verify load properties using post processor`() {

every { applicationContext.environment.getProperty(eq("config.file.path.application.context")) } returns "config/path"
sesameBeanPostProcessorConfiguration.postProcessBeanDefinitionRegistry(registry)

}


}
38 changes: 38 additions & 0 deletions src/test/kotlin/com/sesame/core/SesameCoreConfigurationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.sesame.core

import io.mockk.MockKAnnotations.init
import io.mockk.impl.annotations.MockK
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Test
import org.springframework.context.ApplicationContext

class SesameCoreConfigurationTest {

private val sesameCoreConfig = SesameCoreConfiguration()

@MockK
private lateinit var applicationContext: ApplicationContext

@Before
fun before() {
init(this)
}

@Test
fun `should verify getJsonSerializable`() {
assertNotNull(sesameCoreConfig.getJsonSerializable())
}

@Test
fun `should verify getJsonDeserializable`() {
assertNotNull(sesameCoreConfig.getJsonDeserializable())
}

@Test
fun `should verify getSesameBeanPostProcessorConfiguration`(){
assertNotNull(sesameCoreConfig.getSesameBeanPostProcessorConfiguration(applicationContext))
}


}
37 changes: 37 additions & 0 deletions src/test/kotlin/com/sesame/core/json/domain/AttrDomainTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sesame.core.json.domain

import org.hamcrest.Matchers.containsString
import org.hamcrest.core.AllOf.allOf
import org.junit.Assert.*
import org.junit.Test

class AttrDomainTest {

@Test
fun `should verify toString method`() {

val attrDomain = AttrDomain(false, "value")

assertThat(attrDomain.toString(), allOf(
containsString("isPrimitive"),
containsString("value")

))

}

@Test
fun `should verify get method`() {

val attrDomainString = AttrDomain(false, "value")
val attrDomainInt = AttrDomain(true, 10)

assertFalse(attrDomainString.isPrimitive)
assertEquals("value", attrDomainString.value)

assertTrue(attrDomainInt.isPrimitive)
assertEquals(10, attrDomainInt.value)

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sesame.core.worker

import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Test

class DocumentationFactoryImplTest {

@MockK
private lateinit var textDocumentationWorkerImpl: TextDocumentationWorkerImpl

@MockK
private lateinit var yamlDocumentationWorkerImpl: YamlDocumentationWorkerImpl

private lateinit var documentationFactoryImpl: DocumentationFactoryImpl

@Before
fun before() {
MockKAnnotations.init(this)

documentationFactoryImpl = DocumentationFactoryImpl(textDocumentationWorkerImpl,
yamlDocumentationWorkerImpl)
}

@Test
fun `should verify getTextDocumentationWorker`() {
assertNotNull(documentationFactoryImpl.getTextDocumentationWorker())
}

@Test
fun `should verify getYamlDocumentationWorker`() {
assertNotNull(documentationFactoryImpl.getYamlDocumentationWorker())
}

}

0 comments on commit 5d816d8

Please sign in to comment.