No effective change - test assert to contains rather than containsExactly

This commit is contained in:
rob bygrave
2018-12-21 14:29:50 +13:00
parent 72263c0af0
commit 60c8683914
2 changed files with 46 additions and 43 deletions
@@ -28,7 +28,7 @@ public class TestOrphanRemoveO2MFlat extends BaseTestCase {
m1 = Ebean.find(OrpMaster2.class, "m2");
// Expect only one.
assertThat(m1.getDetails()).hasSize(1);
assertThat(m1.getDetails()).extracting("id").containsExactly("d23");
assertThat(m1.getDetails()).extracting("id").contains("d23");
m1.getDetails().clear();
m1.getDetails().add(new OrpDetail2("d24", "d4", "m2"));
@@ -37,7 +37,7 @@ public class TestOrphanRemoveO2MFlat extends BaseTestCase {
m1 = Ebean.find(OrpMaster2.class, "m2");
assertThat(m1.getDetails()).hasSize(2);
assertThat(m1.getDetails()).extracting("id").containsExactly("d24", "d25");
assertThat(m1.getDetails()).extracting("id").contains("d24", "d25");
m1 = Ebean.find(OrpMaster2.class)
@@ -47,7 +47,7 @@ public class TestOrphanRemoveO2MFlat extends BaseTestCase {
// Expect only one.
assertThat(m1.getDetails()).hasSize(2);
assertThat(m1.getDetails()).extracting("id").containsExactly("d24", "d25");
assertThat(m1.getDetails()).extracting("id").contains("d24", "d25");
}
+43 -40
View File
@@ -3,6 +3,8 @@ package org.tests.query.cache;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.ExpressionList;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import org.junit.Test;
import java.util.List;
@@ -11,49 +13,50 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
public class TestDistinct extends BaseTestCase {
/**
* The call of {@link #positionsQuery} {@link ExpressionList#findList()} causes the following use of {@link #costsQuery(UUID...)} to not
* use distinct and return the wrong number of results.
*/
@Test
public void testMissingUnique() {
Acl acl = new Acl();
Ebean.save(acl);
Acl acl2 = new Acl();
Ebean.save(acl2);
Contract contract = new Contract();
AclContainerRelation rel1 = new AclContainerRelation();
rel1.setAclEntry(acl);
rel1.setContainer(contract);
AclContainerRelation rel2 = new AclContainerRelation();
rel2.setAclEntry(acl2);
rel2.setContainer(contract);
contract.getAclEntries().add(rel1);
contract.getAclEntries().add(rel2);
Position pos = new Position();
pos.setContract(contract);
contract.getPositions().add(pos);
Ebean.save(contract);
ContractCosts cost = new ContractCosts();
cost.setPosition(pos);
Ebean.save(cost);
/**
* The call of {@link #positionsQuery} {@link ExpressionList#findList()} causes the following use of {@link #costsQuery(UUID...)} to not
* use distinct and return the wrong number of results.
*/
@ForPlatform(Platform.H2)
@Test
public void testMissingUnique() {
Acl acl = new Acl();
Ebean.save(acl);
Acl acl2 = new Acl();
Ebean.save(acl2);
Contract contract = new Contract();
AclContainerRelation rel1 = new AclContainerRelation();
rel1.setAclEntry(acl);
rel1.setContainer(contract);
AclContainerRelation rel2 = new AclContainerRelation();
rel2.setAclEntry(acl2);
rel2.setContainer(contract);
contract.getAclEntries().add(rel1);
contract.getAclEntries().add(rel2);
Position pos = new Position();
pos.setContract(contract);
contract.getPositions().add(pos);
Ebean.save(contract);
ContractCosts cost = new ContractCosts();
cost.setPosition(pos);
Ebean.save(cost);
//costsQuery(acl.getId(), acl2.getId()).findCount();
//costsQuery(acl.getId(), acl2.getId()).findCount();
// the between causes the error
List<Position> positions = positionsQuery(acl.getId()).findList();
// the between causes the error
// the between causes the error
List<Position> positions = positionsQuery(acl.getId()).findList();
// the between causes the error
System.out.println("The error, query without distinct:");
List<ContractCosts> costs = costsQuery(acl.getId(), acl2.getId()).findList();
assertThat(costs).hasSize(1);
}
System.out.println("The error, query without distinct:");
List<ContractCosts> costs = costsQuery(acl.getId(), acl2.getId()).findList();
assertThat(costs).hasSize(1);
}
public ExpressionList<Position> positionsQuery(final Long aclId) {
return Ebean.find(Position.class).where().eq("contract.aclEntries.aclEntry.id", aclId);
}
public ExpressionList<Position> positionsQuery(final Long aclId) {
return Ebean.find(Position.class).where().eq("contract.aclEntries.aclEntry.id", aclId);
}
public ExpressionList<ContractCosts> costsQuery(final Long... aclId) {
return Ebean.find(ContractCosts.class).where().in("position.contract.aclEntries.aclEntry.id", aclId);
}
public ExpressionList<ContractCosts> costsQuery(final Long... aclId) {
return Ebean.find(ContractCosts.class).where().in("position.contract.aclEntries.aclEntry.id", aclId);
}
}