use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.
the class FieldAccessorTest method testGet.
@Test
public void testGet() {
FieldAccessor accessor = new FieldAccessor(TstBean.class, "string", String.class);
TstBean object = new TstBean();
object.setString("abc");
assertEquals("abc", accessor.getValue(object));
}
use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.
the class ASTObjPathTest method testEvaluate_JavaBean.
@Test
public void testEvaluate_JavaBean() {
ASTObjPath node = new ASTObjPath("property2");
TstBean b1 = new TstBean();
b1.setProperty2(1);
assertEquals(1, node.evaluate(b1));
TstBean b2 = new TstBean();
b2.setProperty2(-3);
assertEquals(-3, node.evaluate(b2));
}
use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.
the class OrderingTest method testCompare4.
@Test
public void testCompare4() {
// compare on non-persistent property
TstBean t1 = new TstBean(1000);
TstBean t2 = new TstBean(2000);
TstBean t3 = new TstBean(2000);
Ordering ordering = new Ordering("integer", SortOrder.ASCENDING);
assertTrue(ordering.compare(t1, t2) < 0);
assertTrue(ordering.compare(t2, t1) > 0);
assertTrue(ordering.compare(t2, t3) == 0);
}
use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.
the class OrderingTest method testOrderListWithFunction_Static.
@Test
public void testOrderListWithFunction_Static() {
Collection<TstBean> set = new HashSet<>(6);
TstBean shouldBe0 = new TstBean("cx", -2);
TstBean shouldBe1 = new TstBean("cf", -1);
TstBean shouldBe2 = new TstBean("basa", 2);
TstBean shouldBe3 = new TstBean("abcd", -1);
TstBean shouldBe4 = new TstBean("bdsasd", -2);
TstBean shouldBe5 = new TstBean("bdsadf", 1);
set.add(shouldBe4);
set.add(shouldBe2);
set.add(shouldBe1);
set.add(shouldBe5);
set.add(shouldBe0);
set.add(shouldBe3);
List<Ordering> orderings = asList(new Ordering(FunctionExpressionFactory.lengthExp("string"), SortOrder.ASCENDING), new Ordering(FunctionExpressionFactory.absExp("integer"), SortOrder.DESCENDING));
List<TstBean> orderedList = Ordering.orderedList(set, orderings);
assertEquals(shouldBe0, orderedList.get(0));
assertEquals(shouldBe1, orderedList.get(1));
assertEquals(shouldBe2, orderedList.get(2));
assertEquals(shouldBe3, orderedList.get(3));
assertEquals(shouldBe4, orderedList.get(4));
assertEquals(shouldBe5, orderedList.get(5));
}
use of org.apache.cayenne.unit.util.TstBean in project cayenne by apache.
the class OrderingTest method testOrderList_Static.
@Test
public void testOrderList_Static() {
List<TstBean> list = new ArrayList<>(6);
list.add(new TstBean("c", 1));
list.add(new TstBean("c", 30));
list.add(new TstBean("a", 5));
list.add(new TstBean("b", 1));
list.add(new TstBean("b", 2));
list.add(new TstBean("b", 5));
List<Ordering> orderings = asList(new Ordering("string", SortOrder.ASCENDING), new Ordering("integer", SortOrder.DESCENDING));
// clone list and then order
List<TstBean> orderedList = new ArrayList<>(list);
Ordering.orderList(orderedList, orderings);
assertEquals(list.get(2), orderedList.get(0));
assertEquals(list.get(5), orderedList.get(1));
assertEquals(list.get(4), orderedList.get(2));
assertEquals(list.get(3), orderedList.get(3));
assertEquals(list.get(1), orderedList.get(4));
assertEquals(list.get(0), orderedList.get(5));
}
Aggregations