@BeforeMethod public void setUpBeforeMethod() { entityAttributesValidator = new EntityAttributesValidator(); AttributeMetaData idAttr = when(mock(AttributeMetaData.class).getName()).thenReturn("id").getMock(); when(idAttr.getDataType()).thenReturn(STRING); AttributeMetaData intRangeMinAttr = when(mock(AttributeMetaData.class).getName()).thenReturn("intrangemin").getMock(); when(intRangeMinAttr.getDataType()).thenReturn(INT); when(intRangeMinAttr.getRange()).thenReturn(new Range(1l, null)); AttributeMetaData intRangeMaxAttr = when(mock(AttributeMetaData.class).getName()).thenReturn("intrangemin").getMock(); when(intRangeMaxAttr.getDataType()).thenReturn(INT); when(intRangeMaxAttr.getRange()).thenReturn(new Range(null, 1l)); intRangeMinMeta = when(mock(EntityMetaData.class).getName()).thenReturn("entity").getMock(); when(intRangeMinMeta.getIdAttribute()).thenReturn(idAttr); when(intRangeMinMeta.getAttribute("id")).thenReturn(idAttr); when(intRangeMinMeta.getAttribute("intrangemin")).thenReturn(intRangeMinAttr); when(intRangeMinMeta.getAtomicAttributes()).thenReturn(asList(idAttr, intRangeMinAttr)); intRangeMaxMeta = when(mock(EntityMetaData.class).getName()).thenReturn("entity").getMock(); when(intRangeMaxMeta.getIdAttribute()).thenReturn(idAttr); when(intRangeMaxMeta.getAttribute("id")).thenReturn(idAttr); when(intRangeMaxMeta.getAttribute("intrangemin")).thenReturn(intRangeMaxAttr); when(intRangeMaxMeta.getAtomicAttributes()).thenReturn(asList(idAttr, intRangeMaxAttr)); }
private static AttributeMetaData getAttribute(EntityMetaData entityMeta, String attrName) { AttributeMetaData attr = entityMeta.getAttribute(attrName); if (attr == null) { throw new UnknownAttributeException( format("Unknown attribute [%s] of entity [%s]", attrName, entityMeta.getName())); } return attr; }