diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2023-12-10 09:31:35 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2023-12-10 03:50:33 +0100 |
commit | 3ae6e989a4ee2c808452d0984811cfd963286fdd (patch) | |
tree | 1c78ffb1b8f50d5f62a105ccdd8366a48002c49b /weaver | |
parent | 6d72e7a60a64eb5c282ec39bcb5ba51ce1c7a471 (diff) | |
download | aspectj-3ae6e989a4ee2c808452d0984811cfd963286fdd.tar.gz aspectj-3ae6e989a4ee2c808452d0984811cfd963286fdd.zip |
Simple regression test unit test for #266
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java b/weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java new file mode 100644 index 000000000..6136363ae --- /dev/null +++ b/weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java @@ -0,0 +1,51 @@ +/* ******************************************************************* + * Copyright (c) 2023 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + * ******************************************************************/ +package org.aspectj.weaver.bcel; + +import junit.framework.TestCase; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +public class ExtensibleURLClassLoaderTest extends TestCase { + /** + * Simple regression test for <a href="https://github.com/eclipse-aspectj/aspectj/issues/266">GitHub issue 266</a> + */ + public void testClassNotFoundExceptionHasRootCauseOnIOException() throws URISyntaxException, MalformedURLException { + ExtensibleURLClassLoader extensibleURLClassLoader = new MockExtensibleURLClassLoader( + new URL[] { new URI("file://dummy").toURL() }, + null + ); + ClassNotFoundException classNotFoundException = null; + try { + extensibleURLClassLoader.findClass(getClass().getName().replace('.', '/')); + } catch (ClassNotFoundException e) { + classNotFoundException = e; + } + assertNotNull(classNotFoundException); + Throwable cause = classNotFoundException.getCause(); + assertNotNull(cause); + assertTrue(cause instanceof IOException); + assertEquals("uh-oh", cause.getMessage()); + } + + static class MockExtensibleURLClassLoader extends ExtensibleURLClassLoader { + public MockExtensibleURLClassLoader(URL[] urls, ClassLoader parent) { + super(urls, parent); + } + + @Override + protected byte[] getBytes(String name) throws IOException { + throw new IOException("uh-oh"); + } + } +} |