/** * Set up environment. * * @throws Exception to JUnit */ public void setUp() throws Exception { UnitTestHelper.loadConfig(UnitTestHelper.CONFIG_FILE); this.freeTextGraphNode = new GraphNode(); SimpleSemanticModelElement ssme = new SimpleSemanticModelElement(); ssme.setTypeInfo("FreeText"); this.freeTextGraphNode.setSemanticModel(ssme); this.freeTextGraphNode.addContained(new TextElement()); this.diagram = new Diagram(); this.manager = new UMLModelManager(); this.manager.setProjectConfigurationManager(new ProjectConfigurationManager(this.manager)); this.action = new AddFreeTextAction(this.freeTextGraphNode, this.diagram, this.manager); }
/** * Test constructor <code>AddFreeTextAction(GraphNode freeTextGraphNode, GraphNode diagram, * UMLModelManager modelManager)</code> for failure with freeTextGraphNode has no TextElement, * <code>IllegalArgumentException</code> is expected. */ public void testCtor_FreeTextGraphNodeWithoutTextElement() { GraphNode node = new GraphNode(); SimpleSemanticModelElement ssme = new SimpleSemanticModelElement(); ssme.setTypeInfo("FreeText"); node.setSemanticModel(ssme); try { new AddFreeTextAction(node, this.diagram, this.manager); fail("IllegalArgumentException is expected!"); } catch (IllegalArgumentException e) { // expected } }
/** * Tests constructor CutFreeTextAction(freeTextGraphNode, clipboard) if freeTextGraphNode doesn't * contain a TextElement object in its contained attribute. IllegalArgumentException is expected. */ public void testCtorIfFreeTextNotContainedTextElementObject() { try { SimpleSemanticModelElement semanticModelBridge = new SimpleSemanticModelElement(); semanticModelBridge.setTypeInfo("FreeText"); freeTextGraphNode.setSemanticModel(semanticModelBridge); new CutFreeTextAction(freeTextGraphNode, null); fail( "IllegalArgumentException is expected because freeTextGraphNode must contain a TextElement " + "object in its contained attribute."); } catch (IllegalArgumentException e) { // success } }
/** * Tests method copyToClipboard(node, clipboard) if node is null. IllegalArgumentException is * expected * * @throws Exception exception */ public void testCopyToClipboardIfNodeNull() throws Exception { SimpleSemanticModelElement semanticModelBridge = new SimpleSemanticModelElement(); semanticModelBridge.setTypeInfo("FreeText"); freeTextGraphNode.setSemanticModel(semanticModelBridge); freeTextGraphNode.addContained(new TextElement()); CutFreeTextActionExt cutFreeTextAction = new CutFreeTextActionExt(freeTextGraphNode, null); try { cutFreeTextAction.copyToClipboard(null, null); fail("IllegalArgumentException is expected because node cannot be null."); } catch (IllegalArgumentException e) { // success } }
/** * Tests constructor CutFreeTextAction(freeTextGraphNode, clipboard) if freeTextGraphNode contains * a semanticModel attribute (SimpleSemanticModelElement object), but its typeInfo attribute is * not equal to "FreeText". IllegalArgumentException is expected. */ public void testCtorITypeInfoInvalid() { try { freeTextGraphNode.addContained(new TextElement()); SimpleSemanticModelElement semanticModelBridge = new SimpleSemanticModelElement(); semanticModelBridge.setTypeInfo("invalid_type_info"); freeTextGraphNode.setSemanticModel(semanticModelBridge); new CutFreeTextAction(freeTextGraphNode, null); fail( "IllegalArgumentException is expected because semanticModel's typeInfo is not equal " + "to 'FreeText'."); } catch (IllegalArgumentException e) { // success } }