Skip to content

Commit a4c72c8

Browse files
committed
Polish integration tests
1 parent 3d7862a commit a4c72c8

File tree

3 files changed

+42
-83
lines changed

3 files changed

+42
-83
lines changed

spring-context/src/test/java/org/springframework/scheduling/support/PeriodicTriggerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void fixedRateWithTimeUnitSubsequentExecution() {
184184
void equalsVerification() {
185185
PeriodicTrigger trigger1 = new PeriodicTrigger(Duration.ofMillis(3000));
186186
PeriodicTrigger trigger2 = new PeriodicTrigger(Duration.ofMillis(3000));
187-
assertThat(trigger1.equals(new String("not a trigger"))).isFalse();
187+
assertThat(trigger1).isNotEqualTo(new String("not a trigger"));
188188
assertThat(trigger1).isNotEqualTo(null);
189189
assertThat(trigger1).isEqualTo(trigger1);
190190
assertThat(trigger2).isEqualTo(trigger2);

spring-context/src/test/java/org/springframework/scripting/bsh/BshScriptFactoryTests.java

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,13 @@ void staticScript() {
6161
Calculator calc = (Calculator) ctx.getBean("calculator");
6262
Messenger messenger = (Messenger) ctx.getBean("messenger");
6363

64-
boolean condition3 = calc instanceof Refreshable;
65-
assertThat(condition3).as("Scripted object should not be instance of Refreshable").isFalse();
66-
boolean condition2 = messenger instanceof Refreshable;
67-
assertThat(condition2).as("Scripted object should not be instance of Refreshable").isFalse();
64+
assertThat(calc).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
65+
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
6866

6967
assertThat(calc).isEqualTo(calc);
7068
assertThat(messenger).isEqualTo(messenger);
71-
boolean condition1 = !messenger.equals(calc);
72-
assertThat(condition1).isTrue();
7369
assertThat(messenger.hashCode()).isNotEqualTo(calc.hashCode());
74-
boolean condition = !messenger.toString().equals(calc.toString());
75-
assertThat(condition).isTrue();
70+
assertThat(messenger.toString()).isNotEqualTo(calc.toString());
7671

7772
assertThat(calc.add(2, 3)).isEqualTo(5);
7873

@@ -145,8 +140,7 @@ void staticPrototypeScript() {
145140
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
146141

147142
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
148-
boolean condition = messenger instanceof Refreshable;
149-
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
143+
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
150144

151145
assertThat(messenger2).isNotSameAs(messenger);
152146
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@@ -165,8 +159,7 @@ void nonStaticScript() {
165159
Messenger messenger = (Messenger) ctx.getBean("messenger");
166160

167161
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
168-
boolean condition = messenger instanceof Refreshable;
169-
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
162+
assertThat(messenger).as("Should be an instance of Refreshable").isInstanceOf(Refreshable.class);
170163

171164
String desiredMessage = "Hello World!";
172165
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -186,8 +179,7 @@ void nonStaticPrototypeScript() {
186179
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
187180

188181
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
189-
boolean condition = messenger instanceof Refreshable;
190-
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
182+
assertThat(messenger).as("Should be an instance of Refreshable").isInstanceOf(Refreshable.class);
191183

192184
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
193185
assertThat(messenger2.getMessage()).isEqualTo("Hello World!");
@@ -207,9 +199,9 @@ void nonStaticPrototypeScript() {
207199

208200
@Test
209201
void scriptCompilationException() {
210-
assertThatExceptionOfType(NestedRuntimeException.class).isThrownBy(() ->
211-
new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml"))
212-
.matches(ex -> ex.contains(ScriptCompilationException.class));
202+
assertThatExceptionOfType(NestedRuntimeException.class)
203+
.isThrownBy(() -> new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml"))
204+
.matches(ex -> ex.contains(ScriptCompilationException.class));
213205
}
214206

215207
@Test
@@ -228,20 +220,17 @@ void scriptThatCompilesButIsJustPlainBad() throws IOException {
228220

229221
@Test
230222
void ctorWithNullScriptSourceLocator() {
231-
assertThatIllegalArgumentException().isThrownBy(() ->
232-
new BshScriptFactory(null, Messenger.class));
223+
assertThatIllegalArgumentException().isThrownBy(() -> new BshScriptFactory(null, Messenger.class));
233224
}
234225

235226
@Test
236227
void ctorWithEmptyScriptSourceLocator() {
237-
assertThatIllegalArgumentException().isThrownBy(() ->
238-
new BshScriptFactory("", Messenger.class));
228+
assertThatIllegalArgumentException().isThrownBy(() -> new BshScriptFactory("", Messenger.class));
239229
}
240230

241231
@Test
242232
void ctorWithWhitespacedScriptSourceLocator() {
243-
assertThatIllegalArgumentException().isThrownBy(() ->
244-
new BshScriptFactory("\n ", Messenger.class));
233+
assertThatIllegalArgumentException().isThrownBy(() -> new BshScriptFactory("\n ", Messenger.class));
245234
}
246235

247236
@Test
@@ -256,8 +245,7 @@ void resourceScriptFromTag() {
256245

257246
Messenger messenger = (Messenger) ctx.getBean("messenger");
258247
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
259-
boolean condition = messenger instanceof Refreshable;
260-
assertThat(condition).isFalse();
248+
assertThat(messenger).isNotInstanceOf(Refreshable.class);
261249

262250
Messenger messengerImpl = (Messenger) ctx.getBean("messengerImpl");
263251
assertThat(messengerImpl.getMessage()).isEqualTo("Hello World!");
@@ -306,8 +294,7 @@ void inlineScriptFromTag() {
306294
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
307295
Calculator calculator = (Calculator) ctx.getBean("calculator");
308296
assertThat(calculator).isNotNull();
309-
boolean condition = calculator instanceof Refreshable;
310-
assertThat(condition).isFalse();
297+
assertThat(calculator).isNotInstanceOf(Refreshable.class);
311298
ctx.close();
312299
}
313300

@@ -316,8 +303,7 @@ void refreshableFromTag() {
316303
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
317304
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
318305
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
319-
boolean condition = messenger instanceof Refreshable;
320-
assertThat(condition).as("Messenger should be Refreshable").isTrue();
306+
assertThat(messenger).as("Messenger should be Refreshable").isInstanceOf(Refreshable.class);
321307
ctx.close();
322308
}
323309

spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,14 @@ void testStaticScript() {
7878
assertThat(AopUtils.isAopProxy(calc)).as("Shouldn't get proxy when refresh is disabled").isFalse();
7979
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
8080

81-
boolean condition3 = calc instanceof Refreshable;
82-
assertThat(condition3).as("Scripted object should not be instance of Refreshable").isFalse();
83-
boolean condition2 = messenger instanceof Refreshable;
84-
assertThat(condition2).as("Scripted object should not be instance of Refreshable").isFalse();
81+
assertThat(calc instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
82+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
8583

8684
assertThat(calc).isEqualTo(calc);
8785
assertThat(messenger).isEqualTo(messenger);
88-
boolean condition1 = !messenger.equals(calc);
89-
assertThat(condition1).isTrue();
86+
assertThat(messenger).isNotEqualTo(calc);
9087
assertThat(messenger.hashCode()).isNotEqualTo(calc.hashCode());
91-
boolean condition = !messenger.toString().equals(calc.toString());
92-
assertThat(condition).isTrue();
88+
assertThat(messenger.toString()).isNotEqualTo(calc.toString());
9389

9490
String desiredMessage = "Hello World!";
9591
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -111,18 +107,14 @@ void testStaticScriptUsingJsr223() {
111107
assertThat(AopUtils.isAopProxy(calc)).as("Shouldn't get proxy when refresh is disabled").isFalse();
112108
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
113109

114-
boolean condition3 = calc instanceof Refreshable;
115-
assertThat(condition3).as("Scripted object should not be instance of Refreshable").isFalse();
116-
boolean condition2 = messenger instanceof Refreshable;
117-
assertThat(condition2).as("Scripted object should not be instance of Refreshable").isFalse();
110+
assertThat(calc instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
111+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
118112

119113
assertThat(calc).isEqualTo(calc);
120114
assertThat(messenger).isEqualTo(messenger);
121-
boolean condition1 = !messenger.equals(calc);
122-
assertThat(condition1).isTrue();
115+
assertThat(messenger).isNotEqualTo(calc);
123116
assertThat(messenger.hashCode()).isNotEqualTo(calc.hashCode());
124-
boolean condition = !messenger.toString().equals(calc.toString());
125-
assertThat(condition).isTrue();
117+
assertThat(messenger.toString()).isNotEqualTo(calc.toString());
126118

127119
String desiredMessage = "Hello World!";
128120
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -138,8 +130,7 @@ void testStaticPrototypeScript() {
138130
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
139131

140132
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
141-
boolean condition = messenger instanceof Refreshable;
142-
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
133+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
143134

144135
assertThat(messenger2).isNotSameAs(messenger);
145136
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@@ -158,8 +149,7 @@ void testStaticPrototypeScriptUsingJsr223() {
158149
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
159150

160151
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
161-
boolean condition = messenger instanceof Refreshable;
162-
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
152+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
163153

164154
assertThat(messenger2).isNotSameAs(messenger);
165155
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@@ -178,8 +168,7 @@ void testStaticScriptWithInstance() {
178168
Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
179169

180170
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
181-
boolean condition = messenger instanceof Refreshable;
182-
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
171+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
183172

184173
String desiredMessage = "Hello World!";
185174
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -193,8 +182,7 @@ void testStaticScriptWithInstanceUsingJsr223() {
193182
Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
194183

195184
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
196-
boolean condition = messenger instanceof Refreshable;
197-
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
185+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
198186

199187
String desiredMessage = "Hello World!";
200188
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -208,8 +196,7 @@ void testStaticScriptWithInlineDefinedInstance() {
208196
Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
209197

210198
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
211-
boolean condition = messenger instanceof Refreshable;
212-
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
199+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
213200

214201
String desiredMessage = "Hello World!";
215202
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -223,8 +210,7 @@ void testStaticScriptWithInlineDefinedInstanceUsingJsr223() {
223210
Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
224211

225212
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
226-
boolean condition = messenger instanceof Refreshable;
227-
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
213+
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
228214

229215
String desiredMessage = "Hello World!";
230216
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -237,8 +223,7 @@ void testNonStaticScript() {
237223
Messenger messenger = (Messenger) ctx.getBean("messenger");
238224

239225
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
240-
boolean condition = messenger instanceof Refreshable;
241-
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
226+
assertThat(messenger instanceof Refreshable).as("Should be an instance of Refreshable").isTrue();
242227

243228
String desiredMessage = "Hello World!";
244229
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@@ -257,8 +242,7 @@ void testNonStaticPrototypeScript() {
257242
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
258243

259244
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
260-
boolean condition = messenger instanceof Refreshable;
261-
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
245+
assertThat(messenger instanceof Refreshable).as("Should be an instance of Refreshable").isTrue();
262246

263247
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
264248
assertThat(messenger2.getMessage()).isEqualTo("Hello World!");
@@ -371,8 +355,7 @@ void testResourceScriptFromTag() {
371355
CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
372356

373357
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
374-
boolean condition = messenger instanceof Refreshable;
375-
assertThat(condition).isFalse();
358+
assertThat(messenger instanceof Refreshable).isFalse();
376359
assertThat(countingAspect.getCalls()).isEqualTo(0);
377360
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
378361
assertThat(countingAspect.getCalls()).isEqualTo(1);
@@ -404,8 +387,7 @@ void testInlineScriptFromTag() {
404387
assertThat(ObjectUtils.containsElement(bd.getDependsOn(), "messenger")).isTrue();
405388
Calculator calculator = (Calculator) ctx.getBean("calculator");
406389
assertThat(calculator).isNotNull();
407-
boolean condition = calculator instanceof Refreshable;
408-
assertThat(condition).isFalse();
390+
assertThat(calculator instanceof Refreshable).isFalse();
409391
}
410392

411393
@Test
@@ -417,8 +399,7 @@ void testRefreshableFromTag() {
417399
CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
418400

419401
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
420-
boolean condition = messenger instanceof Refreshable;
421-
assertThat(condition).isTrue();
402+
assertThat(messenger instanceof Refreshable).isTrue();
422403
assertThat(countingAspect.getCalls()).isEqualTo(0);
423404
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
424405
assertThat(countingAspect.getCalls()).isEqualTo(1);
@@ -435,8 +416,7 @@ public void testRefreshableFromTagProxyTargetClass() {
435416
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
436417

437418
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
438-
boolean condition = messenger instanceof Refreshable;
439-
assertThat(condition).isTrue();
419+
assertThat(messenger instanceof Refreshable).isTrue();
440420
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
441421

442422
assertThat(ctx.getBeansOfType(ConcreteMessenger.class)).containsValue((ConcreteMessenger) messenger);
@@ -487,8 +467,7 @@ void testRefreshableJsr223FromTag() {
487467
assertThat(Arrays.asList(ctx.getBeanNamesForType(Messenger.class))).contains("refreshableMessenger");
488468
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
489469
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
490-
boolean condition = messenger instanceof Refreshable;
491-
assertThat(condition).isTrue();
470+
assertThat(messenger instanceof Refreshable).isTrue();
492471
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
493472
}
494473

@@ -542,32 +521,26 @@ private void testMetaClass(String xmlFile) {
542521
// expect the exception we threw in the custom metaclass to show it got invoked
543522
ApplicationContext ctx = new ClassPathXmlApplicationContext(xmlFile);
544523
Calculator calc = (Calculator) ctx.getBean("delegatingCalculator");
545-
assertThatIllegalStateException().isThrownBy(() ->
546-
calc.add(1, 2))
547-
.withMessage("Gotcha");
524+
assertThatIllegalStateException()
525+
.isThrownBy(() -> calc.add(1, 2))
526+
.withMessage("Gotcha");
548527
}
549528

550529
@Test
551530
void testFactoryBean() {
552531
ApplicationContext context = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
553532
Object factory = context.getBean("&factory");
554-
boolean condition1 = factory instanceof FactoryBean;
555-
assertThat(condition1).isTrue();
533+
assertThat(factory instanceof FactoryBean).isTrue();
556534
Object result = context.getBean("factory");
557-
boolean condition = result instanceof String;
558-
assertThat(condition).isTrue();
559535
assertThat(result).isEqualTo("test");
560536
}
561537

562538
@Test
563539
void testRefreshableFactoryBean() {
564540
ApplicationContext context = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
565541
Object factory = context.getBean("&refreshableFactory");
566-
boolean condition1 = factory instanceof FactoryBean;
567-
assertThat(condition1).isTrue();
542+
assertThat(factory instanceof FactoryBean).isTrue();
568543
Object result = context.getBean("refreshableFactory");
569-
boolean condition = result instanceof String;
570-
assertThat(condition).isTrue();
571544
assertThat(result).isEqualTo("test");
572545
}
573546

0 commit comments

Comments
 (0)