diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java |
Publish
Diffstat (limited to 'configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java')
-rw-r--r-- | configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java b/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java new file mode 100644 index 00000000000..f0713a090ec --- /dev/null +++ b/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java @@ -0,0 +1,77 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.codegen; + +import static org.junit.Assert.*; + +import java.io.*; +import java.util.List; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; + + +/** + * @author <a href="musum@yahoo-inc.com">Harald Musum</a> + */ +public class NormalizedDefinitionTest { + + @Test + public void testNormalizingFromReader() { + String def = + "version=1\n" + + "aString string \n" + + "anInt int #comment \n" + + "aStringCommentCharacterAfter string default=\"ab\" #foo\n" + + "aStringWithCommentCharacter string default=\"a#b\"\n" + + "aStringWithEscapedQuote string default=\"a\"b\"\n"; + + StringReader reader = new StringReader(def); + + NormalizedDefinition nd = new NormalizedDefinition(); + List<String> out = null; + try { + nd.normalize(new BufferedReader(reader)); + out = nd.getNormalizedContent(); + } catch (IOException e) { + e.printStackTrace(); + } + + assertNotNull(out); + assertThat(out.size(), is(6)); + assertThat(out.get(0), is ("version=1\n")); + assertThat(out.get(1), is ("aString string\n")); + assertThat(out.get(2), is ("anInt int\n")); + assertThat(out.get(3), is ("aStringCommentCharacterAfter string default=\"ab\"\n")); + assertThat(out.get(4), is ("aStringWithCommentCharacter string default=\"a#b\"\n")); + assertThat(out.get(5), is ("aStringWithEscapedQuote string default=\"a\"b\"\n")); + + reader.close(); + } + + @Test + public void testNormalizingFromFile() throws IOException { + FileReader fileReader = null; + try { + fileReader = new FileReader("src/test/resources/allfeatures.def"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + NormalizedDefinition nd = new NormalizedDefinition(); + List<String> out = null; + try { + nd.normalize(new BufferedReader(fileReader)); + out = nd.getNormalizedContent(); + } catch (IOException e) { + e.printStackTrace(); + } + + assertNotNull(out); + assertThat(out.size(), is(70)); + assertThat(out.get(19), is ("version=11\n")); + + assertNotNull(fileReader); + fileReader.close(); + } +} |