use of groovy.lang.Binding in project groovity by disney.
the class TestTraits method testSwallow.
@Test
public void testSwallow() throws Exception {
String message = "{\"maxAltitude\":3500,\"wingSpan\":2.0,\"spineLength\":2.5,\"numFeathers\":2965,\"numLegs\":2}";
Binding binding = new Binding();
String result = run("/testSwallow", binding).replaceAll("\\s+", "");
Assert.assertEquals(message, result);
}
use of groovy.lang.Binding in project groovity by disney.
the class ScriptHelper method stream.
public void stream(final Object o) {
if (o == null) {
return;
}
try {
if (o instanceof Callable) {
@SuppressWarnings("rawtypes") final Object r = ((Callable) o).call();
if (r != null && r != o) {
stream(r);
}
return;
}
final Binding binding = THREAD_BINDING.get();
if (binding == null) {
return;
}
final Writer writer = (Writer) binding.getVariable(OUT);
if (writer == null) {
return;
}
if (o instanceof Writable) {
((Writable) o).writeTo(writer);
} else if (o instanceof CharSequence) {
writer.append((CharSequence) o);
} else if (o.getClass().isArray()) {
@SuppressWarnings("rawtypes") Class ct = o.getClass().getComponentType();
if (ct.isPrimitive()) {
if (ct.equals(Integer.TYPE)) {
writer.append(Arrays.toString((int[]) o));
}
if (ct.equals(Long.TYPE)) {
writer.append(Arrays.toString((long[]) o));
}
if (ct.equals(Float.TYPE)) {
writer.append(Arrays.toString((float[]) o));
}
if (o.getClass().equals(Double.TYPE)) {
writer.append(Arrays.toString((double[]) o));
}
} else {
writer.append(Arrays.deepToString((Object[]) o));
}
} else {
writer.append(o.toString());
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of groovy.lang.Binding in project groovity by disney.
the class TestCoreGroovity method testImplicitReturn.
@Test
public void testImplicitReturn() throws Exception {
Binding binding = new Binding();
Object result = groovity.run("/implicit", binding);
Assert.assertEquals(Date.class, result.getClass());
}
use of groovy.lang.Binding in project groovity by disney.
the class TestCoreGroovity method testDependent.
@Test
public void testDependent() throws Exception {
Binding binding = new Binding();
String result = run("/dependent", binding).trim();
Assert.assertEquals("[antivirus, firewall]", result);
}
use of groovy.lang.Binding in project groovity by disney.
the class TestCoreGroovity method testMissing.
@Test
public void testMissing() throws Exception {
Exception e = null;
try {
Binding binding = new Binding();
run("/notfound", binding);
} catch (Exception x) {
e = x;
}
Assert.assertNotNull("Expected ClassNotFoundException", e);
Assert.assertEquals("Expected ClassNotFoundException", ClassNotFoundException.class, e.getClass());
}
Aggregations