Skip to content

Commit

Permalink
Add tests for the new constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Shredder121 committed Aug 12, 2016
1 parent 8fe6e30 commit b27625e
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
*/
package com.querydsl.sql.codegen;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand All @@ -26,6 +32,7 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.google.common.io.Files;
import com.mysema.codegen.SimpleCompiler;
import com.querydsl.codegen.BeanSerializer;
import com.querydsl.sql.AbstractJDBCTest;
Expand Down Expand Up @@ -93,6 +100,20 @@ public void normal_serialization() throws SQLException {
exporter.export(connection.getMetaData());

compile(exporter);

// validation of output
try {
//
assertMethodsPresent("test/QSurvey.java",
// variable + schema constructor
" public QSurvey(String variable, String schema) {\n"
+ " super(Survey.class, forVariable(variable), schema, \"SURVEY\");\n"
+ " addMetadata();\n"
+ " }"
);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

@Test
Expand Down Expand Up @@ -127,6 +148,20 @@ public void setValue(PreparedStatement st, int startIndex, CustomNumber value) t
exporter.export(connection.getMetaData());

compile(exporter);

// validation of output
try {
//
assertMethodsPresent("test/QSurvey.java",
// variable + schema constructor
" public QSurvey(String variable, String schema) {\n"
+ " super(Survey.class, forVariable(variable), schema, \"SURVEY\");\n"
+ " addMetadata();\n"
+ " }"
);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

private void compile(MetaDataExporter exporter) {
Expand All @@ -140,4 +175,8 @@ private void compile(MetaDataExporter exporter) {
}
}

private void assertMethodsPresent(String path, String... methods) throws IOException {
String content = Files.toString(folder.getRoot().toPath().resolve(path).toFile(), UTF_8);
assertThat(content, stringContainsInOrder(asList(methods)));
}
}

0 comments on commit b27625e

Please sign in to comment.