http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java index 46c1e58..7accdcd 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -25,6 +26,9 @@ import static org.junit.Assert.assertNull; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import static org.junit.Assert.assertTrue; import org.junit.Test; /** @@ -35,6 +39,7 @@ public class BooleanConverterTest { /** * Test conversion. The value are provided by * {@link ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -75,6 +80,7 @@ public class BooleanConverterTest { /** * Test conversion. The value are provided by * {@link ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -115,4 +121,34 @@ public class BooleanConverterTest { valueRead = config.get("tests.converter.boolean.foo", Boolean.class); assertNull(valueRead); } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * + * @throws ConfigException + */ + @Test(expected = ConfigException.class) + public void testConvert_BooleanInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + Boolean valueRead = config.get("tests.converter.boolean.invalid", Boolean.class); + assertNull(valueRead); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Boolean.class)).build(); + BooleanConverter converter = new BooleanConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("true (ignore case) (BooleanConverter)")); + assertTrue(context.getSupportedFormats().contains("false (ignore case) (BooleanConverter)")); + } + + @Test + public void testHashCode() { + BooleanConverter instance = new BooleanConverter(); + assertEquals(BooleanConverter.class.hashCode(), instance.hashCode()); + } + }
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java index 3eb48e3..8eea92d 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java @@ -18,8 +18,11 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.junit.Test; import static org.junit.Assert.*; @@ -78,4 +81,33 @@ public class ByteConverterTest { assertThat(valueRead).isNotNull(); assertEquals(Byte.MAX_VALUE, valueRead.byteValue()); } + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * + * @throws ConfigException + */ + @Test(expected = ConfigException.class) + public void testConvert_ByteInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + Byte valueRead = config.get("tests.converter.byte.invalid", Byte.class); + assertNull(valueRead); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Byte.class)).build(); + ByteConverter converter = new ByteConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<byte> (ByteConverter)")); + assertTrue(context.getSupportedFormats().contains("MIN_VALUE (ByteConverter)")); + assertTrue(context.getSupportedFormats().contains("MAX_VALUE (ByteConverter)")); + } + + @Test + public void testHashCode() { + ByteConverter instance = new ByteConverter(); + assertEquals(ByteConverter.class.hashCode(), instance.hashCode()); + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java index 12810cf..9f27582 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java @@ -18,12 +18,16 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.junit.Test; import static org.junit.Assert.*; import static org.assertj.core.api.Assertions.*; + /** * Tests conversion of the {@link CharConverter}. */ @@ -42,7 +46,7 @@ public class CharConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Character valueRead = config.get("tests.converter.char.f-numeric", Character.class); assertThat(valueRead).isNotNull(); - assertEquals(valueRead.charValue(), (char)101); + assertEquals(valueRead.charValue(), (char) 101); } @Test @@ -51,6 +55,7 @@ public class CharConverterTest { Character valueRead = config.get("tests.converter.char.d", Character.class); assertThat(valueRead).isNotNull(); assertEquals(valueRead.charValue(), 'd'); + } @Test @@ -61,6 +66,20 @@ public class CharConverterTest { assertEquals(valueRead.charValue(), '\''); } + @Test(expected = ConfigException.class) + public void testConvert_Character_TwoSingleQuotes() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + config.get("tests.converter.char.two-single-quotes", Character.class); + } + + @Test + public void testConvert_Character_ThreeSingleQuotes() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Character valueRead = config.get("tests.converter.char.three-single-quotes", Character.class); + assertThat(valueRead).isNotNull(); + assertEquals(valueRead.charValue(), '\''); + } + @Test public void testConvert_Character_WithWhitespace_Before() throws Exception { Configuration config = ConfigurationProvider.getConfiguration(); @@ -91,4 +110,58 @@ public class CharConverterTest { Character valueRead = config.get("tests.converter.char.foo", Character.class); assertNull(valueRead); } + + /** + * Test conversion. The value are provided by + * {@link ConverterTestsPropertySource}. + * + * @throws ConfigException + */ + @Test + public void testConvert_CharString() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + Character valueRead = config.get("tests.converter.char.invalid", Character.class); + assertThat(valueRead).isNotNull(); + assertEquals(valueRead.charValue(), 'i'); //Strings return the first character + } + + @Test + public void testConvert_CharQuotedString() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + Character valueRead = config.get("tests.converter.char.quoted-invalid", Character.class); + assertThat(valueRead).isNotNull(); + assertEquals(valueRead.charValue(), 'i'); //Strings return the first character + } + + @Test + public void testConvert_CharUnicode() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + Character valueRead = config.get("tests.converter.char.ã", Character.class); + assertThat(valueRead).isNotNull(); + assertEquals(valueRead.charValue(), 'ã'); + } + + @Test + public void testConvert_CharUnicodeString() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + Character valueRead = config.get("tests.converter.char.à¸à¸à¸à¸à¸ à¸à¸à¸à¸à¸", Character.class); + assertThat(valueRead).isNotNull(); + assertEquals(valueRead.charValue(), 'à¸'); //Strings return the first character + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Character.class)).build(); + CharConverter converter = new CharConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<char> (CharConverter)")); + assertTrue(context.getSupportedFormats().contains("\\'<char>\\' (CharConverter)")); + } + + @Test + public void testHashCode() { + CharConverter instance = new CharConverter(); + assertEquals(CharConverter.class.hashCode(), instance.hashCode()); + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java index 38e150e..4877d9a 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java @@ -64,4 +64,19 @@ public class ClassConverterTest { assertNull(converter.convert("", context)); assertNull(converter.convert(null, context)); } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(Class.class)).build(); + ClassConverter converter = new ClassConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().contains("<fullyQualifiedClassName> (ClassConverter)")); + } + + @Test + public void testHashCode() { + ClassConverter instance = new ClassConverter(); + assertEquals(ClassConverter.class.hashCode(), instance.hashCode()); + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConvertQueryTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConvertQueryTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConvertQueryTest.java new file mode 100644 index 0000000..26998e3 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConvertQueryTest.java @@ -0,0 +1,80 @@ +/* + * 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.apache.tamaya.TypeLiteral; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author William.Lieurance 2018-02-10 + */ +public class ConvertQueryTest { + + /** + * Test of query method, of class ConvertQuery. + */ + @Test + public void testIntegerQuery() { + Configuration config = ConfigurationProvider.getConfiguration(); + ConvertQuery<Integer> converter = new ConvertQuery<>("101", TypeLiteral.of(Integer.class)); + Integer result = converter.query(config); + assertEquals(101, result.longValue()); + } + + /** + * Test of query method, of class ConvertQuery. + */ + @Test + public void testConfigUsingIntegerQuery() { + Configuration config = ConfigurationProvider.getConfiguration(); + ConvertQuery<Integer> converter = new ConvertQuery<>("101", TypeLiteral.of(Integer.class)); + Integer result = config.query(converter); + assertEquals(101, result.longValue()); + } + + /** + * Test of query method, of class ConvertQuery. + */ + @Test + public void testNonGenericQuery() { + Configuration config = ConfigurationProvider.getConfiguration(); + + Integer intResult = (Integer) new ConvertQuery("101", TypeLiteral.of(Integer.class)).query(config); + assertEquals(101, intResult.longValue()); + + Boolean booleanResult = (Boolean) new ConvertQuery("true", TypeLiteral.of(Boolean.class)).query(config); + assertEquals(Boolean.TRUE, booleanResult); + } + + /** + * Test of query method, of class ConvertQuery. + */ + @Test + public void testNullWithoutSuccess() { + Configuration config = ConfigurationProvider.getConfiguration(); + + Integer intResult = (Integer) new ConvertQuery("invalid", TypeLiteral.of(Integer.class)).query(config); + assertNull(intResult); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java index dd7649f..1ef80f1 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java @@ -27,7 +27,7 @@ import java.util.Map; /** * Test Property Source used by converter tests. */ -public class ConverterTestsPropertySource implements PropertySource{ +public class ConverterTestsPropertySource implements PropertySource { @Override public int getOrdinal() { @@ -35,13 +35,13 @@ public class ConverterTestsPropertySource implements PropertySource{ } @Override - public String getName(){ + public String getName() { return "ConverterTestsPropertySource"; } @Override public PropertyValue get(String key) { - switch(key){ + switch (key) { // Bytes case "tests.converter.byte.decimal": return PropertyValue.of(key, "101", getName()); @@ -55,6 +55,8 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "min", getName()); case "tests.converter.byte.max": return PropertyValue.of(key, "MAX_Value", getName()); + case "tests.converter.byte.invalid": + return PropertyValue.of(key, "invalid", getName()); // Boolean case "tests.converter.boolean.y1": return PropertyValue.of(key, "y", getName()); @@ -96,13 +98,13 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "f", getName()); case "tests.converter.boolean.f2": return PropertyValue.of(key, "F", getName()); + case "tests.converter.boolean.invalid": + return PropertyValue.of(key, "invalid", 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.single-quote": - return PropertyValue.of(key, "'", getName()); case "tests.converter.char.f-before": return PropertyValue.of(key, " f", getName()); case "tests.converter.char.f-after": @@ -111,6 +113,21 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, " f ", getName()); case "tests.converter.char.f-numeric": return PropertyValue.of(key, "101", getName()); + case "tests.converter.char.single-quote": + return PropertyValue.of(key, "'", getName()); + case "tests.converter.char.two-single-quotes": + return PropertyValue.of(key, "''", getName()); + case "tests.converter.char.three-single-quotes": + return PropertyValue.of(key, "'''", getName()); + case "tests.converter.char.invalid": + return PropertyValue.of(key, "invalid", getName()); + case "tests.converter.char.quoted-invalid": + return PropertyValue.of(key, "'invalid'", getName()); + case "tests.converter.char.ã": + return PropertyValue.of(key, "ã", getName()); + case "tests.converter.char.à¸à¸à¸à¸à¸ à¸à¸à¸à¸à¸": + return PropertyValue.of(key, "à¸à¸à¸à¸à¸ à¸à¸à¸à¸à¸", getName()); + // currency case "tests.converter.currency.code1": return PropertyValue.of(key, "CHF", getName()); @@ -138,6 +155,14 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "DE ", getName()); case "tests.converter.currency.code-locale4": return PropertyValue.of(key, " DE ", getName()); + case "tests.converter.currency.code-locale-twopart": + return PropertyValue.of(key, "jp_JP", getName()); + case "tests.converter.currency.code-locale-threepart": + return PropertyValue.of(key, "jp_JP_JP", getName()); + case "tests.converter.currency.code-locale-fourpart": + return PropertyValue.of(key, "jp_JP_JP_JP", getName()); + case "tests.converter.currency.invalid": + return PropertyValue.of(key, "invalid", getName()); //double case "tests.converter.double.decimal": return PropertyValue.of(key, "1.23456789", getName()); @@ -163,6 +188,8 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "positive_infinity", getName()); case "tests.converter.double.ni": return PropertyValue.of(key, "Negative_Infinity", getName()); + case "tests.converter.double.invalid": + return PropertyValue.of(key, "invalid", getName()); //float case "tests.converter.float.decimal": return PropertyValue.of(key, "1.23456789", getName()); @@ -188,6 +215,8 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "positive_infinity", getName()); case "tests.converter.float.ni": return PropertyValue.of(key, "Negative_Infinity", getName()); + case "tests.converter.float.invalid": + return PropertyValue.of(key, "invalid", getName()); // Integer case "tests.converter.integer.decimal": return PropertyValue.of(key, "101", getName()); @@ -201,6 +230,8 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "min", getName()); case "tests.converter.integer.max": return PropertyValue.of(key, "MAX_Value", getName()); + case "tests.converter.integer.invalid": + return PropertyValue.of(key, "invalid", getName()); // Long case "tests.converter.long.decimal": return PropertyValue.of(key, "101", getName()); @@ -214,6 +245,8 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "min", getName()); case "tests.converter.long.max": return PropertyValue.of(key, "MAX_Value", getName()); + case "tests.converter.long.invalid": + return PropertyValue.of(key, "invalid", getName()); // Short case "tests.converter.short.decimal": return PropertyValue.of(key, "101", getName()); @@ -227,7 +260,9 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "min", getName()); case "tests.converter.short.max": return PropertyValue.of(key, "MAX_Value", getName()); - // BigDecimal + case "tests.converter.short.invalid": + return PropertyValue.of(key, "invalid", getName()); + // BigDecimal & BigInteger case "tests.converter.bd.decimal": return PropertyValue.of(key, "101", getName()); case "tests.converter.bd.float": @@ -240,6 +275,21 @@ public class ConverterTestsPropertySource implements PropertySource{ return PropertyValue.of(key, "0x2F", getName()); case "tests.converter.bd.hex.upperX": return PropertyValue.of(key, "0X3F", getName()); + case "tests.converter.bd.hex.negLowerX": + return PropertyValue.of(key, "-0x2F", getName()); + case "tests.converter.bd.hex.negUpperX": + return PropertyValue.of(key, "-0X3F", getName()); + case "tests.converter.bd.hex.badX": + return PropertyValue.of(key, "0X3G2", getName()); + case "tests.converter.bd.hex.negBadX": + return PropertyValue.of(key, "-0X3G2", getName()); + case "tests.converter.bd.hex.subTenX": + return PropertyValue.of(key, "0XFFFFFF", getName()); + case "tests.converter.bd.hex.negSubTenX": + return PropertyValue.of(key, "-0X0107", getName()); + case "tests.converter.bd.invalid": + return PropertyValue.of(key, "invalid", getName()); + } return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java index f17eadd..2541f66 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java @@ -23,6 +23,9 @@ import org.apache.tamaya.ConfigurationProvider; import org.junit.Test; import java.util.Currency; +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.*; @@ -33,12 +36,14 @@ import static org.junit.Assert.*; public class CurrencyConverterTest { private static final String BGL = "BGL"; - private static final String CHF = "CHF"; - private static final String EUR = "EUR"; + private static final String CHF = "CHF"; + private static final String EUR = "EUR"; + private static final String JPY = "JPY"; - /** + /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -52,6 +57,7 @@ public class CurrencyConverterTest { /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -65,6 +71,7 @@ public class CurrencyConverterTest { /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -78,6 +85,7 @@ public class CurrencyConverterTest { /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -91,6 +99,7 @@ public class CurrencyConverterTest { /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -104,6 +113,7 @@ public class CurrencyConverterTest { /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -126,6 +136,7 @@ public class CurrencyConverterTest { /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test @@ -148,12 +159,47 @@ public class CurrencyConverterTest { /** * Test conversion. The values are provided by * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * * @throws Exception */ @Test - public void testConvert_NotPresent() throws Exception { + public void testConvert_Currency_Code_Multipart_Locale() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code-locale-twopart", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(JPY, valueRead.getCurrencyCode()); + valueRead = config.get("tests.converter.currency.code-locale-threepart", Currency.class); + assertThat(valueRead).isNotNull(); + assertEquals(JPY, valueRead.getCurrencyCode()); + } + + @Test(expected = ConfigException.class) + public void testConvert_Currency_Code_Fourpart_Locale_Invalid() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Currency valueRead = config.get("tests.converter.currency.code-locale-fourpart", Currency.class); + assertNull(valueRead); + } + + @Test(expected = ConfigException.class) + public void testConvert_CurrencyInvalid() throws ConfigException { Configuration config = ConfigurationProvider.getConfiguration(); - Byte valueRead = config.get("tests.converter.byte.foo", Byte.class); - assertThat(valueRead).isNull(); + config.get("tests.converter.currency.invalid", Currency.class); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Currency.class)).build(); + CurrencyConverter converter = new CurrencyConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<numericValue> (CurrencyConverter)")); + assertTrue(context.getSupportedFormats().contains("<locale> (CurrencyConverter)")); + assertTrue(context.getSupportedFormats().contains("<currencyCode>, using Locale.ENGLISH (CurrencyConverter)")); + } + + @Test + public void testHashCode() { + CurrencyConverter instance = new CurrencyConverter(); + assertEquals(CurrencyConverter.class.hashCode(), instance.hashCode()); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java index ee2f33a..1f5070d 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java @@ -18,15 +18,18 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import static org.junit.Assert.assertEquals; import org.junit.Test; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** - * Tests the default converter for bytes. + * Tests the default converter for doubles. */ public class DoubleConverterTest { @@ -40,7 +43,7 @@ public class DoubleConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Double valueRead = config.get("tests.converter.double.decimal", Double.class); assertTrue(valueRead!=null); - assertEquals(valueRead.doubleValue(), 1.23456789, 0.0d); + assertEquals(valueRead, 1.23456789, 0.0d); } /** @@ -53,7 +56,7 @@ public class DoubleConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Double valueRead = config.get("tests.converter.double.decimalNegative", Double.class); assertTrue(valueRead!=null); - assertEquals(valueRead.doubleValue(), -1.23456789, 0.0d); + assertEquals(valueRead, -1.23456789, 0.0d); } /** @@ -66,7 +69,7 @@ public class DoubleConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Double valueRead = config.get("tests.converter.double.integer", Double.class); assertTrue(valueRead!=null); - assertEquals(valueRead.doubleValue(),100d, 0.0d); + assertEquals(valueRead,100d, 0.0d); } /** @@ -79,7 +82,7 @@ public class DoubleConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Double valueRead = config.get("tests.converter.double.hex1", Double.class); assertTrue(valueRead!=null); - assertEquals(valueRead.doubleValue(),255d, 0.0d); + assertEquals(valueRead,255d, 0.0d); } /** @@ -92,7 +95,7 @@ public class DoubleConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Double valueRead = config.get("tests.converter.double.hex2", Double.class); assertTrue(valueRead!=null); - assertEquals(valueRead.doubleValue(),-255d, 0.0d); + assertEquals(valueRead,-255d, 0.0d); } /** @@ -117,7 +120,7 @@ public class DoubleConverterTest { 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); + assertEquals(Double.MIN_VALUE, valueRead,0.0d); } /** @@ -130,7 +133,7 @@ public class DoubleConverterTest { 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); + assertEquals(Double.MAX_VALUE, valueRead,0.0d); } /** @@ -143,7 +146,7 @@ public class DoubleConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Double valueRead = config.get("tests.converter.double.nan", Double.class); assertTrue(valueRead!=null); - assertEquals(Double.NaN, valueRead.doubleValue(),0.0d); + assertEquals(Double.NaN, valueRead,0.0d); } /** @@ -156,7 +159,7 @@ public class DoubleConverterTest { 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); + assertEquals(Double.POSITIVE_INFINITY, valueRead,0.0d); } /** @@ -169,7 +172,31 @@ public class DoubleConverterTest { 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); + assertEquals(Double.NEGATIVE_INFINITY, valueRead,0.0d); + } + + + @Test(expected = ConfigException.class) + public void testConvert_DoubleInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + config.get("tests.converter.double.invalid", Double.class); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Double.class)).build(); + DoubleConverter converter = new DoubleConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<double> (DoubleConverter)")); + assertTrue(context.getSupportedFormats().contains("MIN_VALUE (DoubleConverter)")); + assertTrue(context.getSupportedFormats().contains("MAX_VALUE (DoubleConverter)")); + } + + @Test + public void testHashCode() { + DoubleConverter instance = new DoubleConverter(); + assertEquals(DoubleConverter.class.hashCode(), instance.hashCode()); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java index 8a37c0f..a799135 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DurationConverterTest.java @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.time.Duration; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -76,4 +77,19 @@ public class DurationConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(Duration.class)).build(); + DurationConverter converter = new DurationConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().contains("PT20M34S (DurationConverter)")); + } + + @Test + public void testHashCode() { + DurationConverter instance = new DurationConverter(); + assertEquals(DurationConverter.class.hashCode(), instance.hashCode()); + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FileConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FileConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FileConverterTest.java new file mode 100644 index 0000000..41e372d --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FileConverterTest.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 java.io.File; +import java.net.URL; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author William.Lieurance 2018-02-01 + */ +public class FileConverterTest { + + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(File.class)).build(); + /** + * Test of convert method, of class FileConverter. + */ + @Test + public void testConvert() { + + FileConverter instance = new FileConverter(); + File result; + + assertNull(instance.convert(null, context)); + + URL testfileUrl = getClass().getResource("/testfile.properties"); + System.out.println(testfileUrl.toString()); + result = instance.convert(testfileUrl.toString(), context); + assertNotNull(result); + assertTrue(context.getSupportedFormats().contains("<File> (FileConverter)")); + } + + @Test + public void testHashCode(){ + FileConverter instance = new FileConverter(); + assertEquals(FileConverter.class.hashCode(), instance.hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java index 98ea720..59e3c55 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java @@ -18,11 +18,14 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import static org.junit.Assert.assertEquals; import org.junit.Test; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -40,7 +43,7 @@ public class FloatConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Float valueRead = config.get("tests.converter.float.decimal", Float.class); assertTrue(valueRead!=null); - assertEquals(valueRead.floatValue(), 1.23456789f, 0.0f); + assertEquals(valueRead, 1.23456789f, 0.0f); } /** @@ -53,7 +56,7 @@ public class FloatConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Float valueRead = config.get("tests.converter.float.decimalNegative", Float.class); assertTrue(valueRead!=null); - assertEquals(valueRead.floatValue(), -1.23456789f, 0.0f); + assertEquals(valueRead, -1.23456789f, 0.0f); } /** @@ -66,7 +69,7 @@ public class FloatConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Float valueRead = config.get("tests.converter.float.integer", Float.class); assertTrue(valueRead!=null); - assertEquals(valueRead.floatValue(),100f, 0.0f); + assertEquals(valueRead,100f, 0.0f); } /** @@ -79,7 +82,7 @@ public class FloatConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Float valueRead = config.get("tests.converter.float.hex1", Float.class); assertTrue(valueRead!=null); - assertEquals(valueRead.floatValue(),255f, 0.0f); + assertEquals(valueRead,255f, 0.0f); } /** @@ -92,7 +95,7 @@ public class FloatConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Float valueRead = config.get("tests.converter.float.hex2", Float.class); assertTrue(valueRead!=null); - assertEquals(valueRead.floatValue(),-255f, 0.0f); + assertEquals(valueRead,-255f, 0.0f); } /** @@ -105,7 +108,7 @@ public class FloatConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Float valueRead = config.get("tests.converter.float.hex3", Float.class); assertTrue(valueRead!=null); - assertEquals(valueRead.floatValue(),255f, 0.0f); + assertEquals(valueRead,255f, 0.0f); } /** @@ -118,7 +121,7 @@ public class FloatConverterTest { 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); + assertEquals(Float.MIN_VALUE, valueRead,0.0f); } /** @@ -131,7 +134,7 @@ public class FloatConverterTest { 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); + assertEquals(Float.MAX_VALUE, valueRead,0.0f); } /** @@ -144,7 +147,7 @@ public class FloatConverterTest { Configuration config = ConfigurationProvider.getConfiguration(); Float valueRead = config.get("tests.converter.float.nan", Float.class); assertTrue(valueRead!=null); - assertEquals(Float.NaN, valueRead.floatValue(),0.0f); + assertEquals(Float.NaN, valueRead,0.0f); } /** @@ -157,7 +160,7 @@ public class FloatConverterTest { 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); + assertEquals(Float.POSITIVE_INFINITY, valueRead,0.0f); } /** @@ -170,7 +173,31 @@ public class FloatConverterTest { 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); + assertEquals(Float.NEGATIVE_INFINITY, valueRead,0.0f); + } + + @Test(expected = ConfigException.class) + public void testConvert_FloatInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + config.get("tests.converter.float.invalid", Float.class); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Float.class)).build(); + FloatConverter converter = new FloatConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<float> (FloatConverter)")); + assertTrue(context.getSupportedFormats().contains("MIN_VALUE (FloatConverter)")); + assertTrue(context.getSupportedFormats().contains("MAX_VALUE (FloatConverter)")); + } + + @Test + public void testHashCode() { + FloatConverter instance = new FloatConverter(); + assertEquals(FloatConverter.class.hashCode(), instance.hashCode()); } + } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java index 4a9a828..e3b543d 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/InstantConverterTest.java @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.time.Instant; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -54,4 +55,19 @@ public class InstantConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(Instant.class)).build(); + InstantConverter converter = new InstantConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().toString().contains(" (InstantConverter)")); + } + + @Test + public void testHashCode() { + InstantConverter instance = new InstantConverter(); + assertEquals(InstantConverter.class.hashCode(), instance.hashCode()); + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java index 03b0f12..9e8e0af 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java @@ -18,8 +18,11 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.junit.Test; import static org.junit.Assert.*; @@ -108,4 +111,27 @@ public class IntegerConverterTest { assertTrue(valueRead != null); assertEquals(Integer.MAX_VALUE, valueRead.intValue()); } + + @Test(expected = ConfigException.class) + public void testConvert_IntegerInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + config.get("tests.converter.integer.invalid", Integer.class); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Integer.class)).build(); + IntegerConverter converter = new IntegerConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<int> (IntegerConverter)")); + assertTrue(context.getSupportedFormats().contains("MIN_VALUE (IntegerConverter)")); + assertTrue(context.getSupportedFormats().contains("MAX_VALUE (IntegerConverter)")); + } + + @Test + public void testHashCode() { + IntegerConverter instance = new IntegerConverter(); + assertEquals(IntegerConverter.class.hashCode(), instance.hashCode()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java index 752699d..8d7cc0b 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateConverterTest.java @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.time.LocalDate; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -54,4 +55,18 @@ public class LocalDateConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(LocalDate.class)).build(); + LocalDateConverter converter = new LocalDateConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().toString().contains(" (LocalDateConverter)")); + } + + @Test + public void testHashCode() { + LocalDateConverter instance = new LocalDateConverter(); + assertEquals(LocalDateConverter.class.hashCode(), instance.hashCode()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java index 945682a..c3355bb 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverterTest.java @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.time.LocalDateTime; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -54,4 +55,18 @@ public class LocalDateTimeConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(LocalDateTime.class)).build(); + LocalDateTimeConverter converter = new LocalDateTimeConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().toString().contains(" (LocalDateTimeConverter)")); + } + + @Test + public void testHashCode() { + LocalDateTimeConverter instance = new LocalDateTimeConverter(); + assertEquals(LocalDateTimeConverter.class.hashCode(), instance.hashCode()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java index b75ed7b..b8d2b84 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LocalTimeConverterTest.java @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.time.LocalTime; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -54,4 +55,18 @@ public class LocalTimeConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(LocalTime.class)).build(); + LocalTimeConverter converter = new LocalTimeConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().toString().contains(" (LocalTimeConverter)")); + } + + @Test + public void testHashCode() { + LocalTimeConverter instance = new LocalTimeConverter(); + assertEquals(LocalTimeConverter.class.hashCode(), instance.hashCode()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java index 0df6b09..bb228e6 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java @@ -18,8 +18,11 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.junit.Test; import static org.junit.Assert.*; @@ -107,5 +110,28 @@ public class LongConverterTest { Long valueRead = config.get("tests.converter.long.max", Long.class); assertTrue(valueRead != null); assertEquals(Long.MAX_VALUE, valueRead.longValue()); + } + + @Test(expected = ConfigException.class) + public void testConvert_LongInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + config.get("tests.converter.long.invalid", Long.class); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Long.class)).build(); + LongConverter converter = new LongConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<long> (LongConverter)")); + assertTrue(context.getSupportedFormats().contains("MIN_VALUE (LongConverter)")); + assertTrue(context.getSupportedFormats().contains("MAX_VALUE (LongConverter)")); + } + + @Test + public void testHashCode() { + LongConverter instance = new LongConverter(); + assertEquals(LongConverter.class.hashCode(), instance.hashCode()); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java index 3fa2e58..6131157 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java @@ -23,6 +23,9 @@ import org.apache.tamaya.ConfigurationProvider; import org.junit.Test; import java.math.BigDecimal; +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import static org.junit.Assert.*; @@ -40,7 +43,7 @@ public class NumberConverterTest { public void testConvert_Decimal() throws Exception { Configuration config = ConfigurationProvider.getConfiguration(); Number valueRead = config.get("tests.converter.bd.decimal", Number.class); - assertTrue(valueRead!=null); + assertNotNull(valueRead); assertEquals(valueRead, 101L); } @@ -54,10 +57,10 @@ public class NumberConverterTest { public void testConvert_Hex() throws Exception { Configuration config = ConfigurationProvider.getConfiguration(); Number valueRead = config.get("tests.converter.bd.hex.lowerX", Number.class); - assertTrue(valueRead!=null); + assertNotNull(valueRead); assertEquals(valueRead, Long.valueOf("47")); valueRead = config.get("tests.converter.bd.hex.upperX", Number.class); - assertTrue(valueRead!=null); + assertNotNull(valueRead); assertEquals(valueRead, Long.valueOf("63")); } @@ -70,7 +73,7 @@ public class NumberConverterTest { public void testConvert_NotPresent() throws Exception { Configuration config = ConfigurationProvider.getConfiguration(); Number valueRead = config.get("tests.converter.bd.foo", Number.class); - assertFalse(valueRead!=null); + assertNull(valueRead); } /** @@ -82,7 +85,7 @@ public class NumberConverterTest { public void testConvert_BigValue() throws Exception { Configuration config = ConfigurationProvider.getConfiguration(); Number valueRead = config.get("tests.converter.bd.big", Number.class); - assertTrue(valueRead!=null); + assertNotNull(valueRead); assertEquals(new BigDecimal("101666666666666662333337263723628763821638923628193612983618293628763"), valueRead); } @@ -96,8 +99,71 @@ public class NumberConverterTest { public void testConvert_BigFloatValue() throws Exception { Configuration config = ConfigurationProvider.getConfiguration(); Number valueRead = config.get("tests.converter.bd.bigFloat", Number.class); - assertTrue(valueRead!=null); + assertNotNull(valueRead); assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" + "63723628763821638923628193612983618293628763"), valueRead); } + + /** + * Test conversion. The value are provided by + * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}. + * @throws Exception + */ + @Test + public void testConvert_PositiveInfinityValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.double.pi", Number.class); + assertNotNull(valueRead); + 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_NegativeInfinityValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.double.ni", Number.class); + assertNotNull(valueRead); + assertEquals(Double.NEGATIVE_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_NaNValue() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Number valueRead = config.get("tests.converter.double.nan", Number.class); + assertNotNull(valueRead); + assertEquals(Double.NaN, valueRead.doubleValue(),0.0d); + } + + @Test(expected = ConfigException.class) + public void testConvert_NumberInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + config.get("tests.converter.bd.invalid", Number.class); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Number.class)).build(); + NumberConverter converter = new NumberConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("<double>, <long> (NumberConverter)")); + assertTrue(context.getSupportedFormats().contains("POSITIVE_INFINITY (NumberConverter)")); + assertTrue(context.getSupportedFormats().contains("NEGATIVE_INFINITY (NumberConverter)")); + assertTrue(context.getSupportedFormats().contains("NAN (NumberConverter)")); + } + + @Test + public void testHashCode() { + NumberConverter instance = new NumberConverter(); + assertEquals(NumberConverter.class.hashCode(), instance.hashCode()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java index 4ab65a2..fa747be 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetDateTimeConverterTest.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.core.internal.converters; +import java.time.LocalDate; import org.apache.tamaya.spi.ConversionContext; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,6 +26,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.time.OffsetDateTime; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -54,4 +56,18 @@ public class OffsetDateTimeConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(OffsetDateTime.class)).build(); + OffsetDateTimeConverter converter = new OffsetDateTimeConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().toString().contains(" (OffsetDateTimeConverter)")); + } + + @Test + public void testHashCode() { + OffsetDateTimeConverter instance = new OffsetDateTimeConverter(); + assertEquals(OffsetDateTimeConverter.class.hashCode(), instance.hashCode()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java index 3b28b2c..2bf85c9 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OffsetTimeConverterTest.java @@ -25,6 +25,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.time.OffsetTime; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -33,6 +34,7 @@ import static org.junit.Assert.*; */ @RunWith(MockitoJUnitRunner.class) public class OffsetTimeConverterTest { + @Mock ConversionContext context; @@ -53,4 +55,18 @@ public class OffsetTimeConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } -} \ No newline at end of file + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(OffsetTime.class)).build(); + OffsetTimeConverter converter = new OffsetTimeConverter(); + converter.convert("", localcontext); + + assertTrue(localcontext.getSupportedFormats().toString().contains(" (OffsetTimeConverter)")); + } + + @Test + public void testHashCode() { + OffsetTimeConverter instance = new OffsetTimeConverter(); + assertEquals(OffsetTimeConverter.class.hashCode(), instance.hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java index f35280b..3bcb7b1 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/OptionalConverterTest.java @@ -18,20 +18,23 @@ */ package org.apache.tamaya.core.internal.converters; +import java.util.List; import org.apache.tamaya.ConfigException; import org.junit.Test; import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; +import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import static org.junit.Assert.*; public class OptionalConverterTest { @Test public void nullConversionYieldsEmptyOptional() { final Optional<?> result = new OptionalConverter().convert(null, null); - assertThat(result).isNotNull(); - assertThat(result.isPresent()).isFalse(); + assertNotNull(result); + assertFalse(result.isPresent()); } @Test(expected = ConfigException.class) @@ -39,4 +42,36 @@ public class OptionalConverterTest { new OptionalConverter().convert("JustATestValueThatIsIgnored", null); } + @Test + public void testOptionalString() { + TypeLiteral<List<String>> listOfStringTypeLiteral = new TypeLiteral<List<String>>() { + }; + ConversionContext ctx = new ConversionContext.Builder("testOptionalString", listOfStringTypeLiteral).build(); + + final Optional<String> result = new OptionalConverter().convert("astring", ctx); + assertNotNull(result); + assertTrue(result.isPresent()); + assertEquals("astring", result.get()); + } + + @Test + public void testOptionalInteger() { + TypeLiteral<List<Integer>> listOfIntegerTypeLiteral = new TypeLiteral<List<Integer>>() { + }; + ConversionContext ctx = new ConversionContext.Builder("testOptionalInteger", listOfIntegerTypeLiteral) + .setConfiguration(ConfigurationProvider.getConfiguration()) + .build(); + + final Optional<Integer> result = new OptionalConverter().convert("11", ctx); + assertNotNull(result); + assertTrue(result.isPresent()); + assertEquals(11, result.get().intValue()); + } + + + @Test + public void testHashCode() { + OptionalConverter instance = new OptionalConverter(); + assertEquals(OptionalConverter.class.hashCode(), instance.hashCode()); + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java index a7f9eab..534a643 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/PathConverterTest.java @@ -26,6 +26,7 @@ import org.mockito.runners.MockitoJUnitRunner; import java.nio.file.Path; import java.nio.file.Paths; +import org.apache.tamaya.TypeLiteral; import static org.junit.Assert.*; @@ -48,6 +49,22 @@ public class PathConverterTest { } @Test + public void convertNull() throws Exception { + PathConverter conv = new PathConverter(); + Path value = conv.convert(null, context); + assertNull(value); + value = conv.convert("", context); + assertNull(value); + } + + @Test + public void convertInvalidPath() throws Exception { + PathConverter conv = new PathConverter(); + Path value = conv.convert("/invalid:/\u0000", context); + assertNull(value); + } + + @Test public void equalsAndHashcode() throws Exception { PathConverter conv1 = new PathConverter(); PathConverter conv2 = new PathConverter(); @@ -55,4 +72,18 @@ public class PathConverterTest { assertEquals(conv1.hashCode(), conv2.hashCode()); } -} \ No newline at end of file + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(Path.class)).build(); + PathConverter converter = new PathConverter(); + converter.convert("notempty", localcontext); + assertTrue(localcontext.getSupportedFormats().contains("<File> (PathConverter)")); + } + + @Test + public void testHashCode() { + PathConverter instance = new PathConverter(); + assertEquals(PathConverter.class.hashCode(), instance.hashCode()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java index ca9228d..4ee8ada 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java @@ -18,8 +18,11 @@ */ package org.apache.tamaya.core.internal.converters; +import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.junit.Test; import static org.junit.Assert.*; @@ -108,4 +111,28 @@ public class ShortConverterTest { assertTrue(valueRead != null); assertEquals(Short.MAX_VALUE, valueRead.intValue()); } + + + @Test(expected = ConfigException.class) + public void testConvert_ShortInvalid() throws ConfigException { + Configuration config = ConfigurationProvider.getConfiguration(); + config.get("tests.converter.short.invalid", Short.class); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Short.class)).build(); + ShortConverter converter = new ShortConverter(); + converter.convert("", context); + + assertTrue(context.getSupportedFormats().contains("short (ShortConverter)")); + assertTrue(context.getSupportedFormats().contains("MIN_VALUE (ShortConverter)")); + assertTrue(context.getSupportedFormats().contains("MAX_VALUE (ShortConverter)")); + } + + @Test + public void testHashCode() { + ShortConverter instance = new ShortConverter(); + assertEquals(ShortConverter.class.hashCode(), instance.hashCode()); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/SupplierConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/SupplierConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/SupplierConverterTest.java new file mode 100644 index 0000000..b14a506 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/SupplierConverterTest.java @@ -0,0 +1,84 @@ +/* + * 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 java.net.InetAddress; +import java.util.List; +import java.util.function.Supplier; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; +import org.junit.Test; +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import org.mockito.Mockito; + +/** + * + * @author William.Lieurance 2018-02-01 + */ +public class SupplierConverterTest { + + /** + * Test of convert method, of class SupplierConverter. + */ + @Test + public void testConvert() { + SupplierConverter instance = new SupplierConverter(); + Supplier<String> stringResult; + TypeLiteral listStringTypeLiteral = new TypeLiteral<List<String>> () {}; + ConversionContext stringContext = new ConversionContext.Builder(listStringTypeLiteral).build(); + + stringResult = instance.convert(null, stringContext); + assertNull(stringResult.get()); + + stringResult = instance.convert("aString", stringContext); + assertEquals("aString", stringResult.get()); + + Supplier<InetAddress> addressResult; + + Configuration mockConfig = Mockito.mock(Configuration.class); + Mockito.when(mockConfig.query(any())).thenReturn(Mockito.mock(InetAddress.class)); + + TypeLiteral myConverterTypeLiteral = new TypeLiteral<MyConverter<InetAddress>> () {}; + ConversionContext myConverterContext = new ConversionContext.Builder(myConverterTypeLiteral) + .setConfiguration(mockConfig) + .build(); + + addressResult = instance.convert("someKey", myConverterContext); + assertTrue(addressResult.get() instanceof InetAddress); + +} + + @Test + public void testHashCode(){ + SupplierConverter instance = new SupplierConverter(); + assertEquals(SupplierConverter.class.hashCode(), instance.hashCode()); + } + + private class MyConverter<T extends InetAddress> implements PropertyConverter<InetAddress> { + + @Override + public InetAddress convert(String value, ConversionContext context) { + return Mockito.mock(InetAddress.class); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java index 10a5236..373b979 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java @@ -24,8 +24,12 @@ import org.junit.Test; import java.net.URI; +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Tests conversion of the {@link URI}-converter. @@ -65,4 +69,27 @@ public class URIConverterTest { assertNull(converter.convert("", context)); assertNull(converter.convert(null, context)); } + + @Test + public void testConvert_URIInvalid() throws ConfigException { + URIConverter converter = new URIConverter(); + assertNull(converter.convert("not a uri", context)); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(URI.class)).build(); + URIConverter converter = new URIConverter(); + converter.convert("test:path", localcontext); + + assertTrue(localcontext.getSupportedFormats().contains("<uri> -> new URI(uri) (URIConverter)")); + } + + @Test + public void testHashCode() { + URIConverter instance = new URIConverter(); + assertEquals(URIConverter.class.hashCode(), instance.hashCode()); + } + + } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java index 3b66a98..80e5bc9 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java @@ -25,8 +25,12 @@ import org.junit.Test; import java.net.URI; import java.net.URL; +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Tests conversion of the {@link URL}-converter. @@ -66,4 +70,25 @@ public class URLConverterTest { assertNull(converter.convert("", context)); assertNull(converter.convert(null, context)); } + + @Test + public void testConvert_URLInvalid() throws ConfigException { + URLConverter converter = new URLConverter(); + assertNull(converter.convert("not a url", context)); + } + + @Test + public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { + ConversionContext localcontext = new ConversionContext.Builder(TypeLiteral.of(URL.class)).build(); + URLConverter converter = new URLConverter(); + converter.convert("http://localhost", localcontext); + + assertTrue(localcontext.getSupportedFormats().contains("<URL> (URLConverter)")); + } + + @Test + public void testHashCode() { + URLConverter instance = new URLConverter(); + assertEquals(URLConverter.class.hashCode(), instance.hashCode()); + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/core/src/test/resources/mockbundle.service ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/mockbundle.service b/code/core/src/test/resources/mockbundle.service new file mode 100644 index 0000000..985c962 --- /dev/null +++ b/code/core/src/test/resources/mockbundle.service @@ -0,0 +1,18 @@ +# 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. +java.lang.String +java.lang.String # Has a comment http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/spi-support/pom.xml ---------------------------------------------------------------------- diff --git a/code/spi-support/pom.xml b/code/spi-support/pom.xml index 4135834..6c4f94d 100644 --- a/code/spi-support/pom.xml +++ b/code/spi-support/pom.xml @@ -63,19 +63,5 @@ under the License. </dependency> </dependencies> - <build> - <plugins> - <plugin> - <!-- - ! See https://issues.apache.org/jira/browse/TAMAYA-318 - !--> - <groupId>org.pitest</groupId> - <artifactId>pitest-maven</artifactId> - <configuration> - <skip>true</skip> - </configuration> - </plugin> - </plugins> - </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/125eed20/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java index 5f95859..7f3cd7a 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java @@ -18,6 +18,8 @@ */ package org.apache.tamaya.spisupport; +import java.util.Arrays; +import java.util.Iterator; import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource; import org.apache.tamaya.spisupport.propertysource.BuildablePropertySourceProvider; import org.junit.Test; @@ -28,12 +30,18 @@ public class BuildablePropertySourceProviderTest { @Test public void getPropertySources() throws Exception { - BuildablePropertySource ps = BuildablePropertySource.builder() + BuildablePropertySource ps1 = BuildablePropertySource.builder() .withName("test1").build(); + BuildablePropertySource ps2 = BuildablePropertySource.builder() + .withName("test2").build(); BuildablePropertySourceProvider prov = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps).build(); + .withPropertySourcs(ps1) + .withPropertySourcs(Arrays.asList(ps2)) + .build(); assertNotNull(prov); - assertEquals(prov.getPropertySources().iterator().next(), ps); + Iterator testable = prov.getPropertySources().iterator(); + assertEquals(testable.next(), ps1); + assertEquals(testable.next(), ps2); } @Test @@ -44,12 +52,16 @@ public class BuildablePropertySourceProviderTest { .withPropertySourcs(ps).build(); BuildablePropertySourceProvider prov2 = BuildablePropertySourceProvider.builder() .withPropertySourcs(ps).build(); - assertEquals(prov1, prov2); BuildablePropertySource ps2 = BuildablePropertySource.builder() - .withName("test12").build(); - prov2 = BuildablePropertySourceProvider.builder() + .withName("test2").build(); + BuildablePropertySourceProvider prov3 = BuildablePropertySourceProvider.builder() .withPropertySourcs(ps2).build(); - assertNotEquals(prov1, prov2); + + assertEquals(prov1, prov1); + assertEquals(prov1, prov2); + assertNotEquals(prov1, prov3); + assertNotEquals(prov1, null); + assertNotEquals(prov1, "aString"); } @Test
