@Test void mapMakerTest() { JUnitGeneratorHelper helper = new JUnitGeneratorHelper(); String expected = "\n" + "private static java.util.HashMap<java.lang.String, java.lang.String> makeMap(\n" + " java.lang.String... strings) {\n" + " java.util.HashMap<java.lang.String, java.lang.String> result = new java.util.HashMap<>();\n" + " for(int i = 0; i < strings.length; i += 2) {\n" + " result.put(strings[i], strings[i + 1]);\n" + " }\n" + " return result;\n" + "}\n"; assertThat(helper.buildMapMaker().toString()).isEqualTo(expected); }
public MethodSpec buildMapMaker() { MethodSpec.Builder mapMaker = MethodSpec.methodBuilder(METHOD_MAP_MAKER) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(HashMap.class, String.class, String.class)) .addParameter(String[].class, "strings") .varargs() .addJavadoc("Generates a string map from a list of strings.\n"); mapMaker.addStatement("$T<$T, $T> result = new $T<>()", HashMap.class, String.class, String.class, HashMap.class) .beginControlFlow("for(int i = 0; i < strings.length; i += 2)") .addStatement("result.put(strings[i], strings[i + 1])") .endControlFlow() .addStatement("return result"); return mapMaker.build(); }
JUnitGeneratorHelper { public MethodSpec buildMapMaker() { MethodSpec.Builder mapMaker = MethodSpec.methodBuilder(METHOD_MAP_MAKER) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(HashMap.class, String.class, String.class)) .addParameter(String[].class, "strings") .varargs() .addJavadoc("Generates a string map from a list of strings.\n"); mapMaker.addStatement("$T<$T, $T> result = new $T<>()", HashMap.class, String.class, String.class, HashMap.class) .beginControlFlow("for(int i = 0; i < strings.length; i += 2)") .addStatement("result.put(strings[i], strings[i + 1])") .endControlFlow() .addStatement("return result"); return mapMaker.build(); } }
JUnitGeneratorHelper { public MethodSpec buildMapMaker() { MethodSpec.Builder mapMaker = MethodSpec.methodBuilder(METHOD_MAP_MAKER) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(HashMap.class, String.class, String.class)) .addParameter(String[].class, "strings") .varargs() .addJavadoc("Generates a string map from a list of strings.\n"); mapMaker.addStatement("$T<$T, $T> result = new $T<>()", HashMap.class, String.class, String.class, HashMap.class) .beginControlFlow("for(int i = 0; i < strings.length; i += 2)") .addStatement("result.put(strings[i], strings[i + 1])") .endControlFlow() .addStatement("return result"); return mapMaker.build(); }  }
JUnitGeneratorHelper { public MethodSpec buildMapMaker() { MethodSpec.Builder mapMaker = MethodSpec.methodBuilder(METHOD_MAP_MAKER) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(HashMap.class, String.class, String.class)) .addParameter(String[].class, "strings") .varargs() .addJavadoc("Generates a string map from a list of strings.\n"); mapMaker.addStatement("$T<$T, $T> result = new $T<>()", HashMap.class, String.class, String.class, HashMap.class) .beginControlFlow("for(int i = 0; i < strings.length; i += 2)") .addStatement("result.put(strings[i], strings[i + 1])") .endControlFlow() .addStatement("return result"); return mapMaker.build(); }  MethodSpec buildRunSqlImplementation(); MethodSpec buildRunSqlEmpty(); MethodSpec buildMapMaker(); MethodSpec buildGetResultColumns(); }
JUnitGeneratorHelper { public MethodSpec buildMapMaker() { MethodSpec.Builder mapMaker = MethodSpec.methodBuilder(METHOD_MAP_MAKER) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(HashMap.class, String.class, String.class)) .addParameter(String[].class, "strings") .varargs() .addJavadoc("Generates a string map from a list of strings.\n"); mapMaker.addStatement("$T<$T, $T> result = new $T<>()", HashMap.class, String.class, String.class, HashMap.class) .beginControlFlow("for(int i = 0; i < strings.length; i += 2)") .addStatement("result.put(strings[i], strings[i + 1])") .endControlFlow() .addStatement("return result"); return mapMaker.build(); }  MethodSpec buildRunSqlImplementation(); MethodSpec buildRunSqlEmpty(); MethodSpec buildMapMaker(); MethodSpec buildGetResultColumns(); static final String METHOD_RUN_SQL; static final ParameterizedTypeName RETURN_TYPE_RUN_SQL; static final String METHOD_MAP_MAKER; static final String METHOD_GET_RESULT_COLUMNS; }