-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple regression test unit test for #266
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
weaver/src/test/java/org/aspectj/weaver/bcel/ExtensibleURLClassLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"); | ||
} | ||
} | ||
} |