@Test public void shouldReturnCriteriaBuilder() throws Exception { BelongsToType fieldType = mock(BelongsToType.class); InternalDataDefinition dataDefinition = mock(InternalDataDefinition.class, RETURNS_DEEP_STUBS); given(fieldType.getDataDefinition()).willReturn(dataDefinition); FieldDefinition fieldDefinition = mock(FieldDefinition.class); given(fieldDefinition.getType()).willReturn(fieldType); given(fieldDefinition.getName()).willReturn("field"); given(dataDefinition.getField("hasMany")).willReturn(fieldDefinition); SearchCriteriaBuilder searchCriteriaBuilder = mock(SearchCriteriaBuilder.class); given( dataDefinition.find().createAlias(fieldDefinition.getName(), fieldDefinition.getName()) .add(SearchRestrictions.eq(fieldDefinition.getName() + ".id", 1L))).willReturn(searchCriteriaBuilder); EntityList list = new EntityListImpl(dataDefinition, "hasMany", 1L); assertEquals(searchCriteriaBuilder, list.find()); }
@Override public SearchCriteriaBuilder find() { return dataDefinition.find().createAlias(joinFieldDefinition.getName(), joinFieldDefinition.getName()) .add(SearchRestrictions.eq(joinFieldDefinition.getName() + ".id", parentId)); }
EntityListImpl extends AbstractList<Entity> implements EntityList { @Override public SearchCriteriaBuilder find() { return dataDefinition.find().createAlias(joinFieldDefinition.getName(), joinFieldDefinition.getName()) .add(SearchRestrictions.eq(joinFieldDefinition.getName() + ".id", parentId)); } }
EntityListImpl extends AbstractList<Entity> implements EntityList { @Override public SearchCriteriaBuilder find() { return dataDefinition.find().createAlias(joinFieldDefinition.getName(), joinFieldDefinition.getName()) .add(SearchRestrictions.eq(joinFieldDefinition.getName() + ".id", parentId)); } EntityListImpl(final DataDefinition dataDefinition, final String joinFieldName, final Long parentId); }
EntityListImpl extends AbstractList<Entity> implements EntityList { @Override public SearchCriteriaBuilder find() { return dataDefinition.find().createAlias(joinFieldDefinition.getName(), joinFieldDefinition.getName()) .add(SearchRestrictions.eq(joinFieldDefinition.getName() + ".id", parentId)); } EntityListImpl(final DataDefinition dataDefinition, final String joinFieldName, final Long parentId); @Override SearchCriteriaBuilder find(); @Override Entity get(final int index); @Override int size(); @Override boolean isEmpty(); @Override String toString(); }
EntityListImpl extends AbstractList<Entity> implements EntityList { @Override public SearchCriteriaBuilder find() { return dataDefinition.find().createAlias(joinFieldDefinition.getName(), joinFieldDefinition.getName()) .add(SearchRestrictions.eq(joinFieldDefinition.getName() + ".id", parentId)); } EntityListImpl(final DataDefinition dataDefinition, final String joinFieldName, final Long parentId); @Override SearchCriteriaBuilder find(); @Override Entity get(final int index); @Override int size(); @Override boolean isEmpty(); @Override String toString();  }