forked from playframework/play1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request playframework#453 from hongrich/lighthouse-1423-patch
[playframework#1423] Fix initializing an inner class inside groovy templates
- Loading branch information
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
samples-and-tests/just-test-cases/test/TemplateClassBindingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
|
||
import play.templates.GroovyTemplate; | ||
import play.templates.GroovyTemplateCompiler; | ||
import play.test.UnitTest; | ||
|
||
public class TemplateClassBindingTest extends UnitTest { | ||
|
||
public static class StaticInnerClass { | ||
public final int val; | ||
public StaticInnerClass() { | ||
val = 42; | ||
} | ||
} | ||
|
||
@Test | ||
public void testDynamicClassBindingWithNew() { | ||
final String source = "${ new TemplateClassBindingTest.StaticInnerClass().val }"; | ||
GroovyTemplate groovyTemplate = new GroovyTemplate("dynamic_class_binding_with_new", source); | ||
new GroovyTemplateCompiler().compile(groovyTemplate); | ||
assertEquals("42", groovyTemplate.render()); | ||
} | ||
|
||
@Test | ||
public void testDynamicClassBindingWithInstanceOf() { | ||
StaticInnerClass staticInnerClass = new StaticInnerClass(); | ||
final String source = "${ staticInnerClass instanceof TemplateClassBindingTest.StaticInnerClass }"; | ||
GroovyTemplate groovyTemplate = new GroovyTemplate("dynamic_class_binding_with_instanceof", source); | ||
new GroovyTemplateCompiler().compile(groovyTemplate); | ||
Map<String, Object> args = new HashMap<String,Object>(); | ||
args.put("staticInnerClass", staticInnerClass); | ||
assertEquals("true", groovyTemplate.render(args)); | ||
} | ||
|
||
@Test | ||
public void testDynamicClassBindingWithDotClass() { | ||
StaticInnerClass staticInnerClass = new StaticInnerClass(); | ||
final String source = "${ staticInnerClass.getClass() == TemplateClassBindingTest.StaticInnerClass.class }"; | ||
GroovyTemplate groovyTemplate = new GroovyTemplate("dynamic_class_binding_with_dot_class", source); | ||
new GroovyTemplateCompiler().compile(groovyTemplate); | ||
Map<String, Object> args = new HashMap<String,Object>(); | ||
args.put("staticInnerClass", staticInnerClass); | ||
assertEquals("true", groovyTemplate.render(args)); | ||
} | ||
|
||
} |