Boil some plates, whatever that means

This commit is contained in:
Charlie Groves
2010-12-13 20:58:42 +00:00
parent 5455490fcf
commit d34ee233f7
2 changed files with 36 additions and 4 deletions
@@ -202,6 +202,13 @@ public class ProjectionTest extends TestBase
selectInto(IdName.class, TestRecord.RECORD_ID, TestRecord.NAME).toString());
}
@Test public void testSelectBuilder ()
{
assertEquals("[0 Elvis, 1 Elvis]",
_repo.from(TestRecord.class).where(TestRecord.RECORD_ID.lessThan(2)).
select(IDNAME_BUILDER, TestRecord.RECORD_ID, TestRecord.NAME).toString());
}
protected static class IdName {
public final int id;
public final String name;
@@ -214,6 +221,13 @@ public class ProjectionTest extends TestBase
}
}
protected static Builder2<IdName, Integer, String> IDNAME_BUILDER =
new Builder2<IdName, Integer, String>() {
public IdName build (Integer a, String b) {
return new IdName(a, b);
}
};
// the HSQL in-memory database persists for the lifetime of the VM, which means we have to
// clean up after ourselves in every test; thus we go ahead and share a repository
protected TestRepository _repo = createTestRepository();
@@ -20,16 +20,20 @@
package com.samskivert.depot;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Sets;
import com.samskivert.util.RandomUtil;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
import com.google.common.collect.Sets;
import com.samskivert.depot.annotation.Computed;
import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.util.Builder2;
import com.samskivert.util.RandomUtil;
/**
* Tests queries.
@@ -53,6 +57,7 @@ public class QueryTest extends TestBase
TestRecord record = createTestRecord(ii);
record.name = "Spam! " + ii;
record.age = RandomUtil.getInt(100);
record.awesomeness = RandomUtil.getFloat(1.0F);
record.homeTown = "Over there";
_repo.insert(record);
}
@@ -77,6 +82,19 @@ public class QueryTest extends TestBase
assertEquals("Spam! " + tnr.recordId, tnr.name);
}
Builder2<Float, Integer, Float> ageAwesome = new Builder2<Float, Integer, Float>() {
public Float build (Integer a, Float b) {
return a * b;
}
};
List<Float> results =
_repo.from(TestRecord.class).select(ageAwesome, TestRecord.AGE, TestRecord.AWESOMENESS);
assertEquals(CREATE_RECORDS, results.size());
for (float result : results) {
assertTrue("Age goes from [0,99) and awesomeness goes from [0.0,1.0), so their " +
"product should be [0.0,100), not " + result, result >= 0 && result < 100);
}
assertEquals(CREATE_RECORDS, _repo.findAll(TestRecord.class).size());
_repo.from(TestRecord.class).where(TestRecord.RECORD_ID.lessEq(CREATE_RECORDS/2)).delete();
assertEquals(CREATE_RECORDS/2, _repo.findAll(TestRecord.class).size());