@SuppressWarnings("ConstantConditions") @Test void testTransformRefEntity() { EntityType entityType = mock(EntityType.class); Attribute refAttr1 = mock(Attribute.class, RETURNS_DEEP_STUBS); Attribute refAttr2 = mock(Attribute.class, RETURNS_DEEP_STUBS); Attribute normalAttr = mock(Attribute.class); when(refAttr1.getIdentifier()).thenReturn("refAttr1"); when(refAttr1.getDataType()).thenReturn(MREF); when(refAttr1.hasRefEntity()).thenReturn(true); when(refAttr1.getRefEntity().getId()).thenReturn("ref1"); when(refAttr2.getIdentifier()).thenReturn("refAttr2"); when(refAttr2.getDataType()).thenReturn(XREF); when(refAttr2.hasRefEntity()).thenReturn(true); when(refAttr2.getRefEntity().getId()).thenReturn("ref2"); when(normalAttr.getIdentifier()).thenReturn("normalAttr"); when(normalAttr.getDataType()).thenReturn(STRING); EntityType newRef1 = mock(EntityType.class); EntityType newRef3 = mock(EntityType.class); when(entityType.getAtomicAttributes()).thenReturn(asList(refAttr1, refAttr2, normalAttr)); Map<String, EntityType> newEntityTypes = ImmutableMap.of("ref1", newRef1, "ref3", newRef3); RelationTransformer.transformRefEntities(entityType, newEntityTypes); verify(refAttr1).setRefEntity(newRef1); verify(refAttr2, never()).setRefEntity(any(EntityType.class)); verify(normalAttr, never()).setRefEntity(any(EntityType.class)); }
private static void transformRefEntity( Attribute attribute, Map<String, EntityType> newEntityTypes) { if (attribute.hasRefEntity()) { String refId = attribute.getRefEntity().getId(); if (newEntityTypes.containsKey(refId)) { attribute.setRefEntity(newEntityTypes.get(refId)); } } }
RelationTransformer { private static void transformRefEntity( Attribute attribute, Map<String, EntityType> newEntityTypes) { if (attribute.hasRefEntity()) { String refId = attribute.getRefEntity().getId(); if (newEntityTypes.containsKey(refId)) { attribute.setRefEntity(newEntityTypes.get(refId)); } } } }
RelationTransformer { private static void transformRefEntity( Attribute attribute, Map<String, EntityType> newEntityTypes) { if (attribute.hasRefEntity()) { String refId = attribute.getRefEntity().getId(); if (newEntityTypes.containsKey(refId)) { attribute.setRefEntity(newEntityTypes.get(refId)); } } } private  RelationTransformer(); }
RelationTransformer { private static void transformRefEntity( Attribute attribute, Map<String, EntityType> newEntityTypes) { if (attribute.hasRefEntity()) { String refId = attribute.getRefEntity().getId(); if (newEntityTypes.containsKey(refId)) { attribute.setRefEntity(newEntityTypes.get(refId)); } } } private  RelationTransformer();  }
RelationTransformer { private static void transformRefEntity( Attribute attribute, Map<String, EntityType> newEntityTypes) { if (attribute.hasRefEntity()) { String refId = attribute.getRefEntity().getId(); if (newEntityTypes.containsKey(refId)) { attribute.setRefEntity(newEntityTypes.get(refId)); } } } private  RelationTransformer();   }