generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lennart Heimbs <[email protected]>
- Loading branch information
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
.../test/kotlin/com/amos/pitmutationmate/pitmutationmate/execution/GradleTaskExecutorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2023 Lennart Heimbs | ||
|
||
package com.amos.pitmutationmate.pitmutationmate.execution | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertFalse | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.MockitoAnnotations | ||
|
||
/** | ||
* Tests for GradleTaskExecutor | ||
* | ||
* @see GradleTaskExecutor | ||
*/ | ||
class GradleTaskExecutorTest { | ||
@Mock | ||
lateinit var systemInfo: SystemInfoProvider // Assuming SystemInfo is a dependency | ||
|
||
@InjectMocks | ||
lateinit var gradleTaskExecutor: GradleTaskExecutor | ||
|
||
@BeforeEach | ||
fun setup() { | ||
MockitoAnnotations.openMocks(this) | ||
} | ||
|
||
@Test | ||
fun `test buildCommandLine for Windows`() { | ||
`when`(systemInfo.isWindows()).thenReturn(true) | ||
|
||
val commandLine = gradleTaskExecutor.buildCommandLine( | ||
null, | ||
"clean", | ||
"/path/to/project", | ||
"com.example.Class", | ||
8080 | ||
) | ||
|
||
assertEquals(GradleTaskExecutor.WINDOWS_SHELL_EXECUTABLE, commandLine.exePath) | ||
assertEquals(GradleTaskExecutor.WINDOWS_FIRST_PARAMETER, commandLine.parametersList.parameters[0]) | ||
assertEquals(GradleTaskExecutor.WINDOWS_GRADLE_EXECUTABLE, commandLine.parametersList.parameters[1]) | ||
} | ||
|
||
@Test | ||
fun `test buildCommandLine for Unix`() { | ||
`when`(systemInfo.isWindows()).thenReturn(false) | ||
|
||
val commandLine = gradleTaskExecutor.buildCommandLine( | ||
null, | ||
"clean", | ||
"/path/to/project", | ||
"com.example.Class", | ||
8080 | ||
) | ||
|
||
assertEquals(GradleTaskExecutor.UNIX_SHELL_EXECUTABLE, commandLine.exePath) | ||
assertEquals(GradleTaskExecutor.UNIX_FIRST_PARAMETER, commandLine.parametersList.parameters[0]) | ||
assertEquals(GradleTaskExecutor.UNIX_GRADLE_EXECUTABLE, commandLine.parametersList.parameters[1]) | ||
} | ||
|
||
@Test | ||
fun `test buildCommandLine without taskName uses default taskName`() { | ||
`when`(systemInfo.isWindows()).thenReturn(true) | ||
|
||
val commandLine = gradleTaskExecutor.buildCommandLine( | ||
null, | ||
null, | ||
"/path/to/project", | ||
"com.example.Class", | ||
8080 | ||
) | ||
|
||
assertEquals(GradleTaskExecutor.PITEST_TASK_NAME, commandLine.parametersList.parameters[2]) | ||
} | ||
|
||
@Test | ||
fun `test buildCommandLine with taskName uses given taskName`() { | ||
`when`(systemInfo.isWindows()).thenReturn(true) | ||
|
||
val taskName = "test123" | ||
val commandLine = gradleTaskExecutor.buildCommandLine( | ||
null, | ||
taskName, | ||
"/path/to/project", | ||
"com.example.Class", | ||
8080 | ||
) | ||
|
||
assertEquals(taskName, commandLine.parametersList.parameters[2]) | ||
} | ||
|
||
@Test | ||
fun `test buildCommandLine without classFQDN does not add targetClass override`() { | ||
`when`(systemInfo.isWindows()).thenReturn(true) | ||
|
||
val commandLine = gradleTaskExecutor.buildCommandLine( | ||
null, | ||
"clean", | ||
"/path/to/project", | ||
null, | ||
8080 | ||
) | ||
|
||
for (parameter in commandLine.parametersList.parameters) { | ||
assertFalse(parameter.contains("-Dpitmutationmate.override.targetClasses")) | ||
} | ||
} | ||
|
||
@Test | ||
fun `test buildCommandLine with classFQDN adds targetClass override`() { | ||
`when`(systemInfo.isWindows()).thenReturn(true) | ||
|
||
val classFQN = "com.example.Class" | ||
val commandLine = gradleTaskExecutor.buildCommandLine( | ||
null, | ||
"clean", | ||
"/path/to/project", | ||
classFQN, | ||
8080 | ||
) | ||
|
||
assertTrue( | ||
commandLine.parametersList.parameters.contains("-Dpitmutationmate.override.targetClasses=$classFQN") | ||
) | ||
} | ||
} |