Skip to content

Commit

Permalink
refactor: update for tbs
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 4, 2023
1 parent 1e4710e commit e274524
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ class BadsmellAnalyser(val data: List<CodeDataStruct>, 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class TestBadSmell(
)
data class TbsResult(var results: Array<TestBadSmell>)

class TbsAnalyser(val nodes: List<CodeDataStruct>) {
class TestBadsmellAnalyser(val nodes: List<CodeDataStruct>) {
fun analysis(): Array<TestBadSmell> {
val tbsResult: TbsResult = TbsResult(arrayOf())
val callMethodMap = buildCallMethodMap(nodes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit e274524

Please sign in to comment.