CardinalityPrettyPrinter implements CardinalityVisitor { public String prettyprint(ASTCardinalityNode node) { getPrinter().clearBuffer(); node.accept(getRealThis()); return getPrinter().getContent(); } CardinalityPrettyPrinter(IndentPrinter printer); @Override void handle(ASTCardinality node); IndentPrinter getPrinter(); String prettyprint(ASTCardinalityNode node); @Override void setRealThis(CardinalityVisitor realThis); @Override CardinalityVisitor getRealThis();  }
@Test public void testCardinality1() throws IOException { TestCardinalityParser parser = new TestCardinalityParser(); Optional<ASTCardinality> result = parser.parseCardinality(new StringReader("[*]")); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTCardinality cardinality = result.get(); CardinalityPrettyPrinter prettyPrinter = new CardinalityPrettyPrinter(new IndentPrinter()); String output = prettyPrinter.prettyprint(cardinality); result = parser.parseCardinality(new StringReader(output)); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(cardinality.deepEquals(result.get())); }
@Test public void testCardinality2() throws IOException { TestCardinalityParser parser = new TestCardinalityParser(); Optional<ASTCardinality> result = parser.parseCardinality(new StringReader("[5..9]")); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTCardinality cardinality = result.get(); CardinalityPrettyPrinter prettyPrinter = new CardinalityPrettyPrinter(new IndentPrinter()); String output = prettyPrinter.prettyprint(cardinality); result = parser.parseCardinality(new StringReader(output)); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(cardinality.deepEquals(result.get())); }
@Test public void testCardinality3() throws IOException { TestCardinalityParser parser = new TestCardinalityParser(); Optional<ASTCardinality> result = parser.parseCardinality(new StringReader("[6..*]")); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); ASTCardinality cardinality = result.get(); CardinalityPrettyPrinter prettyPrinter = new CardinalityPrettyPrinter(new IndentPrinter()); String output = prettyPrinter.prettyprint(cardinality); result = parser.parseCardinality(new StringReader(output)); assertFalse(parser.hasErrors()); assertTrue(result.isPresent()); assertTrue(cardinality.deepEquals(result.get())); }