@SuppressWarnings({"ConstantConditions", "unchecked"}) @Test void testTransformMappedBy() { 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.isMappedBy()).thenReturn(true); when(refAttr1.getMappedBy().getIdentifier()).thenReturn("mappedByAttr1"); when(refAttr1.getDataType()).thenReturn(ONE_TO_MANY); when(refAttr2.isMappedBy()).thenReturn(true); when(refAttr2.getMappedBy().getIdentifier()).thenReturn("mappedByAttr2"); when(refAttr2.getDataType()).thenReturn(ONE_TO_MANY); when(normalAttr.getIdentifier()).thenReturn("normalAttr"); when(normalAttr.getDataType()).thenReturn(STRING); Attribute newMappedByAttr1 = mock(Attribute.class); Attribute newMappedByAttr3 = mock(Attribute.class); when(entityType.getAtomicAttributes()).thenReturn(asList(refAttr1, refAttr2, normalAttr)); Map<String, Attribute> newAttributes = ImmutableMap.of("mappedByAttr1", newMappedByAttr1, "mappedByAttr3", newMappedByAttr3); RelationTransformer.transformMappedBys(entityType, newAttributes); verify(refAttr1).setMappedBy(newMappedByAttr1); verify(refAttr2, never()).setMappedBy(any(Attribute.class)); verify(normalAttr, never()).setMappedBy(any(Attribute.class)); }
@SuppressWarnings("java:S2259") private static void transformMappedBy(Attribute attribute, Map<String, Attribute> newAttributes) { if (attribute.isMappedBy()) { @SuppressWarnings("ConstantConditions") String mappedByAttrId = attribute.getMappedBy().getIdentifier(); if (newAttributes.containsKey(mappedByAttrId)) { attribute.setMappedBy(newAttributes.get(mappedByAttrId)); } } }
RelationTransformer { @SuppressWarnings("java:S2259") private static void transformMappedBy(Attribute attribute, Map<String, Attribute> newAttributes) { if (attribute.isMappedBy()) { @SuppressWarnings("ConstantConditions") String mappedByAttrId = attribute.getMappedBy().getIdentifier(); if (newAttributes.containsKey(mappedByAttrId)) { attribute.setMappedBy(newAttributes.get(mappedByAttrId)); } } } }
RelationTransformer { @SuppressWarnings("java:S2259") private static void transformMappedBy(Attribute attribute, Map<String, Attribute> newAttributes) { if (attribute.isMappedBy()) { @SuppressWarnings("ConstantConditions") String mappedByAttrId = attribute.getMappedBy().getIdentifier(); if (newAttributes.containsKey(mappedByAttrId)) { attribute.setMappedBy(newAttributes.get(mappedByAttrId)); } } } private  RelationTransformer(); }
RelationTransformer { @SuppressWarnings("java:S2259") private static void transformMappedBy(Attribute attribute, Map<String, Attribute> newAttributes) { if (attribute.isMappedBy()) { @SuppressWarnings("ConstantConditions") String mappedByAttrId = attribute.getMappedBy().getIdentifier(); if (newAttributes.containsKey(mappedByAttrId)) { attribute.setMappedBy(newAttributes.get(mappedByAttrId)); } } } private  RelationTransformer();  }
RelationTransformer { @SuppressWarnings("java:S2259") private static void transformMappedBy(Attribute attribute, Map<String, Attribute> newAttributes) { if (attribute.isMappedBy()) { @SuppressWarnings("ConstantConditions") String mappedByAttrId = attribute.getMappedBy().getIdentifier(); if (newAttributes.containsKey(mappedByAttrId)) { attribute.setMappedBy(newAttributes.get(mappedByAttrId)); } } } private  RelationTransformer();   }