提交 4c5b1c44 authored 作者: Thomas Mueller's avatar Thomas Mueller

Cleanup:

- Add class level Javadoc documentation (I hope it's somewhat correct)
- Make fields private if possible
- Enable the trace option when running in standalone mode
- Instead of System.out.println(), use trace()
- Remove 'verbose' flag, use the trace flag instead
- Remove @Override so it can be compiled with JDK 5 (so that the nightly build works)
- Use { .. } even for single line blocks - this is the code convention used in H2 (so that insertion of a new line of code anywhere is always "safe")
上级 e38a0a80
...@@ -17,13 +17,16 @@ import org.h2.jaqu.Validation; ...@@ -17,13 +17,16 @@ import org.h2.jaqu.Validation;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.test.jaqu.SupportedTypes.SupportedTypes2; import org.h2.test.jaqu.SupportedTypes.SupportedTypes2;
/**
* Test that the mapping between classes and tables is done correctly.
*/
public class ModelsTest extends TestBase { public class ModelsTest extends TestBase {
/** /**
* This object represents a database (actually a connection to the database). * This object represents a database (actually a connection to the database).
*/ */
//## Java 1.5 begin ## //## Java 1.5 begin ##
Db db; private Db db;
//## Java 1.5 end ## //## Java 1.5 end ##
/** /**
...@@ -32,8 +35,11 @@ public class ModelsTest extends TestBase { ...@@ -32,8 +35,11 @@ public class ModelsTest extends TestBase {
* *
* @param args the command line parameters * @param args the command line parameters
*/ */
public static void main(String... args) { public static void main(String... args) throws Exception {
new ModelsTest().test(); ModelsTest test = new ModelsTest();
test.init();
test.config.traceTest = true;
test.test();
} }
public void test() { public void test() {
...@@ -52,25 +58,25 @@ public class ModelsTest extends TestBase { ...@@ -52,25 +58,25 @@ public class ModelsTest extends TestBase {
} }
private void testValidateModels() { private void testValidateModels() {
boolean verbose = false;
DbInspector inspector = new DbInspector(db); DbInspector inspector = new DbInspector(db);
validateModel(inspector, new Product(), verbose); validateModel(inspector, new Product());
validateModel(inspector, new ProductAnnotationOnly(), verbose); validateModel(inspector, new ProductAnnotationOnly());
validateModel(inspector, new ProductMixedAnnotation(), verbose); validateModel(inspector, new ProductMixedAnnotation());
} }
private void validateModel(DbInspector inspector, Object o, boolean verbose) { private void validateModel(DbInspector inspector, Object o) {
List<Validation> remarks = inspector.validateModel(o, false); List<Validation> remarks = inspector.validateModel(o, false);
if (verbose && remarks.size() > 0) { if (config.traceTest && remarks.size() > 0) {
System.out.println("Validation Remarks for " + o.getClass().getName()); trace("Validation remarks for " + o.getClass().getName());
System.out.println("============================================="); for (Validation remark : remarks) {
for (Validation remark:remarks) trace(remark.toString());
System.out.println(remark); }
System.out.println(); trace("");
} }
for (Validation remark:remarks) for (Validation remark : remarks) {
assertFalse(remark.toString(), remark.isError()); assertFalse(remark.toString(), remark.isError());
} }
}
private void testSupportedTypes() { private void testSupportedTypes() {
List<SupportedTypes> original = SupportedTypes.createList(); List<SupportedTypes> original = SupportedTypes.createList();
...@@ -130,27 +136,29 @@ public class ModelsTest extends TestBase { ...@@ -130,27 +136,29 @@ public class ModelsTest extends TestBase {
db.close(); db.close();
} }
@JQDatabase(version=2) /**
private class TestDbUpgrader implements DbUpgrader { * A sample database upgrader class.
*/
@JQDatabase(version = 2)
class TestDbUpgrader implements DbUpgrader {
final AtomicInteger oldVersion = new AtomicInteger(0); final AtomicInteger oldVersion = new AtomicInteger(0);
final AtomicInteger newVersion = new AtomicInteger(0); final AtomicInteger newVersion = new AtomicInteger(0);
@Override
public boolean upgradeTable(Db db, String schema, String table, public boolean upgradeTable(Db db, String schema, String table,
int fromVersion, int toVersion) { int fromVersion, int toVersion) {
// Sample DbUpgrader just claims success on upgrade request // just claims success on upgrade request
oldVersion.set(fromVersion); oldVersion.set(fromVersion);
newVersion.set(toVersion); newVersion.set(toVersion);
return true; return true;
} }
@Override
public boolean upgradeDatabase(Db db, int fromVersion, int toVersion) { public boolean upgradeDatabase(Db db, int fromVersion, int toVersion) {
// Sample DbUpgrader just claims success on upgrade request // just claims success on upgrade request
oldVersion.set(fromVersion); oldVersion.set(fromVersion);
newVersion.set(toVersion); newVersion.set(toVersion);
return true; return true;
} }
};
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论