Skip to content

Commit

Permalink
refactor: fix for context eror issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 24, 2023
1 parent e0470c4 commit 50a925d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ class ClassTestIns(
override fun unique(): Instruction {
val input = StringBuilder()

input.append(specs.joinToString("\n"))
input.append(specs.joinToString("\n") { "- $it" })
input.append("\n")

if (coreFrameworks.isNotEmpty()) {
input.append("Core frameworks: ${coreFrameworks.joinToString(", ")}\n")
input.append("- You are working on a project that uses ${coreFrameworks.joinToString(", ")}\n")
}

if (testFrameworks.isNotEmpty()) {
input.append("Test frameworks: ${testFrameworks.joinToString(", ")}\n")
input.append("- This project uses ${testFrameworks.joinToString(", ")} to test code.\n")
}

if (coreFrameworks.contains("Spring Boot")) {
input.append("Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc.")
if (coreFrameworks.contains("Spring Boot") || coreFrameworks.contains("Spring Boot Web")) {
input.append("- Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc.")
}

if (relatedCode.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ object ProjectLibrary {
val testStack = TestStack()

deps.forEach { dep ->
val name = dep.depName
SpringLibrary.SPRING_MVC.forEach {
it.coords.forEach { coord ->
if (dep.name.contains(coord)) {
testStack.coreFrameworks.putIfAbsent(it.shortText, true)
}
if (name.contains(it.coords)) {
testStack.coreFrameworks.putIfAbsent(it.shortText, true)
}
}

SpringLibrary.SPRING_DATA.forEach {
it.coords.forEach { coord ->
if (dep.name.contains(coord)) {
if (name.contains(coord)) {
testStack.coreFrameworks.putIfAbsent(it.shortText, true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,39 @@ object SpringLibrary {
// Spring
private val SPRING_MVC_MAVEN = "org.springframework:spring-webmvc"
private val SPRING_WEBFLUX_MAVEN = "org.springframework:spring-webflux"
private val SPRING_BOOT_WEB = "org.springframework.boot:spring-boot-starter-web"
private val SPRING_BOOT = "org.springframework.boot:spring-boot-starter"

// Spring Data
private val REACTOR_MAVEN = "io.projectreactor:reactor-core"
private val MONGO_REACTIVE_STREAMS_MAVEN = "org.mongodb:mongodb-driver-reactivestreams"
private val SPRING_DATA_COMMONS_MAVEN = "org.springframework.data:spring-data-commons"
private val JPA_MAVEN = "org.springframework.data:spring-data-jpa"
private val JPA_BOOT_MAVEN = "org.springframework.boot:spring-boot-starter-data-jpa"

private val CASSANDRA_MAVEN = "org.springframework.data:spring-data-cassandra"
private val COUCHBASE_MAVEN = "org.springframework.data:spring-data-couchbase"

private val JDBC_MAVEN = "org.springframework.data:spring-data-jdbc"
private val JDBC_BOOT_MAVEN = "org.springframework.data:spring-data-mongodb"
private val MONGO_MAVEN = "org.springframework.data:spring-data-mongodb"
private val MONGO_BOOT_MAVEN = "org.springframework.boot:spring-boot-starter-data-mongodb"

private val NEO4J_MAVEN = "org.springframework.data:spring-data-neo4j"
private val R2DBC_MAVEN = "org.springframework.data:spring-data-r2dbc"
private val REDIS_MAVEN = "org.springframework.data:spring-data-redis"

val SPRING_DATA = listOf(
SpringDataLibraryDescriptor("JPA ", listOf(JPA_MAVEN)),
SpringDataLibraryDescriptor("JPA SPRING BOOT", listOf(JPA_MAVEN, REACTOR_MAVEN)),
SpringDataLibraryDescriptor("CASSANDRA", listOf(CASSANDRA_MAVEN)),
SpringDataLibraryDescriptor("REACTIVE CASSANDRA", listOf(CASSANDRA_MAVEN, REACTOR_MAVEN)),
SpringDataLibraryDescriptor("COUCHBASE", listOf(COUCHBASE_MAVEN)),
SpringDataLibraryDescriptor("REACTIVE COUCHBASE", listOf(COUCHBASE_MAVEN, REACTOR_MAVEN)),
SpringDataLibraryDescriptor("JDBC", listOf(JDBC_MAVEN)),
SpringDataLibraryDescriptor("JDBC SPRING BOOT", listOf(JDBC_BOOT_MAVEN)),
SpringDataLibraryDescriptor("MONGO", listOf(MONGO_MAVEN)),
SpringDataLibraryDescriptor("MONGO SPRING BOOT", listOf(MONGO_BOOT_MAVEN)),
SpringDataLibraryDescriptor(
"REACTIVE MONGO",
listOf(MONGO_MAVEN, REACTOR_MAVEN, MONGO_REACTIVE_STREAMS_MAVEN)
Expand All @@ -40,6 +51,8 @@ object SpringLibrary {

val SPRING_MVC = listOf(
LibraryDescriptor("Spring MVC", SPRING_MVC_MAVEN),
LibraryDescriptor("Spring WebFlux", SPRING_WEBFLUX_MAVEN)
LibraryDescriptor("Spring WebFlux", SPRING_WEBFLUX_MAVEN),
LibraryDescriptor("Spring Boot", SPRING_BOOT),
LibraryDescriptor("Spring Boot Web", SPRING_BOOT)
)
}

0 comments on commit 50a925d

Please sign in to comment.