diff options
author | mwebster <mwebster> | 2006-07-12 14:26:21 +0000 |
---|---|---|
committer | mwebster <mwebster> | 2006-07-12 14:26:21 +0000 |
commit | 928cb4a192b7f8acdfe706a35a6e329cc0dff13c (patch) | |
tree | e722194f1fa235b286e825c6d1aa5b7b499d1aa6 /loadtime/testsrc | |
parent | e22244ba499571a43caf518567cba3717e4b5ce3 (diff) | |
download | aspectj-928cb4a192b7f8acdfe706a35a6e329cc0dff13c.tar.gz aspectj-928cb4a192b7f8acdfe706a35a6e329cc0dff13c.zip |
Fix for Bug 150254 "Provide context for LTW verbose messages" (IWeavingContext.getId(), WeavingContextTest)
Diffstat (limited to 'loadtime/testsrc')
-rw-r--r-- | loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingContextTest.java | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingContextTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingContextTest.java new file mode 100644 index 000000000..7d5318219 --- /dev/null +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingContextTest.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.weaver.loadtime; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Enumeration; + +import junit.framework.TestCase; + +public class WeavingContextTest extends TestCase { + + private boolean called; + + public void testWeavingContext() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context); + } + + public void testGetResources() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader) { + + public Enumeration getResources(String name) throws IOException { + called = true; + return super.getResources(name); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context); + adaptor.initialize(null,null); + + assertTrue("IWeavingContext not called",called); + } + + public void testGetBundleIdFromURL() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getBundleIdFromURL(URL url) { + throw new UnsupportedOperationException(); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context); + try { + adaptor.initialize(null,null); + } + catch (UnsupportedOperationException ex) { + fail("IWeavingContect.getBundleIdFromURL() is deprecated"); + } + } + + public void testGetClassLoaderName() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getClassLoaderName () { + called = true; + return super.getClassLoaderName(); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context); + adaptor.initialize(null,null); + + assertTrue("IWeavingContext not called",called); + } + + public void testGetFile() throws IOException { + File file = new File("../loadtime/testdata"); + URL fileURL = file.getCanonicalFile().toURL(); + URLClassLoader loader = new URLClassLoader(new URL[] { fileURL },null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getFile (URL url) { + called = true; + return super.getFile(url); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context); + adaptor.initialize(null,null); + + assertTrue("IWeavingContext not called",called); + } + + public void testGetId() throws IOException { + File file = new File("../loadtime/testdata"); + URL fileURL = file.getCanonicalFile().toURL(); + URLClassLoader loader = new URLClassLoader(new URL[] { fileURL },null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getId () { + called = true; + return super.getId(); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context); + adaptor.initialize(null,null); + + assertTrue("IWeavingContext not called",called); + } + + private static class TestWeavingContext implements IWeavingContext { + + private ClassLoader loader; + + public TestWeavingContext (ClassLoader classLoader) { + this.loader = classLoader; + } + + public String getBundleIdFromURL(URL url) { + return null; + } + + public String getClassLoaderName() { + return "ClassLoaderName"; + } + + public String getFile(URL url) { + return "File"; + } + + public String getId() { + return "Id"; + } + + public Enumeration getResources(String name) throws IOException { + return loader.getResources(name); + } + + } + + protected void setUp() throws Exception { + super.setUp(); + + this.called = false; + } + +} |