1
+ package org .springframework .sbm .boot ;
2
+
3
+ import org .junit .jupiter .api .Test ;
4
+
5
+ import org .springframework .sbm .openrewrite .MavenRefactoringTestHelper ;
6
+
7
+ class ChangeMavenPluginConfigurationTest {
8
+
9
+ @ Test
10
+ void happyPath () {
11
+ String given = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
12
+ + " <project xmlns=\" http://maven.apache.org/POM/4.0.0\" \n "
13
+ + " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" \n "
14
+ + " xsi:schemaLocation=\" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" >\n "
15
+ + " <modelVersion>4.0.0</modelVersion>\n "
16
+ + " <parent>\n "
17
+ + " <groupId>org.springframework.boot</groupId>\n "
18
+ + " <artifactId>spring-boot-starter-parent</artifactId>\n "
19
+ + " <version>2.7.3</version>\n "
20
+ + " </parent>\n "
21
+ + " <artifactId>module1</artifactId>\n "
22
+ + " <properties>\n "
23
+ + " <test1>17</test1>\n "
24
+ + " <test2>17</test2>\n "
25
+ + " </properties>\n "
26
+ + " <build>\n "
27
+ + " <plugins>\n "
28
+ + " <plugin>\n "
29
+ + " <groupId>org.apache.maven.plugins</groupId>\n "
30
+ + " <artifactId>maven-compiler-plugin</artifactId>\n "
31
+ + " <configuration>\n "
32
+ + " <source>${test1}</source>\n "
33
+ + " <target>${test2}</target>\n "
34
+ + " </configuration>\n "
35
+ + " </plugin>\n "
36
+ + " </plugins>\n "
37
+ + " </build>\n "
38
+ + " </project>" ;
39
+
40
+ String expected = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
41
+ + " <project xmlns=\" http://maven.apache.org/POM/4.0.0\" \n "
42
+ + " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" \n "
43
+ + " xsi:schemaLocation=\" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" >\n "
44
+ + " <modelVersion>4.0.0</modelVersion>\n "
45
+ + " <parent>\n "
46
+ + " <groupId>org.springframework.boot</groupId>\n "
47
+ + " <artifactId>spring-boot-starter-parent</artifactId>\n "
48
+ + " <version>2.7.3</version>\n "
49
+ + " </parent>\n "
50
+ + " <artifactId>module1</artifactId>\n "
51
+ + " <properties>\n "
52
+ + " <java.version>17</java.version>\n "
53
+ + " </properties>\n "
54
+ + " <build>\n "
55
+ + " <plugins>\n "
56
+ + " <plugin>\n "
57
+ + " <groupId>org.apache.maven.plugins</groupId>\n "
58
+ + " <artifactId>maven-compiler-plugin</artifactId>\n "
59
+ + " <configuration>\n "
60
+ + " <source>${maven.compiler.source}</source>\n "
61
+ + " <target>${maven.compiler.target}</target>\n "
62
+ + " </configuration>\n "
63
+ + " </plugin>\n "
64
+ + " </plugins>\n "
65
+ + " </build>\n "
66
+ + " </project>" ;
67
+
68
+ ChangeMavenCompilerPluginConfiguration sut = new ChangeMavenCompilerPluginConfiguration ();
69
+ MavenRefactoringTestHelper .verifyChange (given , expected , sut );
70
+ }
71
+
72
+ @ Test
73
+ void emptyMavenCompilerConfiguration () {
74
+ String given = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
75
+ + " <project xmlns=\" http://maven.apache.org/POM/4.0.0\" \n "
76
+ + " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" \n "
77
+ + " xsi:schemaLocation=\" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" >\n "
78
+ + " <modelVersion>4.0.0</modelVersion>\n "
79
+ + " <parent>\n "
80
+ + " <groupId>org.springframework.boot</groupId>\n "
81
+ + " <artifactId>spring-boot-starter-parent</artifactId>\n "
82
+ + " <version>2.7.3</version>\n "
83
+ + " </parent>\n "
84
+ + " <artifactId>module1</artifactId>\n "
85
+ + " <properties>\n "
86
+ + " </properties>\n "
87
+ + " <build>\n "
88
+ + " <plugins>\n "
89
+ + " <plugin>\n "
90
+ + " <groupId>org.apache.maven.plugins</groupId>\n "
91
+ + " <artifactId>maven-compiler-plugin</artifactId>\n "
92
+ + " </plugin>\n "
93
+ + " </plugins>\n "
94
+ + " </build>\n "
95
+ + " </project>" ;
96
+
97
+ String expected = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
98
+ + " <project xmlns=\" http://maven.apache.org/POM/4.0.0\" \n "
99
+ + " xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" \n "
100
+ + " xsi:schemaLocation=\" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" >\n "
101
+ + " <modelVersion>4.0.0</modelVersion>\n "
102
+ + " <parent>\n "
103
+ + " <groupId>org.springframework.boot</groupId>\n "
104
+ + " <artifactId>spring-boot-starter-parent</artifactId>\n "
105
+ + " <version>2.7.3</version>\n "
106
+ + " </parent>\n "
107
+ + " <artifactId>module1</artifactId>\n "
108
+ + " <properties>\n "
109
+ + " </properties>\n "
110
+ + " <build>\n "
111
+ + " <plugins>\n "
112
+ + " <plugin>\n "
113
+ + " <groupId>org.apache.maven.plugins</groupId>\n "
114
+ + " <artifactId>maven-compiler-plugin</artifactId>\n "
115
+ + " <configuration>\n "
116
+ + " <source>${maven.compiler.source}</source>\n "
117
+ + " <target>${maven.compiler.target}</target>\n "
118
+ + " </configuration>\n "
119
+ + " </plugin>\n "
120
+ + " </plugins>\n "
121
+ + " </build>\n "
122
+ + " </project>" ;
123
+
124
+ ChangeMavenCompilerPluginConfiguration sut = new ChangeMavenCompilerPluginConfiguration ();
125
+ MavenRefactoringTestHelper .verifyChange (given , expected , sut );
126
+ }
127
+
128
+ }
0 commit comments