http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java new file mode 100644 index 0000000..d09ed8d --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java @@ -0,0 +1,254 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; + +import java.util.Collections; +import java.util.Map; + +/** + * Test Property Source used by converter tests. + */ +public class ConverterTestsPropertySource implements PropertySource{ + + @Override + public int getOrdinal() { + return 0; + } + + @Override + public String getName(){ + return "ConverterTestsPropertySource"; + } + + @Override + public PropertyValue get(String key) { + switch(key){ + // Bytes + case "tests.converter.byte.decimal": + return PropertyValue.of(key, "101", getName()); + case "tests.converter.byte.octal": + return PropertyValue.of(key, "02", getName()); + case "tests.converter.byte.hex.lowerX": + return PropertyValue.of(key, "0x2F", getName()); + case "tests.converter.byte.hex.upperX": + return PropertyValue.of(key, "0X3F", getName()); + case "tests.converter.byte.min": + return PropertyValue.of(key, "min", getName()); + case "tests.converter.byte.max": + return PropertyValue.of(key, "MAX_Value", getName()); + // Boolean + case "tests.converter.boolean.y1": + return PropertyValue.of(key, "y", getName()); + case "tests.converter.boolean.y2": + return PropertyValue.of(key, "Y", getName()); + case "tests.converter.boolean.yes1": + return PropertyValue.of(key, "yes", getName()); + case "tests.converter.boolean.yes2": + return PropertyValue.of(key, "Yes", getName()); + case "tests.converter.boolean.yes3": + return PropertyValue.of(key, "yeS", getName()); + case "tests.converter.boolean.true1": + return PropertyValue.of(key, "true", getName()); + case "tests.converter.boolean.true2": + return PropertyValue.of(key, "True", getName()); + case "tests.converter.boolean.true3": + return PropertyValue.of(key, "trUe", getName()); + case "tests.converter.boolean.t1": + return PropertyValue.of(key, "t", getName()); + case "tests.converter.boolean.t2": + return PropertyValue.of(key, "T", getName()); + case "tests.converter.boolean.n1": + return PropertyValue.of(key, "n", getName()); + case "tests.converter.boolean.n2": + return PropertyValue.of(key, "N", getName()); + case "tests.converter.boolean.no1": + return PropertyValue.of(key, "no", getName()); + case "tests.converter.boolean.no2": + return PropertyValue.of(key, "No", getName()); + case "tests.converter.boolean.no3": + return PropertyValue.of(key, "nO", getName()); + case "tests.converter.boolean.false1": + return PropertyValue.of(key, "false", getName()); + case "tests.converter.boolean.false2": + return PropertyValue.of(key, "False", getName()); + case "tests.converter.boolean.false3": + return PropertyValue.of(key, "falSe", getName()); + case "tests.converter.boolean.f1": + return PropertyValue.of(key, "f", getName()); + case "tests.converter.boolean.f2": + return PropertyValue.of(key, "F", getName()); + // Character + case "tests.converter.char.f": + return PropertyValue.of(key, "f", getName()); + case "tests.converter.char.d": + return PropertyValue.of(key, "'d'", getName()); + case "tests.converter.char.f-before": + return PropertyValue.of(key, " f", getName()); + case "tests.converter.char.f-after": + return PropertyValue.of(key, "f ", getName()); + case "tests.converter.char.f-around": + return PropertyValue.of(key, " f ", getName()); + case "tests.converter.char.f-numeric": + return PropertyValue.of(key, "101", getName()); + // currency + case "tests.converter.currency.code1": + return PropertyValue.of(key, "CHF", getName()); + case "tests.converter.currency.code2": + return PropertyValue.of(key, "cHf", getName()); + case "tests.converter.currency.code3": + return PropertyValue.of(key, " CHF", getName()); + case "tests.converter.currency.code4": + return PropertyValue.of(key, "CHF ", getName()); + case "tests.converter.currency.code5": + return PropertyValue.of(key, " CHF ", getName()); + case "tests.converter.currency.code-numeric1": + return PropertyValue.of(key, "100", getName()); + case "tests.converter.currency.code-numeric2": + return PropertyValue.of(key, " 100", getName()); + case "tests.converter.currency.code-numeric3": + return PropertyValue.of(key, "100 ", getName()); + case "tests.converter.currency.code-numeric4": + return PropertyValue.of(key, " 100 ", getName()); + case "tests.converter.currency.code-locale1": + return PropertyValue.of(key, "DE", getName()); + case "tests.converter.currency.code-locale2": + return PropertyValue.of(key, " DE", getName()); + case "tests.converter.currency.code-locale3": + return PropertyValue.of(key, "DE ", getName()); + case "tests.converter.currency.code-locale4": + return PropertyValue.of(key, " DE ", getName()); + //double + case "tests.converter.double.decimal": + return PropertyValue.of(key, "1.23456789", getName()); + case "tests.converter.double.decimalNegative": + return PropertyValue.of(key, "-1.23456789", getName()); + case "tests.converter.double.integer": + return PropertyValue.of(key, " 100", getName()); + case "tests.converter.double.hex1": + return PropertyValue.of(key, " 0XFF", getName()); + case "tests.converter.double.hex2": + return PropertyValue.of(key, "-0xFF ", getName()); + case "tests.converter.double.hex3": + return PropertyValue.of(key, "#FF", getName()); + case "tests.converter.double.octal": + return PropertyValue.of(key, "0013", getName()); + case "tests.converter.double.min": + return PropertyValue.of(key, "MIN_Value", getName()); + case "tests.converter.double.max": + return PropertyValue.of(key, "max", getName()); + case "tests.converter.double.nan": + return PropertyValue.of(key, "NAN", getName()); + case "tests.converter.double.pi": + return PropertyValue.of(key, "positive_infinity", getName()); + case "tests.converter.double.ni": + return PropertyValue.of(key, "Negative_Infinity", getName()); + //float + case "tests.converter.float.decimal": + return PropertyValue.of(key, "1.23456789", getName()); + case "tests.converter.float.decimalNegative": + return PropertyValue.of(key, "-1.23456789", getName()); + case "tests.converter.float.integer": + return PropertyValue.of(key, " 100", getName()); + case "tests.converter.float.hex1": + return PropertyValue.of(key, " 0XFF", getName()); + case "tests.converter.float.hex2": + return PropertyValue.of(key, "-0xFF ", getName()); + case "tests.converter.float.hex3": + return PropertyValue.of(key, "#FF", getName()); + case "tests.converter.float.octal": + return PropertyValue.of(key, "0013", getName()); + case "tests.converter.float.min": + return PropertyValue.of(key, "MIN_Value", getName()); + case "tests.converter.float.max": + return PropertyValue.of(key, "max", getName()); + case "tests.converter.float.nan": + return PropertyValue.of(key, "NAN", getName()); + case "tests.converter.float.pi": + return PropertyValue.of(key, "positive_infinity", getName()); + case "tests.converter.float.ni": + return PropertyValue.of(key, "Negative_Infinity", getName()); + // Integer + case "tests.converter.integer.decimal": + return PropertyValue.of(key, "101", getName()); + case "tests.converter.integer.octal": + return PropertyValue.of(key, "02", getName()); + case "tests.converter.integer.hex.lowerX": + return PropertyValue.of(key, "0x2F", getName()); + case "tests.converter.integer.hex.upperX": + return PropertyValue.of(key, "0X3F", getName()); + case "tests.converter.integer.min": + return PropertyValue.of(key, "min", getName()); + case "tests.converter.integer.max": + return PropertyValue.of(key, "MAX_Value", getName()); + // Long + case "tests.converter.long.decimal": + return PropertyValue.of(key, "101", getName()); + case "tests.converter.long.octal": + return PropertyValue.of(key, "02", getName()); + case "tests.converter.long.hex.lowerX": + return PropertyValue.of(key, "0x2F", getName()); + case "tests.converter.long.hex.upperX": + return PropertyValue.of(key, "0X3F", getName()); + case "tests.converter.long.min": + return PropertyValue.of(key, "min", getName()); + case "tests.converter.long.max": + return PropertyValue.of(key, "MAX_Value", getName()); + // Short + case "tests.converter.short.decimal": + return PropertyValue.of(key, "101", getName()); + case "tests.converter.short.octal": + return PropertyValue.of(key, "02", getName()); + case "tests.converter.short.hex.lowerX": + return PropertyValue.of(key, "0x2F", getName()); + case "tests.converter.short.hex.upperX": + return PropertyValue.of(key, "0X3F", getName()); + case "tests.converter.short.min": + return PropertyValue.of(key, "min", getName()); + case "tests.converter.short.max": + return PropertyValue.of(key, "MAX_Value", getName()); + // BigDecimal + case "tests.converter.bd.decimal": + return PropertyValue.of(key, "101", getName()); + case "tests.converter.bd.float": + return PropertyValue.of(key, "101.36438746", getName()); + case "tests.converter.bd.big": + return PropertyValue.of(key, "101666666666666662333337263723628763821638923628193612983618293628763", getName()); + case "tests.converter.bd.bigFloat": + return PropertyValue.of(key, "1016666666666666623333372637236287638216389293628763.101666666666666662333337263723628763821638923628193612983618293628763", getName()); + case "tests.converter.bd.hex.lowerX": + return PropertyValue.of(key, "0x2F", getName()); + case "tests.converter.bd.hex.upperX": + return PropertyValue.of(key, "0X3F", getName()); + } + return null; + } + + @Override + public Map<String, PropertyValue> getProperties() { + return Collections.emptyMap(); + } + + @Override + public boolean isScannable() { + return false; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java new file mode 100644 index 0000000..f17eadd --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java @@ -0,0 +1,159 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import java.util.Currency; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.*; + +/** + * Tests the default converter for currencies. + */ +public class CurrencyConverterTest { + + private static final String BGL = "BGL"; + private static final String CHF = "CHF"; + private static final String EUR = "EUR"; + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Currency_Code_CHF() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code1", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(valueRead, Currency.getInstance(CHF)); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Currency_Code_CHF1() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code2", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(valueRead, Currency.getInstance(CHF)); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Currency_Code_CHF_Whitespace_Before() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code3", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(Currency.getInstance(CHF), valueRead); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Currency_Code_CHF_Whitespace_After() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code4", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(Currency.getInstance(CHF), valueRead); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Currency_Code_CHF_Whitespace_Around() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code5", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(Currency.getInstance(CHF), valueRead); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Currency_Code_Numeric() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code-numeric1", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(Currency.getInstance(BGL).getNumericCode(), valueRead.getNumericCode()); + valueRead = config.get("tests.converter.currency.code-numeric2", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(Currency.getInstance(BGL).getNumericCode(), valueRead.getNumericCode()); + valueRead = config.get("tests.converter.currency.code-numeric3", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(Currency.getInstance(BGL).getNumericCode(), valueRead.getNumericCode()); + valueRead = config.get("tests.converter.currency.code-numeric4", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(Currency.getInstance(BGL).getNumericCode(), valueRead.getNumericCode()); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Currency_Code_Locale() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code-locale1", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(EUR, valueRead.getCurrencyCode()); + valueRead = config.get("tests.converter.currency.code-locale2", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(EUR, valueRead.getCurrencyCode()); + valueRead = config.get("tests.converter.currency.code-locale3", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(EUR, valueRead.getCurrencyCode()); + valueRead = config.get("tests.converter.currency.code-locale4", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(EUR, valueRead.getCurrencyCode()); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_NotPresent() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Byte valueRead = config.get("tests.converter.byte.foo", Byte.class); + assertThat(valueRead).isNull(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java new file mode 100644 index 0000000..ee2f33a --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java @@ -0,0 +1,175 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Tests the default converter for bytes. + */ +public class DoubleConverterTest { + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_Decimal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.decimal", Double.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.doubleValue(), 1.23456789, 0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_DecimalNegative() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.decimalNegative", Double.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.doubleValue(), -1.23456789, 0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_Integer() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.integer", Double.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.doubleValue(),100d, 0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_Hex1() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.hex1", Double.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.doubleValue(),255d, 0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_Hex2() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.hex2", Double.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.doubleValue(),-255d, 0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_Hex3() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.hex3", Double.class); + assertTrue(valueRead!=null); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_MinValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.min", Double.class); + assertTrue(valueRead!=null); + assertEquals(Double.MIN_VALUE, valueRead.doubleValue(),0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_MaxValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.max", Double.class); + assertTrue(valueRead!=null); + assertEquals(Double.MAX_VALUE, valueRead.doubleValue(),0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_NaNValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.nan", Double.class); + assertTrue(valueRead!=null); + assertEquals(Double.NaN, valueRead.doubleValue(),0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_PositiveInfinityValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.pi", Double.class); + assertTrue(valueRead!=null); + assertEquals(Double.POSITIVE_INFINITY, valueRead.doubleValue(),0.0d); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Double_NegativeInfinityValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Double valueRead = config.get("tests.converter.double.ni", Double.class); + assertTrue(valueRead!=null); + assertEquals(Double.NEGATIVE_INFINITY, valueRead.doubleValue(),0.0d); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java new file mode 100644 index 0000000..8a37c0f --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java @@ -0,0 +1,79 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.Duration; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class DurationConverterTest { + + @Mock + ConversionContext context; + + /** + * Examples: + * <pre> + * "PT20.345S" -- parses as "20.345 seconds" + * "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds) + * "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds) + * "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds) + * "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes" + * "P-6H3M" -- parses as "-6 hours and +3 minutes" + * "-P6H3M" -- parses as "-6 hours and -3 minutes" + * "-P-6H+3M" -- parses as "+6 hours and -3 minutes" + * </pre> + * @throws Exception + */ + @Test + public void convert() throws Exception { + DurationConverter conv = new DurationConverter(); + Duration duration = conv.convert("PT20.345S", context); + assertEquals(Duration.parse("PT20.345S"), duration); + duration = conv.convert("PT15M", context); + assertEquals(Duration.parse("PT15M"), duration); + duration = conv.convert("PT10H", context); + assertEquals(Duration.parse("PT10H"), duration); + duration = conv.convert("P2D", context); + assertEquals(Duration.parse("P2D"), duration); + duration = conv.convert("P2DT3H4M", context); + assertEquals(Duration.parse("P2DT3H4M"), duration); + duration = conv.convert("foo", context); + assertNull(duration); + } + + @Test + public void equalsAndHashcode() throws Exception { + DurationConverter conv1 = new DurationConverter(); + DurationConverter conv2 = new DurationConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java new file mode 100644 index 0000000..98ea720 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java @@ -0,0 +1,176 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Tests the default converter for bytes. + */ +public class FloatConverterTest { + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_Decimal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.decimal", Float.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.floatValue(), 1.23456789f, 0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_DecimalNegative() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.decimalNegative", Float.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.floatValue(), -1.23456789f, 0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_Integer() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.integer", Float.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.floatValue(),100f, 0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_Hex1() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.hex1", Float.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.floatValue(),255f, 0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_Hex2() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.hex2", Float.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.floatValue(),-255f, 0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_Hex3() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.hex3", Float.class); + assertTrue(valueRead!=null); + assertEquals(valueRead.floatValue(),255f, 0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_MinValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.min", Float.class); + assertTrue(valueRead!=null); + assertEquals(Float.MIN_VALUE, valueRead.floatValue(),0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_MaxValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.max", Float.class); + assertTrue(valueRead!=null); + assertEquals(Float.MAX_VALUE, valueRead.floatValue(),0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_NaNValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.nan", Float.class); + assertTrue(valueRead!=null); + assertEquals(Float.NaN, valueRead.floatValue(),0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_PositiveInfinityValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.pi", Float.class); + assertTrue(valueRead!=null); + assertEquals(Float.POSITIVE_INFINITY, valueRead.floatValue(),0.0f); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Float_NegativeInfinityValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Float valueRead = config.get("tests.converter.float.ni", Float.class); + assertTrue(valueRead!=null); + assertEquals(Float.NEGATIVE_INFINITY, valueRead.floatValue(),0.0f); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java new file mode 100644 index 0000000..4a9a828 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.Instant; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class InstantConverterTest { + + @Mock + ConversionContext context; + + @Test + public void convert() throws Exception { + InstantConverter conv = new InstantConverter(); + Instant value = conv.convert("2007-12-03T10:15:30.00Z", context); + assertEquals(value, Instant.parse("2007-12-03T10:15:30.00Z")); + value = conv.convert("foo", context); + assertNull(value); + } + + @Test + public void equalsAndHashcode() throws Exception { + InstantConverter conv1 = new InstantConverter(); + InstantConverter conv2 = new InstantConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java new file mode 100644 index 0000000..03b0f12 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java @@ -0,0 +1,111 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the default converter for Integers. + */ +public class IntegerConverterTest { + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Integer_Decimal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Integer valueRead = config.get("tests.converter.integer.decimal", Integer.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), 101); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Integer_Octal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Integer valueRead = config.get("tests.converter.integer.octal", Integer.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Integer.decode("02").intValue()); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Integer_Hex() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Integer valueRead = config.get("tests.converter.integer.hex.lowerX", Integer.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Integer.decode("0x2F").intValue()); + valueRead = config.get("tests.converter.integer.hex.upperX", Integer.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Integer.decode("0X3F").intValue()); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_NotPresent() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Integer valueRead = config.get("tests.converter.integer.foo", Integer.class); + assertFalse(valueRead != null); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Integer_MinValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Integer valueRead = config.get("tests.converter.integer.min", Integer.class); + assertTrue(valueRead != null); + assertEquals(Integer.MIN_VALUE, valueRead.intValue()); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Integer_MaxValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Integer valueRead = config.get("tests.converter.integer.max", Integer.class); + assertTrue(valueRead != null); + assertEquals(Integer.MAX_VALUE, valueRead.intValue()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java new file mode 100644 index 0000000..752699d --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.LocalDate; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class LocalDateConverterTest { + + @Mock + ConversionContext context; + + @Test + public void convert() throws Exception { + LocalDateConverter conv = new LocalDateConverter(); + LocalDate value = conv.convert("2007-12-03", context); + assertEquals(value, LocalDate.parse("2007-12-03")); + value = conv.convert("foo", context); + assertNull(value); + } + + @Test + public void equalsAndHashcode() throws Exception { + LocalDateConverter conv1 = new LocalDateConverter(); + LocalDateConverter conv2 = new LocalDateConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java new file mode 100644 index 0000000..945682a --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.LocalDateTime; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class LocalDateTimeConverterTest { + + @Mock + ConversionContext context; + + @Test + public void convert() throws Exception { + LocalDateTimeConverter conv = new LocalDateTimeConverter(); + LocalDateTime value = conv.convert("2007-12-03T10:15:30", context); + assertEquals(value, LocalDateTime.parse("2007-12-03T10:15:30")); + value = conv.convert("foo", context); + assertNull(value); + } + + @Test + public void equalsAndHashcode() throws Exception { + LocalDateTimeConverter conv1 = new LocalDateTimeConverter(); + LocalDateTimeConverter conv2 = new LocalDateTimeConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java new file mode 100644 index 0000000..b75ed7b --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.LocalTime; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class LocalTimeConverterTest { + + @Mock + ConversionContext context; + + @Test + public void convert() throws Exception { + LocalTimeConverter conv = new LocalTimeConverter(); + LocalTime value = conv.convert("10:15:30", context); + assertEquals(value, LocalTime.parse("10:15:30")); + value = conv.convert("foo", context); + assertNull(value); + } + + @Test + public void equalsAndHashcode() throws Exception { + LocalTimeConverter conv1 = new LocalTimeConverter(); + LocalTimeConverter conv2 = new LocalTimeConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java new file mode 100644 index 0000000..0df6b09 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java @@ -0,0 +1,111 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the default converter for Longs. + */ +public class LongConverterTest { + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Long_Decimal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Long valueRead = config.get("tests.converter.long.decimal", Long.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), 101); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Long_Octal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Long valueRead = config.get("tests.converter.long.octal", Long.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Long.decode("02").intValue()); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Long_Hex() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Long valueRead = config.get("tests.converter.long.hex.lowerX", Long.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Long.decode("0x2F").intValue()); + valueRead = config.get("tests.converter.long.hex.upperX", Long.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Long.decode("0X3F").intValue()); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_NotPresent() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Long valueRead = config.get("tests.converter.long.foo", Long.class); + assertFalse(valueRead != null); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Long_MinValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Long valueRead = config.get("tests.converter.long.min", Long.class); + assertTrue(valueRead != null); + assertEquals(Long.MIN_VALUE, valueRead.longValue()); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Long_MaxValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Long valueRead = config.get("tests.converter.long.max", Long.class); + assertTrue(valueRead != null); + assertEquals(Long.MAX_VALUE, valueRead.longValue()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java new file mode 100644 index 0000000..3fa2e58 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java @@ -0,0 +1,103 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import java.math.BigDecimal; + +import static org.junit.Assert.*; + +/** + * Tests the default converter for Number. + */ +public class NumberConverterTest { + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Decimal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.bd.decimal", Number.class); + assertTrue(valueRead!=null); + assertEquals(valueRead, 101L); + } + + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Hex() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.bd.hex.lowerX", Number.class); + assertTrue(valueRead!=null); + assertEquals(valueRead, Long.valueOf("47")); + valueRead = config.get("tests.converter.bd.hex.upperX", Number.class); + assertTrue(valueRead!=null); + assertEquals(valueRead, Long.valueOf("63")); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_NotPresent() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.bd.foo", Number.class); + assertFalse(valueRead!=null); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_BigValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.bd.big", Number.class); + assertTrue(valueRead!=null); + assertEquals(new BigDecimal("101666666666666662333337263723628763821638923628193612983618293628763"), + valueRead); + } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_BigFloatValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.bd.bigFloat", Number.class); + assertTrue(valueRead!=null); + assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" + + "63723628763821638923628193612983618293628763"), valueRead); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java new file mode 100644 index 0000000..4ab65a2 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.OffsetDateTime; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class OffsetDateTimeConverterTest { + + @Mock + ConversionContext context; + + @Test + public void convert() throws Exception { + OffsetDateTimeConverter conv = new OffsetDateTimeConverter(); + OffsetDateTime value = conv.convert("2007-12-03T10:15:30+01:00", context); + assertEquals(value, OffsetDateTime.parse("2007-12-03T10:15:30+01:00")); + value = conv.convert("foo", context); + assertNull(value); + } + + @Test + public void equalsAndHashcode() throws Exception { + OffsetDateTimeConverter conv1 = new OffsetDateTimeConverter(); + OffsetDateTimeConverter conv2 = new OffsetDateTimeConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java new file mode 100644 index 0000000..3b28b2c --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java @@ -0,0 +1,56 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.time.OffsetTime; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class OffsetTimeConverterTest { + @Mock + ConversionContext context; + + @Test + public void convert() throws Exception { + OffsetTimeConverter conv = new OffsetTimeConverter(); + OffsetTime value = conv.convert("10:15:30+01:00", context); + assertEquals(value, OffsetTime.parse("10:15:30+01:00")); + value = conv.convert("foo", context); + assertNull(value); + } + + @Test + public void equalsAndHashcode() throws Exception { + OffsetTimeConverter conv1 = new OffsetTimeConverter(); + OffsetTimeConverter conv2 = new OffsetTimeConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java new file mode 100644 index 0000000..f35280b --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java @@ -0,0 +1,42 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.ConfigException; +import org.junit.Test; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +public class OptionalConverterTest { + + @Test + public void nullConversionYieldsEmptyOptional() { + final Optional<?> result = new OptionalConverter().convert(null, null); + assertThat(result).isNotNull(); + assertThat(result.isPresent()).isFalse(); + } + + @Test(expected = ConfigException.class) + public void emulateExceptionWhenGivenContextIsNull() { + new OptionalConverter().convert("JustATestValueThatIsIgnored", null); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java new file mode 100644 index 0000000..a7f9eab --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java @@ -0,0 +1,58 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.Assert.*; + +/** + * Created by atsti on 02.10.2017. + */ +@RunWith(MockitoJUnitRunner.class) +public class PathConverterTest { + + @Mock + ConversionContext context; + + @Test + public void convert() throws Exception { + PathConverter conv = new PathConverter(); + Path value = conv.convert("testRoot", context); + assertEquals(value, Paths.get("testRoot")); + value = conv.convert("foo", context); + assertNotNull(value); + } + + @Test + public void equalsAndHashcode() throws Exception { + PathConverter conv1 = new PathConverter(); + PathConverter conv2 = new PathConverter(); + assertEquals(conv1, conv2); + assertEquals(conv1.hashCode(), conv2.hashCode()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java new file mode 100644 index 0000000..ca9228d --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java @@ -0,0 +1,111 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the default converter for Shorts. + */ +public class ShortConverterTest { + + /** + * Test conversion. The values are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Short_Decimal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Short valueRead = config.get("tests.converter.short.decimal", Short.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), 101); + } + + /** + * Test conversion. The values are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Short_Octal() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Short valueRead = config.get("tests.converter.short.octal", Short.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Short.decode("02").intValue()); + } + + /** + * Test conversion. The values are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Short_Hex() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Short valueRead = config.get("tests.converter.short.hex.lowerX", Short.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Short.decode("0x2F").intValue()); + valueRead = config.get("tests.converter.short.hex.upperX", Short.class); + assertTrue(valueRead != null); + assertEquals(valueRead.intValue(), Short.decode("0X3F").intValue()); + } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_NotPresent() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Short valueRead = config.get("tests.converter.short.foo", Short.class); + assertFalse(valueRead != null); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Short_MinValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Short valueRead = config.get("tests.converter.short.min", Short.class); + assertTrue(valueRead != null); + assertEquals(Short.MIN_VALUE, valueRead.intValue()); + } + + /** + * Test conversion. The values are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_Short_MaxValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Short valueRead = config.get("tests.converter.short.max", Short.class); + assertTrue(valueRead != null); + assertEquals(Short.MAX_VALUE, valueRead.intValue()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java new file mode 100644 index 0000000..263a76e --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java @@ -0,0 +1,68 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; + +import java.net.URI; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * Tests conversion of the {@link URI}-converter. + */ +public class URIConverterTest { + + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(URI.class)) + .build(); + + @Test + public void testConvert_URI() throws Exception { + URIConverter converter = new URIConverter(); + assertEquals(new URI("test:path"), converter.convert("test:path", context)); + } + + @Test + public void testConvert_URI_WithSpaces() throws Exception { + URIConverter converter = new URIConverter(); + assertEquals(new URI("test:path"), converter.convert(" test:path\t", context)); + } + + @Test + public void testConvert_URI_WithSpacesBefore() throws Exception { + URIConverter converter = new URIConverter(); + assertEquals(new URI("test:path"), converter.convert(" test:path", context)); + } + + @Test + public void testConvert_URI_WithSpacesAfter() throws Exception { + URIConverter converter = new URIConverter(); + assertEquals(new URI("test:path"), converter.convert("test:path ", context)); + } + + @Test + public void testConvert_NotPresent() throws Exception { + URIConverter converter = new URIConverter(); + assertNull(converter.convert("", context)); + assertNull(converter.convert(null, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java new file mode 100644 index 0000000..eee5024 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java @@ -0,0 +1,69 @@ +/* + * 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 org.apache.tamaya.core.internal.converters; + +import org.apache.tamaya.spi.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; + +import java.net.URI; +import java.net.URL; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * Tests conversion of the {@link URL}-converter. + */ +public class URLConverterTest { + + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(URI.class)) + .build(); + + @Test + public void testConvert_URL() throws Exception { + URLConverter converter = new URLConverter(); + assertEquals(new URL("http://google.com:4000/path"), converter.convert("http://google.com:4000/path", context)); + } + + @Test + public void testConvert_URL_WithSpaces() throws Exception { + URLConverter converter = new URLConverter(); + assertEquals(new URL("http://google.com:4000/path"), converter.convert(" http://google.com:4000/path\t", context)); + } + + @Test + public void testConvert_URL_WithSpacesBefore() throws Exception { + URLConverter converter = new URLConverter(); + assertEquals(new URL("http://google.com:4000/path"), converter.convert(" http://google.com:4000/path", context)); + } + + @Test + public void testConvert_URL_WithSpacesAfter() throws Exception { + URLConverter converter = new URLConverter(); + assertEquals(new URL("http://google.com:4000/path"), converter.convert("http://google.com:4000/path ", context)); + } + + @Test + public void testConvert_NotPresent() throws Exception { + URLConverter converter = new URLConverter(); + assertNull(converter.convert("", context)); + assertNull(converter.convert(null, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/code/old/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java new file mode 100644 index 0000000..c315ff6 --- /dev/null +++ b/code/old/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.tamaya.core.testdata; + +import org.apache.tamaya.spisupport.propertysource.BasePropertySource; +import org.apache.tamaya.spi.PropertyValue; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Test provider reading properties from classpath:cfg/defaults/**.properties. + */ +public class TestPropertyDefaultSource extends BasePropertySource{ + + private Map<String,PropertyValue> properties = new HashMap<>(); + + public TestPropertyDefaultSource() { + super(100); + properties.put("name",PropertyValue.of("name", "Anatole", "test")); + properties.put("name2",PropertyValue.of("name2", "Sabine", "test")); + properties = Collections.unmodifiableMap(properties); + } + + @Override + public String getName() { + return "default-testdata-properties"; + } + + @Override + public Map<String, PropertyValue> getProperties() { + return properties; + } + + @Override + public boolean isScannable() { + return true; + } + +}