Skip to content

Commit

Permalink
Used spy to get BackwardCompatibilityCheckCommand tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrosario committed May 29, 2024
1 parent 13805eb commit ef5c73c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package application
import `in`.specmatic.conversions.OpenApiSpecification
import `in`.specmatic.core.CONTRACT_EXTENSIONS
import `in`.specmatic.core.git.GitCommand
import `in`.specmatic.core.git.SystemGit
import `in`.specmatic.core.testBackwardCompatibility
import `in`.specmatic.core.utilities.exitWithMessage
import org.springframework.stereotype.Component
Expand All @@ -17,7 +18,7 @@ import java.util.concurrent.Callable
description = ["Checks backward compatibility of a directory across the current HEAD and the main branch"]
)
open class BackwardCompatibilityCheckCommand(
private val gitCommand: GitCommand,
private val gitCommand: GitCommand = SystemGit(),
) : Callable<Unit> {

private val newLine = System.lineSeparator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package application

import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import java.io.File
Expand All @@ -17,7 +20,7 @@ class BackwardCompatibilityCheckCommandTest {

@Test
fun `filesReferringToChangedSchemaFiles returns empty set when no files refer to changed schema files`() {
val command = BackwardCompatibilityCheckCommand(mockk(relaxed = true))
val command = spyk<BackwardCompatibilityCheckCommand>()
every { command.allOpenApiSpecFiles() } returns listOf(
File("file1.yaml").apply { writeText("content1") },
File("file2.yaml").apply { writeText("content2") }
Expand All @@ -28,12 +31,19 @@ class BackwardCompatibilityCheckCommandTest {

@Test
fun `filesReferringToChangedSchemaFiles returns set of files that refer to changed schema files`() {
val command = mockk<BackwardCompatibilityCheckCommand>(relaxed = true)
val command = spyk<BackwardCompatibilityCheckCommand>()
every { command.allOpenApiSpecFiles() } returns listOf(
File("file1.yaml").apply { writeText("file3.yaml") },
File("file2.yaml").apply { writeText("file4.yaml") }
)
val result = command.filesReferringToChangedSchemaFiles(setOf("file3.yaml"))
assertEquals(setOf("file1.yaml"), result)
}

@AfterEach
fun `cleanup files`() {
listOf(File("file1.yaml"), File("file2.yaml")).forEach {
it.delete()
}
}
}

0 comments on commit ef5c73c

Please sign in to comment.