Permalink
Browse files

- Added an isEmpty method

- Added test
  • Loading branch information...
1 parent 07bb766 commit fee8b5d8e4a9749501467d47e95148f7875f5d81 @mpermar mpermar committed Aug 6, 2011
@@ -384,6 +384,12 @@ class TropoBuilder extends BuilderSupport {
stack.push root.tropo
}
+ def isEmpty() {
+
+ def node = root?.get("tropo")
+ node == null || node.size() == 0
+ }
+
private Object cleanGStrings(Object value) {
if (value instanceof GString) {
@@ -721,4 +721,21 @@ class TropoBuilderTests extends GroovyTestCase {
}
assert builder2.text() == "{\"tropo\":[{\"ask\":{\"name\":\"foo\",\"bargein\":true,\"timeout\":30,\"required\":true,\"say\":[{\"value\":\"Please say your account number\"}],\"choices\":{\"value\":\"[5 DIGITS]\"}}},{\"on\":{\"event\":\"success\",\"next\":\"/result.json\"}}]}"
}
+
+ public void testIsEmpty() {
+
+ def builder = new TropoBuilder()
+ assertTrue builder.isEmpty()
+
+ builder.tropo {}
+ assertTrue builder.isEmpty()
+
+ builder.tropo {
+ say('hello')
+ }
+ assertFalse builder.isEmpty()
+
+ builder.reset()
+ assertTrue builder.isEmpty()
+ }
}

0 comments on commit fee8b5d

Please sign in to comment.