### Question:
JavaCode extends Code { public Collection<String> methods() { return collectPatterns(METHOD_NAME_PATTERN, 4); } JavaCode(); String typeName(); boolean isClass(); Collection<String> typeAnnotations(); Collection<String> imports(); Collection<String> methods(); Collection<String> methodAnnotations(String method); String methodReturns(String method); String methodArguments(String method); String packageName(); String fullyQualifiedName(); String methodBody(String method); Collection<String> fieldNames(); String fieldType(String fieldName); Iterable<String> fieldAnnotations(String fieldName); String fieldValue(String fieldName); Iterable<String> fileComments(); String superTypeName(); Iterable<String> implementedInterfaces(); boolean isType(String type); boolean fieldIsContant(String fieldName); Iterable<String> fieldComments(String fieldName); String constructorBody(); void ensureImport(String packageName, String typeName); String simpleTypeName(); static final String TYPE_PATTERN; static final String NAME_PATTERN; }### Answer:
@Test public void extractsEmptyMethods() { code.add("public class %s {", randomJavaId()); code.add("}"); TestUtil.assertCollectionEquals("Methods", Collections.<String>emptyList(), code.methods()); }
@Test public void extractsMethods() { String method1 = 'z' + someValue(); String method2 = 'm' + someValue(); String method3 = 'a' + someValue(); String method4 = 'b' + someValue(); code.add("public class %s {", randomJavaId()); code.add(" public void %s() {", method1); code.add(" }"); code.add(" public int %s(int arg) {", method2); code.add(" return 42;"); code.add(" }"); code.add(" public String %s(@RequestBody String arg) {", method3); code.add(" return \"foo\";"); code.add(" }"); code.add(" public void %s", method4); code.add(" () {"); code.add(" }"); code.add("}"); TestUtil.assertCollectionEquals("Methods", Arrays.asList(method3, method4, method2, method1), code.methods()); }