Merge "Reuse PEM provider in netconf-testtool."
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / test / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / util / StringUtilTest.java
1 package org.opendaylight.controller.config.yangjmxgenerator.plugin.util;
2
3 import static java.util.Arrays.asList;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertTrue;
6
7 import java.io.IOException;
8 import org.junit.Ignore;
9 import org.junit.Test;
10 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
11
12 public class StringUtilTest {
13     @Test
14     public void testPrefixAndJoin() {
15         assertEquals(" extends p1.Foo,Bar", StringUtil.prefixAndJoin(asList(
16                 new FullyQualifiedName("p1", "Foo"), new FullyQualifiedName("", "Bar")), "extends"));
17     }
18
19     @Test
20     public void testAddAsterixAtEachLineStart() {
21         String input = "foo   \nbar";
22         String expectedOutput = "* foo\n* bar\n";
23         assertEquals(expectedOutput, StringUtil.addAsterixAtEachLineStart(input));
24     }
25
26     @Test
27     @Ignore
28     public void testCopyright() throws IOException {
29         assertTrue(StringUtil.loadCopyright().isPresent());
30     }
31
32     @Test
33     public void testFormatting() {
34         {
35             String input = "  \tpack;\n" +
36                 "class Bar{ \n" +
37                 " method() {\n" +
38                 "  body\n" +
39                 "}\n" +
40                 "  }";
41             String expected = "pack;\n" +
42                 "class Bar{\n" +
43                 "    method() {\n" +
44                 "        body\n" +
45                 "    }\n" +
46                 "}\n";
47             assertEquals(expected, StringUtil.formatJavaSource(input));
48         }
49         {
50             String input = "{\n" +
51                     "bar\n" +
52                     "}\n" +
53                     "\n\nbaz\n\n\n\n";
54             String expected = "{\n" +
55                     "    bar\n" +
56                     "}\n\n" +
57                     "baz\n";
58             assertEquals(expected, StringUtil.formatJavaSource(input));
59         }
60     }
61 }