1+ package org.utbot.maven.plugin.extension
2+
3+ import org.apache.maven.plugin.testing.AbstractMojoTestCase
4+ import org.apache.maven.project.MavenProject
5+ import org.junit.jupiter.api.*
6+ import org.utbot.common.PathUtil.toPath
7+ import org.utbot.engine.Mocker
8+ import org.utbot.framework.codegen.*
9+ import org.utbot.framework.plugin.api.ClassId
10+ import org.utbot.framework.plugin.api.CodegenLanguage
11+ import org.utbot.framework.plugin.api.MockFramework
12+ import org.utbot.framework.plugin.api.MockStrategyApi
13+ import org.utbot.maven.plugin.GenerateTestsAndSarifReportMojo
14+ import org.utbot.maven.plugin.TestMavenProject
15+ import java.io.File
16+
17+ @TestInstance(TestInstance .Lifecycle .PER_CLASS )
18+ class SarifMavenConfigurationProviderTest : AbstractMojoTestCase () {
19+
20+ @BeforeAll
21+ override fun setUp () {
22+ super .setUp()
23+ }
24+
25+ @AfterAll
26+ override fun tearDown () {
27+ super .tearDown()
28+ }
29+
30+ @Test
31+ fun `targetClasses should be provided from the configuration` () {
32+ Assertions .assertEquals(listOf (" Main" ), configurationProvider.targetClasses)
33+ }
34+
35+ @Test
36+ fun `projectRoot should be provided from the configuration` () {
37+ Assertions .assertEquals(File (" build/resources/project-to-test" ), configurationProvider.projectRoot)
38+ }
39+
40+ @Test
41+ fun `generatedTestsRelativeRoot should be provided from the configuration` () {
42+ Assertions .assertEquals(" target/generated/test" , configurationProvider.generatedTestsRelativeRoot)
43+ }
44+
45+ @Test
46+ fun `sarifReportsRelativeRoot should be provided from the configuration` () {
47+ Assertions .assertEquals(" target/generated/sarif" , configurationProvider.sarifReportsRelativeRoot)
48+ }
49+
50+ @Test
51+ fun `markGeneratedTestsDirectoryAsTestSourcesRoot should be provided from the configuration` () {
52+ Assertions .assertEquals(true , configurationProvider.markGeneratedTestsDirectoryAsTestSourcesRoot)
53+ }
54+
55+ @Test
56+ fun `testFramework should be provided from the configuration` () {
57+ Assertions .assertEquals(Junit5 , configurationProvider.testFramework)
58+ }
59+
60+
61+ @Test
62+ fun `mockFramework should be provided from the configuration` () {
63+ Assertions .assertEquals(MockFramework .MOCKITO , configurationProvider.mockFramework)
64+ }
65+
66+
67+ @Test
68+ fun `generationTimeout should be provided from the configuration` () {
69+ Assertions .assertEquals(10000 , configurationProvider.generationTimeout)
70+ }
71+
72+ @Test
73+ fun `codegenLanguage should be provided from the configuration` () {
74+ Assertions .assertEquals(CodegenLanguage .JAVA , configurationProvider.codegenLanguage)
75+ }
76+
77+ @Test
78+ fun `mockStrategy should be provided from the configuration` () {
79+ Assertions .assertEquals(MockStrategyApi .OTHER_PACKAGES , configurationProvider.mockStrategy)
80+ }
81+
82+ @Test
83+ fun `staticsMocking should be provided from the configuration` () {
84+ Assertions .assertEquals(MockitoStaticMocking , configurationProvider.staticsMocking)
85+ }
86+
87+ @Test
88+ fun `forceStaticMocking should be provided from the configuration` () {
89+ Assertions .assertEquals(ForceStaticMocking .FORCE , configurationProvider.forceStaticMocking)
90+ }
91+
92+ @Test
93+ fun `classesToMockAlways should be provided from the configuration` () {
94+ val expectedClassesToMockAlways =
95+ (Mocker .defaultSuperClassesToMockAlwaysNames + " java.io.File" ).map(::ClassId ).toSet()
96+ Assertions .assertEquals(expectedClassesToMockAlways, configurationProvider.classesToMockAlways)
97+ }
98+
99+ // internal
100+
101+ private val testMavenProject: TestMavenProject =
102+ TestMavenProject (" src/test/resources/project-to-test" .toPath())
103+
104+ private val sarifReportMojo by lazy {
105+ configureSarifReportMojo(testMavenProject.mavenProject)
106+ }
107+
108+ private val configurationProvider by lazy {
109+ sarifReportMojo.sarifProperties
110+ }
111+
112+ private fun configureSarifReportMojo (mavenProject : MavenProject ): GenerateTestsAndSarifReportMojo {
113+ val generateTestsAndSarifReportMojo = configureMojo(
114+ GenerateTestsAndSarifReportMojo (), " utbot-maven" , mavenProject.file
115+ ) as GenerateTestsAndSarifReportMojo
116+ generateTestsAndSarifReportMojo.mavenProject = mavenProject
117+ return generateTestsAndSarifReportMojo
118+ }
119+ }
0 commit comments