Merge "Bug 849: Fixed NPE in Translated Data Change Events."
[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 org.junit.Ignore;
4 import org.junit.Test;
5 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
6
7 import java.io.IOException;
8
9 import static java.util.Arrays.asList;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 public class StringUtilTest {
14     @Test
15     public void testPrefixAndJoin() {
16         assertEquals(" extends p1.Foo,Bar", StringUtil.prefixAndJoin(asList(
17                 new FullyQualifiedName("p1", "Foo"), new FullyQualifiedName("", "Bar")), "extends"));
18     }
19
20     @Test
21     public void testAddAsterixAtEachLineStart() {
22         String input = "foo   \nbar";
23         String expectedOutput = "* foo\n* bar\n";
24         assertEquals(expectedOutput, StringUtil.addAsterixAtEachLineStart(input));
25     }
26
27     @Test
28     @Ignore
29     public void testCopyright() throws IOException {
30         assertTrue(StringUtil.loadCopyright().isPresent());
31     }
32
33     @Test
34     public void testFormatting() {
35         {
36         String input = "  \tpack;\n" +
37                 "class Bar{ \n" +
38                 " method() {\n" +
39                 "  body\n" +
40                 "}\n" +
41                 "  }";
42         String expected = "pack;\n" +
43                 "class Bar{\n" +
44                 "    method() {\n" +
45                 "        body\n" +
46                 "    }\n" +
47                 "}\n";
48         assertEquals(expected, StringUtil.formatJavaSource(input));
49         }
50         {
51             String input = "{\n" +
52                     "bar\n" +
53                     "}\n" +
54                     "\n\nbaz\n\n\n\n";
55             String expected = "{\n" +
56                     "    bar\n" +
57                     "}\n\n" +
58                     "baz\n";
59             assertEquals(expected, StringUtil.formatJavaSource(input));
60         }
61     }
62 }