@Test void getResultColumnsTest() { JUnitGeneratorHelper helper = new JUnitGeneratorHelper(); String expected = "\n" + "private static java.util.List<java.lang.String> getResultColumns(java.sql.ResultSet result) throws\n" + " java.sql.SQLException {\n" + " java.sql.ResultSetMetaData meta = result.getMetaData();\n" + " java.util.List<java.lang.String> columns = new java.util.ArrayList<>();\n" + " " for (int i = 1; i <= meta.getColumnCount(); ++i) {\n" + " columns.add(meta.getColumnLabel(i));\n" + " }\n" + " return columns;\n" + "}\n"; assertThat(helper.buildGetResultColumns().toString()).isEqualTo(expected); }
public MethodSpec buildGetResultColumns() { MethodSpec.Builder getResultColumns = MethodSpec.methodBuilder(METHOD_GET_RESULT_COLUMNS) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(List.class, String.class)) .addParameter(ResultSet.class, "result") .addException(SQLException.class) .addJavadoc("Gets the columns of a statement result set.\n"); getResultColumns.addStatement("$T meta = result.getMetaData()", ResultSetMetaData.class) .addStatement("$T<$T> columns = new $T<>()", List.class, String.class, ArrayList.class) .addComment("Start at one; this is 1-indexed") .beginControlFlow("for (int i = 1; i <= meta.getColumnCount(); ++i)") .addStatement("columns.add(meta.getColumnLabel(i))") .endControlFlow() .addStatement("return columns"); return getResultColumns.build(); }
JUnitGeneratorHelper { public MethodSpec buildGetResultColumns() { MethodSpec.Builder getResultColumns = MethodSpec.methodBuilder(METHOD_GET_RESULT_COLUMNS) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(List.class, String.class)) .addParameter(ResultSet.class, "result") .addException(SQLException.class) .addJavadoc("Gets the columns of a statement result set.\n"); getResultColumns.addStatement("$T meta = result.getMetaData()", ResultSetMetaData.class) .addStatement("$T<$T> columns = new $T<>()", List.class, String.class, ArrayList.class) .addComment("Start at one; this is 1-indexed") .beginControlFlow("for (int i = 1; i <= meta.getColumnCount(); ++i)") .addStatement("columns.add(meta.getColumnLabel(i))") .endControlFlow() .addStatement("return columns"); return getResultColumns.build(); } }
JUnitGeneratorHelper { public MethodSpec buildGetResultColumns() { MethodSpec.Builder getResultColumns = MethodSpec.methodBuilder(METHOD_GET_RESULT_COLUMNS) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(List.class, String.class)) .addParameter(ResultSet.class, "result") .addException(SQLException.class) .addJavadoc("Gets the columns of a statement result set.\n"); getResultColumns.addStatement("$T meta = result.getMetaData()", ResultSetMetaData.class) .addStatement("$T<$T> columns = new $T<>()", List.class, String.class, ArrayList.class) .addComment("Start at one; this is 1-indexed") .beginControlFlow("for (int i = 1; i <= meta.getColumnCount(); ++i)") .addStatement("columns.add(meta.getColumnLabel(i))") .endControlFlow() .addStatement("return columns"); return getResultColumns.build(); }  }
JUnitGeneratorHelper { public MethodSpec buildGetResultColumns() { MethodSpec.Builder getResultColumns = MethodSpec.methodBuilder(METHOD_GET_RESULT_COLUMNS) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(List.class, String.class)) .addParameter(ResultSet.class, "result") .addException(SQLException.class) .addJavadoc("Gets the columns of a statement result set.\n"); getResultColumns.addStatement("$T meta = result.getMetaData()", ResultSetMetaData.class) .addStatement("$T<$T> columns = new $T<>()", List.class, String.class, ArrayList.class) .addComment("Start at one; this is 1-indexed") .beginControlFlow("for (int i = 1; i <= meta.getColumnCount(); ++i)") .addStatement("columns.add(meta.getColumnLabel(i))") .endControlFlow() .addStatement("return columns"); return getResultColumns.build(); }  MethodSpec buildRunSqlImplementation(); MethodSpec buildRunSqlEmpty(); MethodSpec buildMapMaker(); MethodSpec buildGetResultColumns(); }
JUnitGeneratorHelper { public MethodSpec buildGetResultColumns() { MethodSpec.Builder getResultColumns = MethodSpec.methodBuilder(METHOD_GET_RESULT_COLUMNS) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .returns(ParameterizedTypeName.get(List.class, String.class)) .addParameter(ResultSet.class, "result") .addException(SQLException.class) .addJavadoc("Gets the columns of a statement result set.\n"); getResultColumns.addStatement("$T meta = result.getMetaData()", ResultSetMetaData.class) .addStatement("$T<$T> columns = new $T<>()", List.class, String.class, ArrayList.class) .addComment("Start at one; this is 1-indexed") .beginControlFlow("for (int i = 1; i <= meta.getColumnCount(); ++i)") .addStatement("columns.add(meta.getColumnLabel(i))") .endControlFlow() .addStatement("return columns"); return getResultColumns.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; }