use of org.springframework.scripting.ScriptSource in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testScriptedClassThatHasNoPublicNoArgCtor.
@Test
public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
ScriptSource script = mock(ScriptSource.class);
String badScript = "class Foo { protected Foo() {} \n String toString() { 'X' }}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript);
assertEquals("X", factory.getScriptedObject(script).toString());
}
use of org.springframework.scripting.ScriptSource in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn.
@Test
public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn() throws Exception {
ScriptSource script = mock(ScriptSource.class);
given(script.getScriptAsString()).willReturn("class Bar {}");
given(script.suggestedClassName()).willReturn("someName");
GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)");
Object scriptedObject = factory.getScriptedObject(script);
assertNotNull(scriptedObject);
}
use of org.springframework.scripting.ScriptSource in project spring-framework by spring-projects.
the class GroovyScriptFactoryTests method testScriptedClassThatDoesNotHaveANoArgCtor.
@Test
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
ScriptSource script = mock(ScriptSource.class);
String badScript = "class Foo { public Foo(String foo) {}}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript);
try {
factory.getScriptedObject(script);
fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class).");
} catch (ScriptCompilationException expected) {
assertTrue(expected.contains(NoSuchMethodException.class));
}
}
Aggregations