From e2745243551a4977e1dd82f8dd1a023dc8f471ea Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 4 Dec 2023 22:31:38 +0800 Subject: [PATCH] refactor: update for tbs --- README.md | 4 +++- .../eval/picker/bs/BadsmellAnalyser.kt | 5 +++- .../eval/picker/bs/TestBadsmellAnalyser.kt | 2 +- ...nalyserTest.kt => BadsmellAnalyserTest.kt} | 2 +- ...serTest.kt => TestBadsmellAnalyserTest.kt} | 24 +++++++++---------- 5 files changed, 21 insertions(+), 16 deletions(-) rename unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/{BsAnalyserTest.kt => BadsmellAnalyserTest.kt} (99%) rename unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/{TbsAnalyserTest.kt => TestBadsmellAnalyserTest.kt} (85%) diff --git a/README.md b/README.md index 0e570782..af4fc3df 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,11 @@ AutoDev [#54](https://github.com/unit-mesh/auto-dev/issues/56) - [ ] Code quality metrics - [ ] ArchGuard CodeDB metrics: [CodeDB](https://github.com/archguard/codedb) - [ ] AST parser by [Chapi](https://github.com/phodal/chapi) -- [ ] Good code +- [ ] Good code - [x] Test BadSmell from [Coca](https://github.com/phodal/coca) - [ ] BadSmell from [Coca](https://github.com/phodal/coca) + - [x] Long Parameters, Long Method, LARGE_CLASS + - [ ] Todo: Rewrite If, Switch logic - [ ] Estimation from [ArchGuard](https://github.com/archguard/archguard) ### Code Eval diff --git a/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/BadsmellAnalyser.kt b/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/BadsmellAnalyser.kt index 505db035..9ff76589 100644 --- a/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/BadsmellAnalyser.kt +++ b/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/BadsmellAnalyser.kt @@ -53,11 +53,14 @@ class BadsmellAnalyser(val data: List, val bsConfig: BsConfig = } checkLongParameterList(method, node, badSmellList) - checkRepeatedSwitches(method, node, badSmellList) + // Todo: Custom with new API + // checkRepeatedSwitches(method, node, badSmellList) + // Todo: Custom with new API checkComplexIf(method, node, badSmellList) } checkDataClass(onlyHaveGetterAndSetter, node, badSmellList) + // Todo: Custom with new API checkRefusedBequest(node, badSmellList) checkLargeClass(node, badSmellList) } diff --git a/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/TestBadsmellAnalyser.kt b/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/TestBadsmellAnalyser.kt index 34e58a84..026628bf 100644 --- a/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/TestBadsmellAnalyser.kt +++ b/unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/TestBadsmellAnalyser.kt @@ -15,7 +15,7 @@ data class TestBadSmell( ) data class TbsResult(var results: Array) -class TbsAnalyser(val nodes: List) { +class TestBadsmellAnalyser(val nodes: List) { fun analysis(): Array { val tbsResult: TbsResult = TbsResult(arrayOf()) val callMethodMap = buildCallMethodMap(nodes) diff --git a/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/BsAnalyserTest.kt b/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/BadsmellAnalyserTest.kt similarity index 99% rename from unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/BsAnalyserTest.kt rename to unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/BadsmellAnalyserTest.kt index b47b5d06..c78f15cb 100644 --- a/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/BsAnalyserTest.kt +++ b/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/BadsmellAnalyserTest.kt @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test import java.io.File import java.nio.file.Paths -class BsAnalyserTest { +class BadsmellAnalyserTest { private fun getAbsolutePath(path: String): String { val resource = this.javaClass.classLoader.getResource(path) return Paths.get(resource!!.toURI()).toFile().absolutePath diff --git a/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/TbsAnalyserTest.kt b/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/TestBadsmellAnalyserTest.kt similarity index 85% rename from unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/TbsAnalyserTest.kt rename to unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/TestBadsmellAnalyserTest.kt index 466f13eb..e5631c46 100644 --- a/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/TbsAnalyserTest.kt +++ b/unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/TestBadsmellAnalyserTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import java.io.File import java.nio.file.Paths -class TbsAnalyserTest { +class TestBadsmellAnalyserTest { private fun getAbsolutePath(path: String): String { val resource = this.javaClass.classLoader.getResource(path) return Paths.get(resource!!.toURI()).toFile().absolutePath @@ -16,7 +16,7 @@ class TbsAnalyserTest { internal fun shouldIdentifyJavaEmptyTest() { val path = getAbsolutePath("tbs/usecases/EmptyTest.java") val data = JavaAnalyser().analysis(File(path).readText(), "EmptyTest.java").DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results[0].FileName, "EmptyTest.java") assertEquals(results[0].Line, 8) @@ -27,7 +27,7 @@ class TbsAnalyserTest { internal fun shouldIdentifyJavaIgnoreTest() { val path = getAbsolutePath("tbs/usecases/IgnoreTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results[0].Line, 7) assertEquals(results[0].Type, "IgnoreTest") @@ -37,7 +37,7 @@ class TbsAnalyserTest { internal fun shouldIdentifyJavaRedundantPrintTest() { val path = getAbsolutePath("tbs/usecases/RedundantPrintTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results[0].Line, 9) assertEquals(results[0].Type, "RedundantPrintTest") @@ -47,7 +47,7 @@ class TbsAnalyserTest { internal fun shouldIdentifyJavaSleepyTest() { val path = getAbsolutePath("tbs/usecases/SleepyTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results[0].Line, 8) assertEquals(results[0].Type, "SleepyTest") @@ -57,7 +57,7 @@ class TbsAnalyserTest { internal fun shouldIdentifyRedundantAssertionTest() { val path = getAbsolutePath("tbs/usecases/RedundantAssertionTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results[0].Line, 14) assertEquals(results[0].Type, "RedundantAssertionTest") @@ -67,7 +67,7 @@ class TbsAnalyserTest { internal fun shouldIdentifyUnknownTest() { val path = getAbsolutePath("tbs/usecases/UnknownTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results[0].Line, 7) assertEquals(results[0].Type, "EmptyTest") @@ -79,7 +79,7 @@ class TbsAnalyserTest { internal fun shouldIdentifyDuplicateAssertTest() { val path = getAbsolutePath("tbs/usecases/DuplicateAssertTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results[0].Line, 9) assertEquals(results[0].Type, "DuplicateAssertTest") @@ -89,7 +89,7 @@ class TbsAnalyserTest { internal fun shouldReturnEmptyWhenIsCreator() { val path = getAbsolutePath("regression/CreatorNotUnknownTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results.size, 0) } @@ -98,7 +98,7 @@ class TbsAnalyserTest { internal fun shouldReturnEmptyWhenCallAssertInClassTests() { val path = getAbsolutePath("regression/CallAssertInClassTests.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results.size, 0) } @@ -107,7 +107,7 @@ class TbsAnalyserTest { internal fun shouldReturnEmptyWhenCall() { val path = getAbsolutePath("regression/EnvironmentSystemIntegrationTests.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results.size, 0) } @@ -116,7 +116,7 @@ class TbsAnalyserTest { internal fun shouldReturnMultipleResults() { val path = getAbsolutePath("regression/I18NTest.java") val data = JavaAnalyser().analysis(File(path).readText(), path).DataStructures - val results = TbsAnalyser(data).analysis() + val results = TestBadsmellAnalyser(data).analysis() assertEquals(results.size, 4) }