Browse Source

Polish integration tests

pull/36028/head
Sam Brannen 2 days ago
parent
commit
a4c72c8fcf
  1. 2
      spring-context/src/test/java/org/springframework/scheduling/support/PeriodicTriggerTests.java
  2. 42
      spring-context/src/test/java/org/springframework/scripting/bsh/BshScriptFactoryTests.java
  3. 77
      spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java

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

@ -184,7 +184,7 @@ class PeriodicTriggerTests { @@ -184,7 +184,7 @@ class PeriodicTriggerTests {
void equalsVerification() {
PeriodicTrigger trigger1 = new PeriodicTrigger(Duration.ofMillis(3000));
PeriodicTrigger trigger2 = new PeriodicTrigger(Duration.ofMillis(3000));
assertThat(trigger1.equals(new String("not a trigger"))).isFalse();
assertThat(trigger1).isNotEqualTo(new String("not a trigger"));
assertThat(trigger1).isNotEqualTo(null);
assertThat(trigger1).isEqualTo(trigger1);
assertThat(trigger2).isEqualTo(trigger2);

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

@ -61,18 +61,13 @@ class BshScriptFactoryTests { @@ -61,18 +61,13 @@ class BshScriptFactoryTests {
Calculator calc = (Calculator) ctx.getBean("calculator");
Messenger messenger = (Messenger) ctx.getBean("messenger");
boolean condition3 = calc instanceof Refreshable;
assertThat(condition3).as("Scripted object should not be instance of Refreshable").isFalse();
boolean condition2 = messenger instanceof Refreshable;
assertThat(condition2).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(calc).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(calc).isEqualTo(calc);
assertThat(messenger).isEqualTo(messenger);
boolean condition1 = !messenger.equals(calc);
assertThat(condition1).isTrue();
assertThat(messenger.hashCode()).isNotEqualTo(calc.hashCode());
boolean condition = !messenger.toString().equals(calc.toString());
assertThat(condition).isTrue();
assertThat(messenger.toString()).isNotEqualTo(calc.toString());
assertThat(calc.add(2, 3)).isEqualTo(5);
@ -145,8 +140,7 @@ class BshScriptFactoryTests { @@ -145,8 +140,7 @@ class BshScriptFactoryTests {
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger).as("Scripted object should not be instance of Refreshable").isNotInstanceOf(Refreshable.class);
assertThat(messenger2).isNotSameAs(messenger);
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@ -165,8 +159,7 @@ class BshScriptFactoryTests { @@ -165,8 +159,7 @@ class BshScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messenger");
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
assertThat(messenger).as("Should be an instance of Refreshable").isInstanceOf(Refreshable.class);
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -186,8 +179,7 @@ class BshScriptFactoryTests { @@ -186,8 +179,7 @@ class BshScriptFactoryTests {
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
assertThat(messenger).as("Should be an instance of Refreshable").isInstanceOf(Refreshable.class);
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
assertThat(messenger2.getMessage()).isEqualTo("Hello World!");
@ -207,8 +199,8 @@ class BshScriptFactoryTests { @@ -207,8 +199,8 @@ class BshScriptFactoryTests {
@Test
void scriptCompilationException() {
assertThatExceptionOfType(NestedRuntimeException.class).isThrownBy(() ->
new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml"))
assertThatExceptionOfType(NestedRuntimeException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml"))
.matches(ex -> ex.contains(ScriptCompilationException.class));
}
@ -228,20 +220,17 @@ class BshScriptFactoryTests { @@ -228,20 +220,17 @@ class BshScriptFactoryTests {
@Test
void ctorWithNullScriptSourceLocator() {
assertThatIllegalArgumentException().isThrownBy(() ->
new BshScriptFactory(null, Messenger.class));
assertThatIllegalArgumentException().isThrownBy(() -> new BshScriptFactory(null, Messenger.class));
}
@Test
void ctorWithEmptyScriptSourceLocator() {
assertThatIllegalArgumentException().isThrownBy(() ->
new BshScriptFactory("", Messenger.class));
assertThatIllegalArgumentException().isThrownBy(() -> new BshScriptFactory("", Messenger.class));
}
@Test
void ctorWithWhitespacedScriptSourceLocator() {
assertThatIllegalArgumentException().isThrownBy(() ->
new BshScriptFactory("\n ", Messenger.class));
assertThatIllegalArgumentException().isThrownBy(() -> new BshScriptFactory("\n ", Messenger.class));
}
@Test
@ -256,8 +245,7 @@ class BshScriptFactoryTests { @@ -256,8 +245,7 @@ class BshScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messenger");
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
boolean condition = messenger instanceof Refreshable;
assertThat(condition).isFalse();
assertThat(messenger).isNotInstanceOf(Refreshable.class);
Messenger messengerImpl = (Messenger) ctx.getBean("messengerImpl");
assertThat(messengerImpl.getMessage()).isEqualTo("Hello World!");
@ -306,8 +294,7 @@ class BshScriptFactoryTests { @@ -306,8 +294,7 @@ class BshScriptFactoryTests {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
Calculator calculator = (Calculator) ctx.getBean("calculator");
assertThat(calculator).isNotNull();
boolean condition = calculator instanceof Refreshable;
assertThat(condition).isFalse();
assertThat(calculator).isNotInstanceOf(Refreshable.class);
ctx.close();
}
@ -316,8 +303,7 @@ class BshScriptFactoryTests { @@ -316,8 +303,7 @@ class BshScriptFactoryTests {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Messenger should be Refreshable").isTrue();
assertThat(messenger).as("Messenger should be Refreshable").isInstanceOf(Refreshable.class);
ctx.close();
}

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

@ -78,18 +78,14 @@ public class GroovyScriptFactoryTests { @@ -78,18 +78,14 @@ public class GroovyScriptFactoryTests {
assertThat(AopUtils.isAopProxy(calc)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition3 = calc instanceof Refreshable;
assertThat(condition3).as("Scripted object should not be instance of Refreshable").isFalse();
boolean condition2 = messenger instanceof Refreshable;
assertThat(condition2).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(calc instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(calc).isEqualTo(calc);
assertThat(messenger).isEqualTo(messenger);
boolean condition1 = !messenger.equals(calc);
assertThat(condition1).isTrue();
assertThat(messenger).isNotEqualTo(calc);
assertThat(messenger.hashCode()).isNotEqualTo(calc.hashCode());
boolean condition = !messenger.toString().equals(calc.toString());
assertThat(condition).isTrue();
assertThat(messenger.toString()).isNotEqualTo(calc.toString());
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -111,18 +107,14 @@ public class GroovyScriptFactoryTests { @@ -111,18 +107,14 @@ public class GroovyScriptFactoryTests {
assertThat(AopUtils.isAopProxy(calc)).as("Shouldn't get proxy when refresh is disabled").isFalse();
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition3 = calc instanceof Refreshable;
assertThat(condition3).as("Scripted object should not be instance of Refreshable").isFalse();
boolean condition2 = messenger instanceof Refreshable;
assertThat(condition2).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(calc instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(calc).isEqualTo(calc);
assertThat(messenger).isEqualTo(messenger);
boolean condition1 = !messenger.equals(calc);
assertThat(condition1).isTrue();
assertThat(messenger).isNotEqualTo(calc);
assertThat(messenger.hashCode()).isNotEqualTo(calc.hashCode());
boolean condition = !messenger.toString().equals(calc.toString());
assertThat(condition).isTrue();
assertThat(messenger.toString()).isNotEqualTo(calc.toString());
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -138,8 +130,7 @@ public class GroovyScriptFactoryTests { @@ -138,8 +130,7 @@ public class GroovyScriptFactoryTests {
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger2).isNotSameAs(messenger);
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@ -158,8 +149,7 @@ public class GroovyScriptFactoryTests { @@ -158,8 +149,7 @@ public class GroovyScriptFactoryTests {
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger2).isNotSameAs(messenger);
assertThat(messenger2.getClass()).isSameAs(messenger.getClass());
@ -178,8 +168,7 @@ public class GroovyScriptFactoryTests { @@ -178,8 +168,7 @@ public class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -193,8 +182,7 @@ public class GroovyScriptFactoryTests { @@ -193,8 +182,7 @@ public class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -208,8 +196,7 @@ public class GroovyScriptFactoryTests { @@ -208,8 +196,7 @@ public class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -223,8 +210,7 @@ public class GroovyScriptFactoryTests { @@ -223,8 +210,7 @@ public class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
assertThat(AopUtils.isAopProxy(messenger)).as("Shouldn't get proxy when refresh is disabled").isFalse();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Scripted object should not be instance of Refreshable").isFalse();
assertThat(messenger instanceof Refreshable).as("Scripted object should not be instance of Refreshable").isFalse();
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -237,8 +223,7 @@ public class GroovyScriptFactoryTests { @@ -237,8 +223,7 @@ public class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("messenger");
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
assertThat(messenger instanceof Refreshable).as("Should be an instance of Refreshable").isTrue();
String desiredMessage = "Hello World!";
assertThat(messenger.getMessage()).as("Message is incorrect").isEqualTo(desiredMessage);
@ -257,8 +242,7 @@ public class GroovyScriptFactoryTests { @@ -257,8 +242,7 @@ public class GroovyScriptFactoryTests {
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
assertThat(AopUtils.isAopProxy(messenger)).as("Should be a proxy for refreshable scripts").isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).as("Should be an instance of Refreshable").isTrue();
assertThat(messenger instanceof Refreshable).as("Should be an instance of Refreshable").isTrue();
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
assertThat(messenger2.getMessage()).isEqualTo("Hello World!");
@ -371,8 +355,7 @@ public class GroovyScriptFactoryTests { @@ -371,8 +355,7 @@ public class GroovyScriptFactoryTests {
CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).isFalse();
assertThat(messenger instanceof Refreshable).isFalse();
assertThat(countingAspect.getCalls()).isEqualTo(0);
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
assertThat(countingAspect.getCalls()).isEqualTo(1);
@ -404,8 +387,7 @@ public class GroovyScriptFactoryTests { @@ -404,8 +387,7 @@ public class GroovyScriptFactoryTests {
assertThat(ObjectUtils.containsElement(bd.getDependsOn(), "messenger")).isTrue();
Calculator calculator = (Calculator) ctx.getBean("calculator");
assertThat(calculator).isNotNull();
boolean condition = calculator instanceof Refreshable;
assertThat(condition).isFalse();
assertThat(calculator instanceof Refreshable).isFalse();
}
@Test
@ -417,8 +399,7 @@ public class GroovyScriptFactoryTests { @@ -417,8 +399,7 @@ public class GroovyScriptFactoryTests {
CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).isTrue();
assertThat(messenger instanceof Refreshable).isTrue();
assertThat(countingAspect.getCalls()).isEqualTo(0);
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
assertThat(countingAspect.getCalls()).isEqualTo(1);
@ -435,8 +416,7 @@ public class GroovyScriptFactoryTests { @@ -435,8 +416,7 @@ public class GroovyScriptFactoryTests {
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).isTrue();
assertThat(messenger instanceof Refreshable).isTrue();
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
assertThat(ctx.getBeansOfType(ConcreteMessenger.class)).containsValue((ConcreteMessenger) messenger);
@ -487,8 +467,7 @@ public class GroovyScriptFactoryTests { @@ -487,8 +467,7 @@ public class GroovyScriptFactoryTests {
assertThat(Arrays.asList(ctx.getBeanNamesForType(Messenger.class))).contains("refreshableMessenger");
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
assertThat(AopUtils.isAopProxy(messenger)).isTrue();
boolean condition = messenger instanceof Refreshable;
assertThat(condition).isTrue();
assertThat(messenger instanceof Refreshable).isTrue();
assertThat(messenger.getMessage()).isEqualTo("Hello World!");
}
@ -542,8 +521,8 @@ public class GroovyScriptFactoryTests { @@ -542,8 +521,8 @@ public class GroovyScriptFactoryTests {
// expect the exception we threw in the custom metaclass to show it got invoked
ApplicationContext ctx = new ClassPathXmlApplicationContext(xmlFile);
Calculator calc = (Calculator) ctx.getBean("delegatingCalculator");
assertThatIllegalStateException().isThrownBy(() ->
calc.add(1, 2))
assertThatIllegalStateException()
.isThrownBy(() -> calc.add(1, 2))
.withMessage("Gotcha");
}
@ -551,11 +530,8 @@ public class GroovyScriptFactoryTests { @@ -551,11 +530,8 @@ public class GroovyScriptFactoryTests {
void testFactoryBean() {
ApplicationContext context = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
Object factory = context.getBean("&factory");
boolean condition1 = factory instanceof FactoryBean;
assertThat(condition1).isTrue();
assertThat(factory instanceof FactoryBean).isTrue();
Object result = context.getBean("factory");
boolean condition = result instanceof String;
assertThat(condition).isTrue();
assertThat(result).isEqualTo("test");
}
@ -563,11 +539,8 @@ public class GroovyScriptFactoryTests { @@ -563,11 +539,8 @@ public class GroovyScriptFactoryTests {
void testRefreshableFactoryBean() {
ApplicationContext context = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
Object factory = context.getBean("&refreshableFactory");
boolean condition1 = factory instanceof FactoryBean;
assertThat(condition1).isTrue();
assertThat(factory instanceof FactoryBean).isTrue();
Object result = context.getBean("refreshableFactory");
boolean condition = result instanceof String;
assertThat(condition).isTrue();
assertThat(result).isEqualTo("test");
}

Loading…
Cancel
Save