Skip to content

Commit d2ae86d

Browse files
committed
Polish
1 parent 89c6bd8 commit d2ae86d

File tree

5 files changed

+303
-276
lines changed

5 files changed

+303
-276
lines changed

src/test/java/org/openrewrite/java/spring/AddSpringPropertyTest.java

Lines changed: 132 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -31,154 +31,168 @@ class AddSpringPropertyTest implements RewriteTest {
3131
@Test
3232
void addNestedIntoExisting() {
3333
rewriteRun(
34-
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", null, List.of("*"))),
35-
properties(
36-
"""
37-
server.port=8080
38-
""",
39-
"""
40-
server.port=8080
41-
server.servlet.path=/tmp/my-server-path
42-
"""
43-
),
44-
yaml(
45-
"""
46-
server:
47-
port: 8080
48-
""",
49-
"""
50-
server:
51-
port: 8080
52-
servlet:
53-
path: /tmp/my-server-path
54-
"""
55-
)
34+
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", null, List.of("*"))),
35+
//language=properties
36+
properties(
37+
"""
38+
server.port=8080
39+
""",
40+
"""
41+
server.port=8080
42+
server.servlet.path=/tmp/my-server-path
43+
"""
44+
),
45+
//language=yaml
46+
yaml(
47+
"""
48+
server:
49+
port: 8080
50+
""",
51+
"""
52+
server:
53+
port: 8080
54+
servlet:
55+
path: /tmp/my-server-path
56+
"""
57+
)
5658
);
5759
}
5860

5961
@Test
6062
void addPropertyToRoot() {
6163
rewriteRun(
62-
spec -> spec.recipe(new AddSpringProperty("fred", "fred", null, List.of("*"))),
63-
properties(
64-
"""
65-
servlet.session.cookie.path=/cookie-monster
66-
""",
67-
"""
68-
servlet.session.cookie.path=/cookie-monster
69-
fred=fred
70-
"""
71-
),
72-
yaml(
73-
"""
74-
server:
75-
port: 8888
76-
""",
77-
"""
78-
server:
79-
port: 8888
80-
fred: fred
81-
"""
82-
)
64+
spec -> spec.recipe(new AddSpringProperty("fred", "fred", null, List.of("*"))),
65+
//language=properties
66+
properties(
67+
"""
68+
servlet.session.cookie.path=/cookie-monster
69+
""",
70+
"""
71+
servlet.session.cookie.path=/cookie-monster
72+
fred=fred
73+
"""
74+
),
75+
//language=yaml
76+
yaml(
77+
"""
78+
server:
79+
port: 8888
80+
""",
81+
"""
82+
server:
83+
port: 8888
84+
fred: fred
85+
"""
86+
)
8387
);
8488
}
8589

8690
@Test
8791
void propertyAlreadyExists() {
8892
rewriteRun(
89-
spec -> spec.recipe(new AddSpringProperty("fred", "fred", null, List.of("*"))),
90-
properties(
91-
"""
92-
servlet.session.cookie.path=/cookie-monster
93-
fred=doNotChangeThis
94-
"""
95-
),
96-
yaml(
97-
"""
98-
server:
99-
port: 8888
100-
fred: doNotChangeThis
101-
"""
102-
)
93+
spec -> spec.recipe(new AddSpringProperty("fred", "fred", null, List.of("*"))),
94+
//language=properties
95+
properties(
96+
"""
97+
servlet.session.cookie.path=/cookie-monster
98+
fred=doNotChangeThis
99+
"""
100+
),
101+
//language=yaml
102+
yaml(
103+
"""
104+
server:
105+
port: 8888
106+
fred: doNotChangeThis
107+
"""
108+
)
103109
);
104110
}
105111

106112
@Test
107113
void addPropertyWithComment() {
108114
rewriteRun(
109-
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", "This property was added", List.of("*"))),
110-
properties(
111-
"""
112-
server.port=8080
113-
""",
114-
"""
115-
server.port=8080
116-
server.servlet.path=/tmp/my-server-path
117-
"""
118-
),
119-
yaml(
120-
"""
121-
server:
122-
port: 8080
123-
""",
124-
"""
125-
server:
126-
port: 8080
127-
servlet:
128-
# This property was added
129-
path: /tmp/my-server-path
130-
"""
131-
)
115+
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", "This property was added", List.of("*"))),
116+
//language=properties
117+
properties(
118+
"""
119+
server.port=8080
120+
""",
121+
"""
122+
server.port=8080
123+
server.servlet.path=/tmp/my-server-path
124+
"""
125+
),
126+
//language=yaml
127+
yaml(
128+
"""
129+
server:
130+
port: 8080
131+
""",
132+
"""
133+
server:
134+
port: 8080
135+
servlet:
136+
# This property was added
137+
path: /tmp/my-server-path
138+
"""
139+
)
132140
);
133141
}
134142

135143
@Test
136144
void makeChangeToMatchingFiles() {
137145
rewriteRun(
138-
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", null, List.of("**/application.properties", "**/application.yml"))),
139-
properties(
140-
"""
141-
server.port=8080
142-
""",
143-
"""
144-
server.port=8080
145-
server.servlet.path=/tmp/my-server-path
146-
""",
147-
s -> s.path("src/main/resources/application.properties")
148-
),
149-
yaml(
150-
"""
151-
server:
152-
port: 8080
153-
""",
154-
"""
155-
server:
156-
port: 8080
157-
servlet:
158-
path: /tmp/my-server-path
159-
""",
160-
s -> s.path("src/main/resources/application.yml")
161-
)
146+
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", null, List.of("**/application.properties", "**/application.yml"))),
147+
properties(
148+
//language=properties
149+
"""
150+
server.port=8080
151+
""",
152+
//language=properties
153+
"""
154+
server.port=8080
155+
server.servlet.path=/tmp/my-server-path
156+
""",
157+
s -> s.path("src/main/resources/application.properties")
158+
),
159+
yaml(
160+
//language=yaml
161+
"""
162+
server:
163+
port: 8080
164+
""",
165+
//language=yaml
166+
"""
167+
server:
168+
port: 8080
169+
servlet:
170+
path: /tmp/my-server-path
171+
""",
172+
s -> s.path("src/main/resources/application.yml")
173+
)
162174
);
163175
}
164176

165177
@Test
166178
void doNotChangeToFilesThatDoNotMatch() {
167179
rewriteRun(
168-
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", null, List.of("**/application.properties", "**/application.yml"))),
169-
properties(
170-
"""
171-
server.port=8080
172-
""",
173-
s -> s.path("src/main/resources/application-test.properties")
174-
),
175-
yaml(
176-
"""
177-
server:
178-
port: 8080
179-
""",
180-
s -> s.path("src/main/resources/application-dev.yml")
181-
)
180+
spec -> spec.recipe(new AddSpringProperty("server.servlet.path", "/tmp/my-server-path", null, List.of("**/application.properties", "**/application.yml"))),
181+
properties(
182+
//language=properties
183+
"""
184+
server.port=8080
185+
""",
186+
s -> s.path("src/main/resources/application-test.properties")
187+
),
188+
yaml(
189+
//language=yaml
190+
"""
191+
server:
192+
port: 8080
193+
""",
194+
s -> s.path("src/main/resources/application-dev.yml")
195+
)
182196
);
183197
}
184198
}

0 commit comments

Comments
 (0)