@@ -0,0 +1,1488 @@
+package org.minimalj.util;%0D%0A%0D%0Aimport java.util.List;%0D%0A%0D%0Aimport org.junit.Assert;%0D%0Aimport org.junit.BeforeClass;%0D%0Aimport org.junit.Test;%0D%0Aimport org.minimalj.model.Code;%0D%0Aimport org.minimalj.model.annotation.Size;%0D%0Aimport org.minimalj.persistence.criteria.By;%0D%0Aimport org.minimalj.persistence.sql.SqlPersistence;%0D%0A%0D%0Apublic class CodesTest %7B%0D%0A%0D%0A%09private static SqlPersistence persistence;%0D%0A%09%0D%0A%09@BeforeClass%0D%0A%09public static void setupPersistence() %7B%0D%0A%09%09persistence = new SqlPersistence(SqlPersistence.embeddedDataSource(), TestCode.class);%0D%0A%09%7D%0D%0A%09%0D%0A%09@Test%0D%0A%09public void testDeclaratedCodes() %7B%0D%0A%09%09List%3CTestCode%3E codes = persistence.read(TestCode.class, By.all(), 3);%0D%0A%09%09Assert.assertEquals(%22public static final codes should be automatically inserted in the persistence%22, 2, codes.size());%0D%0A%09%7D%0D%0A%0D%0A%09@Test%0D%0A%09public void testDeclaratedCode() %7B%0D%0A%09%09TestCode code = persistence.read(TestCode.class, TestCode.A.id);%0D%0A%09%09Assert.assertEquals(TestCode.A.text, code.text);%0D%0A%09%7D%0D%0A%09%0D%0A%09public static class TestCode implements Code %7B%0D%0A%09%09@Size(2)%0D%0A%09%09public String id;%0D%0A%09%09@Size(255)%0D%0A%09%09public String text;%0D%0A%09%09%0D%0A%09%09public static final TestCode A = new TestCode(%2242%22, %22Text42%22);%0D%0A%09%09public static final TestCode B = new TestCode(%2243%22, %22Text43%22);%0D%0A%0D%0A%09%09// not final declarations must not generate an entry in database%0D%0A%09%09public static TestCode NOT_FINAL = new TestCode(%2244%22, %22Text44%22);%0D%0A%0D%0A%09%09public TestCode() %7B%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09public TestCode(String id, String text) %7B%0D%0A%09%09%09this.id = id;%0D%0A%09%09%09this.text = text;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%7D%0D%0A

Test programatically declarated codes