1+ /*
2+ * Copyright 2023 the original author or authors.
3+ * <p>
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ * <p>
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ * <p>
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+ package org .openrewrite .java .migrate .jakarta ;
17+
18+ import org .junit .jupiter .api .Test ;
19+ import org .openrewrite .java .JavaParser ;
20+ import org .openrewrite .test .RecipeSpec ;
21+ import org .openrewrite .test .RewriteTest ;
22+
23+ import static org .openrewrite .java .Assertions .*;
24+ import static org .openrewrite .maven .Assertions .pomXml ;
25+
26+ class MaybeAddJakartaServletApiTest implements RewriteTest {
27+ @ Override
28+ public void defaults (RecipeSpec spec ) {
29+ spec .recipe (new MaybeAddJakartaServletApi ())
30+ .parser (JavaParser .fromJavaVersion ()
31+ .dependsOn ("package javax.servlet;\n public class Filter {}" ));
32+ }
33+
34+ @ Test
35+ void hasSpringBootStarterWeb () {
36+ rewriteRun (
37+ mavenProject ("my-project" ,
38+ srcMainJava (java ("""
39+ import javax.servlet.Filter;
40+ class A {
41+ Filter foo = null;
42+ }
43+ """ )),
44+ pomXml ("""
45+ <?xml version="1.0" encoding="UTF-8"?>
46+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
47+ <modelVersion>4.0.0</modelVersion>
48+ <groupId>org.sample</groupId>
49+ <artifactId>sample</artifactId>
50+ <version>1.0.0</version>
51+
52+ <dependencies>
53+ <dependency>
54+ <groupId>org.springframework.boot</groupId>
55+ <artifactId>spring-boot-starter-web</artifactId>
56+ <version>2.7.0</version>
57+ </dependency>
58+ </dependencies>
59+
60+ </project>
61+ """ )
62+ )
63+ );
64+ }
65+
66+ @ Test
67+ void doesNotHaveSpringBootStarterWeb () {
68+ rewriteRun (
69+ mavenProject ("my-project" ,
70+ srcMainJava (java ("""
71+ import javax.servlet.Filter;
72+ class A {
73+ Filter foo = null;
74+ }
75+ """ )),
76+ pomXml ("""
77+ <?xml version="1.0" encoding="UTF-8"?>
78+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
79+ <modelVersion>4.0.0</modelVersion>
80+ <groupId>org.sample</groupId>
81+ <artifactId>sample</artifactId>
82+ <version>1.0.0</version>
83+
84+ <dependencies>
85+ </dependencies>
86+
87+ </project>
88+ """ ,
89+ """
90+ <?xml version="1.0" encoding="UTF-8"?>
91+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
92+ <modelVersion>4.0.0</modelVersion>
93+ <groupId>org.sample</groupId>
94+ <artifactId>sample</artifactId>
95+ <version>1.0.0</version>
96+
97+ <dependencies>
98+ <dependency>
99+ <groupId>jakarta.servlet</groupId>
100+ <artifactId>jakarta.servlet-api</artifactId>
101+ <version>6.0.0</version>
102+ </dependency>
103+ </dependencies>
104+
105+ </project>
106+ """ )
107+ )
108+ );
109+ }
110+ }
0 commit comments