Merge "Bug 509: Fixed incorrect merging of Data Store Writes / 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.Test;
4 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
5
6 import java.io.IOException;
7
8 import static java.util.Arrays.asList;
9 import static org.junit.Assert.assertEquals;
10 import static org.junit.Assert.assertTrue;
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     public void testCopyright() throws IOException {
28         assertTrue(StringUtil.loadCopyright().isPresent());
29     }
30
31     @Test
32     public void testFormatting() {
33         {
34         String input = "  \tpack;\n" +
35                 "class Bar{ \n" +
36                 " method() {\n" +
37                 "  body\n" +
38                 "}\n" +
39                 "  }";
40         String expected = "pack;\n" +
41                 "class Bar{\n" +
42                 "    method() {\n" +
43                 "        body\n" +
44                 "    }\n" +
45                 "}\n";
46         assertEquals(expected, StringUtil.formatJavaSource(input));
47         }
48         {
49             String input = "{\n" +
50                     "bar\n" +
51                     "}\n" +
52                     "\n\nbaz\n\n\n\n";
53             String expected = "{\n" +
54                     "    bar\n" +
55                     "}\n\n" +
56                     "baz\n";
57             assertEquals(expected, StringUtil.formatJavaSource(input));
58         }
59     }
60 }