This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push: new 5affcab Updated URLConverter (#50) 5affcab is described below commit 5affcabc199144ef33d9db4ecc347a39557a8f29 Author: Seth <s...@elypia.org> AuthorDate: Thu Dec 31 17:35:46 2020 +0100 Updated URLConverter (#50) * Updated URLConverter to use JUnit 4. Updated URLConverter to compare Strings instead of URLs. * Refactored URLConverterTestCase --- .../beanutils2/converters/ConverterTestSuite.java | 1 - .../converters/URLConverterTestCase.java | 98 +++++----------------- 2 files changed, 21 insertions(+), 78 deletions(-) diff --git a/src/test/java/org/apache/commons/beanutils2/converters/ConverterTestSuite.java b/src/test/java/org/apache/commons/beanutils2/converters/ConverterTestSuite.java index 82c0e22..6c89389 100644 --- a/src/test/java/org/apache/commons/beanutils2/converters/ConverterTestSuite.java +++ b/src/test/java/org/apache/commons/beanutils2/converters/ConverterTestSuite.java @@ -53,7 +53,6 @@ public class ConverterTestSuite { testSuite.addTestSuite(SqlDateConverterTestCase.class); testSuite.addTestSuite(SqlTimeConverterTestCase.class); testSuite.addTestSuite(SqlTimestampConverterTestCase.class); - testSuite.addTestSuite(URLConverterTestCase.class); return testSuite; } } diff --git a/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java index 502c8ba..251b544 100644 --- a/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java @@ -17,70 +17,29 @@ package org.apache.commons.beanutils2.converters; -import java.net.URL; - import org.apache.commons.beanutils2.ConversionException; -import org.apache.commons.beanutils2.Converter; +import org.junit.Before; +import org.junit.Test; + +import java.net.URL; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; /** * Test Case for the URLConverter class. - * */ +public class URLConverterTestCase { -public class URLConverterTestCase extends TestCase { - - public static TestSuite suite() { - return new TestSuite(URLConverterTestCase.class); - } - - - - private Converter converter = null; - - - - public URLConverterTestCase(final String name) { - super(name); - } - - protected Class<?> getExpectedType() { - return URL.class; - } + private URLConverter converter; - protected Converter makeConverter() { - return new URLConverter(); + @Before + public void before() { + converter = new URLConverter(); } - - - @Override - public void setUp() throws Exception { - converter = makeConverter(); - } - - @Override - public void tearDown() throws Exception { - converter = null; - } - - - + @Test public void testSimpleConversion() throws Exception { - final String[] message= { - "from String", - "from String", - "from String", - "from String", - "from String", - "from String", - "from String", - "from String", - }; - - final Object[] input = { + final String[] input = { "http://www.apache.org", "http://www.apache.org/", "ftp://cvs.apache.org", @@ -89,39 +48,24 @@ public class URLConverterTestCase extends TestCase { "http://www.apache.org:9999/test/thing", "http://user:ad...@www.apache.org:50/one/two.three", "http://notreal.apache.org", + "http://notreal.apache.org/test/file.xml#计算机图形学", + "http://notreal.apache.org/test/file.xml#%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9B%BE%E5%BD%A2%E5%AD%A6" }; - final URL[] expected = { - new URL("http://www.apache.org"), - new URL("http://www.apache.org/"), - new URL("ftp://cvs.apache.org"), - new URL("file://project.xml"), - new URL("http://208.185.179.12"), - new URL("http://www.apache.org:9999/test/thing"), - new URL("http://user:ad...@www.apache.org:50/one/two.three"), - new URL("http://notreal.apache.org") - }; + for (String urlString : input) { + assertEquals("from String to URL", urlString, converter.convert(URL.class, urlString).toString()); + assertEquals("from String to null type", urlString, converter.convert(null, urlString).toString()); - for(int i=0;i<expected.length;i++) { - assertEquals(message[i] + " to URL",expected[i],converter.convert(URL.class,input[i])); - assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i])); - } - - for(int i=0;i<expected.length;i++) { - assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i])); + URL url = new URL(urlString); + assertEquals(urlString + " to String", urlString, converter.convert(String.class, url)); } } /** * Tests a conversion to an unsupported type. */ + @Test(expected = ConversionException.class) public void testUnsupportedType() { - try { - converter.convert(Integer.class, "http://www.apache.org"); - fail("Unsupported type could be converted!"); - } catch (final ConversionException cex) { - // expected result - } + converter.convert(Integer.class, "http://www.apache.org"); } } -