View Javadoc
1   package net.sourceforge.jenesis4java.util;
2   
3   /*
4    * #%L
5    * Jenesis 4 Java Code Generator
6    * %%
7    * Copyright (C) 2000 - 2016 jenesis4java
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * #L%
23   */
24  
25  import net.sourceforge.jenesis4java.CodeWriter;
26  import net.sourceforge.jenesis4java.Declaration;
27  import net.sourceforge.jenesis4java.DocumentationComment;
28  import net.sourceforge.jenesis4java.impl.MCodeWriter;
29  import org.junit.Test;
30  
31  import java.io.PrintWriter;
32  import java.io.StringWriter;
33  
34  import static net.sourceforge.jenesis4java.util.TestHelper.LS;
35  import static org.junit.Assert.assertNotNull;
36  import static org.junit.Assert.assertSame;
37  
38  public abstract class DeclarationBaseTest {
39  
40      public abstract Declaration getInstance();
41  
42      @Test
43      public void testToCodeReturnsGivenCodeWriter() {
44          Declaration declaration = getInstance();
45  
46          CodeWriter cout = new MCodeWriter(new PrintWriter(new StringWriter()));
47          assertSame(cout, declaration.toCode(cout));
48      }
49  
50      @Test
51      public void javadoc() {
52          Declaration instance = getInstance();
53          String withoutComment = instance.toString();
54          DocumentationComment comment = instance.javadoc("comment");
55          assertNotNull(comment);
56  
57          String expected = "/**" + LS + " * comment" + LS + " */" + LS + withoutComment;
58          CodeGenerationAssertions.assertEqualsIgnoreLineBreaks(expected, instance.toString());
59      }
60  
61  }