-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-refactor(configuration): Converted Kotlin files to Java in the j…
…ava/com/synopsys/integration/configuration/parse package.
- Loading branch information
1 parent
25dfa6e
commit 44c652a
Showing
2 changed files
with
94 additions
and
79 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...ation/src/test/java/com/synopsys/integration/configuration/parse/ListValueParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* configuration | ||
* | ||
* Copyright (c) 2020 Synopsys, Inc. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.synopsys.integration.configuration.parse; | ||
|
||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.synopsys.integration.configuration.util.Bds; | ||
|
||
class ListValueParserTest { | ||
private static class TestValueParser extends ValueParser<String> { | ||
@NotNull | ||
@Override | ||
public String parse(@NotNull final String value) throws ValueParseException { | ||
if ("-1".equals(value)) { | ||
throw new ValueParseException(value, "String", "Can convert anything but this value to a String."); | ||
} | ||
return value; | ||
} | ||
} | ||
|
||
private static class TestDefaultListValueParser extends ListValueParser<String> { | ||
final ValueParser<String> valueParser; | ||
|
||
public TestDefaultListValueParser(final ValueParser<String> valueParser) { | ||
super(valueParser); | ||
this.valueParser = valueParser; | ||
} | ||
} | ||
|
||
private static class TestCustomListValueParser extends ListValueParser<String> { | ||
final ValueParser<String> valueParser; | ||
|
||
public TestCustomListValueParser(final ValueParser<String> valueParser, final String delimiter) { | ||
super(valueParser, delimiter); | ||
this.valueParser = valueParser; | ||
} | ||
} | ||
|
||
@Test | ||
public void parseDefault() throws ValueParseException { | ||
final ListValueParser<String> listValueParser = new TestDefaultListValueParser(new TestValueParser()); | ||
final List<String> actualValues = listValueParser.parse("test,this,example , parser"); | ||
Assertions.assertEquals(Bds.listOf("test", "this", "example", "parser"), actualValues, "The list parser should be splitting on comma and trimming by default."); | ||
} | ||
|
||
@Test | ||
public void parseCustomDelimiters() throws ValueParseException { | ||
final ListValueParser<String> listValueParser = new TestCustomListValueParser(new TestValueParser(), "|"); | ||
final List<String> actualValues = listValueParser.parse("test this|parser|for real"); | ||
Assertions.assertEquals(Bds.listOf("test this", "parser", "for real"), actualValues); | ||
} | ||
|
||
@Test | ||
public void failsToParseInvalidElement() { | ||
final ListValueParser<String> listValueParser = new TestDefaultListValueParser(new TestValueParser()); | ||
Assertions.assertThrows(ValueParseException.class, () -> listValueParser.parse("test,should,throw,-1,for,test")); | ||
} | ||
|
||
@Test | ||
public void failsToParseEmpty() { | ||
final ListValueParser<String> listValueParser = new TestDefaultListValueParser(new TestValueParser()); | ||
Assertions.assertThrows(ValueParseException.class, () -> listValueParser.parse("should,,throw")); | ||
} | ||
|
||
@Test | ||
public void failsToParseWhitespace() { | ||
final ListValueParser<String> listValueParser = new TestDefaultListValueParser(new TestValueParser()); | ||
Assertions.assertThrows(ValueParseException.class, () -> listValueParser.parse("should, ,throw")); | ||
} | ||
} |
79 changes: 0 additions & 79 deletions
79
...uration/src/test/java/com/synopsys/integration/configuration/parse/ListValueParserTest.kt
This file was deleted.
Oops, something went wrong.