@Test public void testTransform() throws Exception { Method method = visitor.getClass().getDeclaredMethod("transform", ClassType.class, ModelIndex.class); method.setAccessible(true); ClassType classType = Mockito.mock(ClassType.class); ModelIndex modelIndex = Mockito.mock(ModelIndex.class); AssociationEnd lhs = Mockito.mock(AssociationEnd.class); AssociationEnd rhs = Mockito.mock(AssociationEnd.class); Multiplicity multiplicity = Mockito.mock(Multiplicity.class); TagDefinition tagDefinition = Mockito.mock(TagDefinition.class); Range range = Mockito.mock(Range.class); List<AssociationEnd> ends = new ArrayList<AssociationEnd>(); ends.add(lhs); ends.add(rhs); Mockito.when(modelIndex.getAssociationEnds(Matchers.any(Identifier.class))).thenReturn(ends); Mockito.when(modelIndex.getTagDefinition(Matchers.any(Identifier.class))).thenReturn(tagDefinition); Mockito.when(lhs.getMultiplicity()).thenReturn(multiplicity); Mockito.when(rhs.getMultiplicity()).thenReturn(multiplicity); TaggedValue taggedValue = Mockito.mock(TaggedValue.class); List<TaggedValue> taggedValueList = new ArrayList<TaggedValue>(); taggedValueList.add(taggedValue); Mockito.when(lhs.getTaggedValues()).thenReturn(taggedValueList); Mockito.when(rhs.getTaggedValues()).thenReturn(taggedValueList); Mockito.when(multiplicity.getRange()).thenReturn(range); Mockito.when(range.getLower()).thenReturn(Occurs.ONE); Mockito.when(range.getUpper()).thenReturn(Occurs.ONE); Mockito.when(tagDefinition.getName()).thenReturn(SliUmlConstants.TAGDEF_NATURAL_KEY); Mockito.when(taggedValue.getValue()).thenReturn("true"); Mockito.when(lhs.getName()).thenReturn("lhsTest"); Mockito.when(rhs.getName()).thenReturn("rhsTest"); Mockito.when(lhs.getType()).thenReturn(Identifier.random()); Mockito.when(rhs.getType()).thenReturn(Identifier.random()); Mockito.when(lhs.getAssociatedAttributeName()).thenReturn("attribute"); Mockito.when(rhs.getAssociatedAttributeName()).thenReturn("attribute"); Mockito.when(classType.getName()).thenReturn("Association"); Mockito.when(classType.getId()).thenReturn(Identifier.random()); method.invoke(visitor, classType, modelIndex); }
private static final ClassType transform(final ClassType classType, final ModelIndex model) { if (classType == null) { throw new IllegalArgumentException(); } final List<AssociationEnd> ends = model.getAssociationEnds(classType.getId()); final List<AssociationEnd> singletonEnds = new ArrayList<AssociationEnd>(2); for (final AssociationEnd end : ends) { if (isExactlyOne(end, model)) { singletonEnds.add(end); } } if (singletonEnds.size() == 2) { if (classType.getName().endsWith("Association")) { final AssociationEnd lhsAssociationEnd = singletonEnds.get(0); final AssociationEnd rhsAssociationEnd = singletonEnds.get(1); final AssociationEnd lhsEnd = compute(lhsAssociationEnd); final AssociationEnd rhsEnd = compute(rhsAssociationEnd); return new ClassType(classType.getId(), classType.getName(), classType.isAbstract(), classType.getAttributes(), lhsEnd, rhsEnd, classType.getTaggedValues()); } else { return classType; } } else { return classType; } }
Xsd2UmlTweakerVisitor implements Visitor { private static final ClassType transform(final ClassType classType, final ModelIndex model) { if (classType == null) { throw new IllegalArgumentException(); } final List<AssociationEnd> ends = model.getAssociationEnds(classType.getId()); final List<AssociationEnd> singletonEnds = new ArrayList<AssociationEnd>(2); for (final AssociationEnd end : ends) { if (isExactlyOne(end, model)) { singletonEnds.add(end); } } if (singletonEnds.size() == 2) { if (classType.getName().endsWith("Association")) { final AssociationEnd lhsAssociationEnd = singletonEnds.get(0); final AssociationEnd rhsAssociationEnd = singletonEnds.get(1); final AssociationEnd lhsEnd = compute(lhsAssociationEnd); final AssociationEnd rhsEnd = compute(rhsAssociationEnd); return new ClassType(classType.getId(), classType.getName(), classType.isAbstract(), classType.getAttributes(), lhsEnd, rhsEnd, classType.getTaggedValues()); } else { return classType; } } else { return classType; } } }
Xsd2UmlTweakerVisitor implements Visitor { private static final ClassType transform(final ClassType classType, final ModelIndex model) { if (classType == null) { throw new IllegalArgumentException(); } final List<AssociationEnd> ends = model.getAssociationEnds(classType.getId()); final List<AssociationEnd> singletonEnds = new ArrayList<AssociationEnd>(2); for (final AssociationEnd end : ends) { if (isExactlyOne(end, model)) { singletonEnds.add(end); } } if (singletonEnds.size() == 2) { if (classType.getName().endsWith("Association")) { final AssociationEnd lhsAssociationEnd = singletonEnds.get(0); final AssociationEnd rhsAssociationEnd = singletonEnds.get(1); final AssociationEnd lhsEnd = compute(lhsAssociationEnd); final AssociationEnd rhsEnd = compute(rhsAssociationEnd); return new ClassType(classType.getId(), classType.getName(), classType.isAbstract(), classType.getAttributes(), lhsEnd, rhsEnd, classType.getTaggedValues()); } else { return classType; } } else { return classType; } } Xsd2UmlTweakerVisitor(final ModelIndex model); }
Xsd2UmlTweakerVisitor implements Visitor { private static final ClassType transform(final ClassType classType, final ModelIndex model) { if (classType == null) { throw new IllegalArgumentException(); } final List<AssociationEnd> ends = model.getAssociationEnds(classType.getId()); final List<AssociationEnd> singletonEnds = new ArrayList<AssociationEnd>(2); for (final AssociationEnd end : ends) { if (isExactlyOne(end, model)) { singletonEnds.add(end); } } if (singletonEnds.size() == 2) { if (classType.getName().endsWith("Association")) { final AssociationEnd lhsAssociationEnd = singletonEnds.get(0); final AssociationEnd rhsAssociationEnd = singletonEnds.get(1); final AssociationEnd lhsEnd = compute(lhsAssociationEnd); final AssociationEnd rhsEnd = compute(rhsAssociationEnd); return new ClassType(classType.getId(), classType.getName(), classType.isAbstract(), classType.getAttributes(), lhsEnd, rhsEnd, classType.getTaggedValues()); } else { return classType; } } else { return classType; } } Xsd2UmlTweakerVisitor(final ModelIndex model); @Override void beginPackage(final UmlPackage pkg); @Override void endPackage(final UmlPackage pkg); final List<NamespaceOwnedElement> getOwnedElements(); @Override void visit(final AssociationEnd associationEnd); @Override void visit(final Attribute attribute); @Override void visit(final ClassType classType); @Override void visit(final DataType dataType); @Override void visit(final EnumLiteral enumLiteral); @Override void visit(final EnumType enumType); @Override void visit(final Generalization generalization); @Override void visit(final Model model); @Override void visit(final Multiplicity multiplicity); @Override void visit(final Range range); @Override void visit(final TagDefinition tagDefinition); @Override void visit(final TaggedValue taggedValue); }
Xsd2UmlTweakerVisitor implements Visitor { private static final ClassType transform(final ClassType classType, final ModelIndex model) { if (classType == null) { throw new IllegalArgumentException(); } final List<AssociationEnd> ends = model.getAssociationEnds(classType.getId()); final List<AssociationEnd> singletonEnds = new ArrayList<AssociationEnd>(2); for (final AssociationEnd end : ends) { if (isExactlyOne(end, model)) { singletonEnds.add(end); } } if (singletonEnds.size() == 2) { if (classType.getName().endsWith("Association")) { final AssociationEnd lhsAssociationEnd = singletonEnds.get(0); final AssociationEnd rhsAssociationEnd = singletonEnds.get(1); final AssociationEnd lhsEnd = compute(lhsAssociationEnd); final AssociationEnd rhsEnd = compute(rhsAssociationEnd); return new ClassType(classType.getId(), classType.getName(), classType.isAbstract(), classType.getAttributes(), lhsEnd, rhsEnd, classType.getTaggedValues()); } else { return classType; } } else { return classType; } } Xsd2UmlTweakerVisitor(final ModelIndex model); @Override void beginPackage(final UmlPackage pkg); @Override void endPackage(final UmlPackage pkg); final List<NamespaceOwnedElement> getOwnedElements(); @Override void visit(final AssociationEnd associationEnd); @Override void visit(final Attribute attribute); @Override void visit(final ClassType classType); @Override void visit(final DataType dataType); @Override void visit(final EnumLiteral enumLiteral); @Override void visit(final EnumType enumType); @Override void visit(final Generalization generalization); @Override void visit(final Model model); @Override void visit(final Multiplicity multiplicity); @Override void visit(final Range range); @Override void visit(final TagDefinition tagDefinition); @Override void visit(final TaggedValue taggedValue);  }