Skip to content

Commit

Permalink
feat: <core> add function test
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 2, 2020
1 parent b1be5fb commit efb00ca
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/kotlin/domain/core/CodeAnnotation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package domain.core

data class AnnotationKeyValue(var Key: String = "", var Value: String = "") {}

open class CodeAnnotation(var Name: String = "", var KeyValues: Array<AnnotationKeyValue>) {
open class CodeAnnotation(
var Name: String = "",
var KeyValues: Array<AnnotationKeyValue> = arrayOf()
) {
open fun isComponentOrRepository(): Boolean {
return this.Name == "Component" || this.Name == "Repository"
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/kotlin/domain/core/CodeFunction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,30 @@ open class CodeFunction(
fun isGetterSetter(): Boolean {
return this.Name.startsWith("set") || this.Name.startsWith("get")
}

fun buildFullMethodName(node: CodeDataStruct): String {
return node.Package + "." + node.NodeName + "." + this.Name
}


fun getAllCallString(): Array<String> {
var calls = arrayOf<String>()
for (codeCall in this.FunctionCalls) {
if (codeCall.NodeName != "") {
calls += codeCall.buildClassFullName()
}
}

return calls
}

fun isJUnitTest(): Boolean {
var isTest = false
for (annotation in this.Annotations) {
if (annotation.isIgnoreOrTest()) {
return true
}
}
return false
}
}
31 changes: 31 additions & 0 deletions src/test/kotlin/domain/core/CodeFunctionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,35 @@ internal class CodeFunctionTest {
assertEquals(CodeFunction(Name = "getFunc").isGetterSetter(), true)
assertEquals(CodeFunction(Name = "setFunc").isGetterSetter(), true)
}

@Test
internal fun shouldEnableBuildFullName() {
val dataStruct = CodeDataStruct(Package = "package", NodeName = "nodeName")

val fullMethodName = CodeFunction(Name = "getFunc").buildFullMethodName(dataStruct)

assertEquals(fullMethodName, "package.nodeName.getFunc")
}

@Test
internal fun shouldGetAllCallStrings() {
var calls = arrayOf<CodeCall>()
calls += CodeCall(Package = "package", NodeName = "nodeName")

val allCallString = CodeFunction(Name = "getFunc", FunctionCalls = calls).getAllCallString()

assertEquals(allCallString.size, 1)
assertEquals(allCallString[0], "package.nodeName")
}


@Test
internal fun shouldHandleJunitTest() {
var annotations = arrayOf<CodeAnnotation>()
annotations += CodeAnnotation(Name = "Test")

val isTest = CodeFunction(Name = "getFunc", Annotations = annotations).isJUnitTest()

assertEquals(isTest, true)
}
}

0 comments on commit efb00ca

Please # to comment.