From 642ea4f1b6870f6604bf56269c4705d9da46444e Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Wed, 25 Sep 2024 02:57:46 +0200 Subject: [PATCH] Clean up. --- .../main/java/net/bytebuddy/build/Plugin.java | 56 ++++++++----------- .../bytebuddy/dynamic/ClassFileLocator.java | 18 +++--- .../build/PluginEngineDefaultOtherTest.java | 2 +- .../build/PluginEngineDefaultTest.java | 2 +- .../build/PluginEngineSourceInMemoryTest.java | 2 +- .../PluginEngineTargetForFolderTest.java | 3 +- .../PluginEngineTargetForJarFileTest.java | 3 +- .../build/PluginEngineTargetInMemoryTest.java | 9 +-- .../ClassFileLocatorForClassLoaderTest.java | 24 ++++---- ...torForClassLoaderWeaklyReferencedTest.java | 6 +- .../ClassFileLocatorForFolderTest.java | 4 +- .../ClassFileLocatorForJarFileTest.java | 4 +- .../ClassFileLocatorForModuleFileTest.java | 2 +- .../ClassFileLocatorForModuleTest.java | 6 +- .../dynamic/ClassFileLocatorForUrlTest.java | 2 +- .../dynamic/ClassFileLocatorSimpleTest.java | 2 +- .../dynamic/DynamicTypeDefaultTest.java | 2 +- .../ByteArrayClassLoaderChildFirstTest.java | 27 +++++---- .../loading/ByteArrayClassLoaderTest.java | 6 +- .../ClassInjectorUsingReflectionTest.java | 2 +- ...ackageTypeStrategyManifestReadingTest.java | 9 +-- 21 files changed, 91 insertions(+), 100 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/build/Plugin.java b/byte-buddy-dep/src/main/java/net/bytebuddy/build/Plugin.java index c9c1f61de3..e49193049b 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/build/Plugin.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/build/Plugin.java @@ -757,31 +757,21 @@ public Resolution resolve(int index, Class type) { */ interface Engine { - /** - * The class file extension. - */ - String CLASS_FILE_EXTENSION = ".class"; - /** * The module info class file. */ - String MODULE_INFO = "module-info" + CLASS_FILE_EXTENSION; + String MODULE_INFO = "module-info" + ClassFileLocator.CLASS_FILE_EXTENSION; /** * The package info class file. */ - String PACKAGE_INFO = "package-info" + CLASS_FILE_EXTENSION; + String PACKAGE_INFO = "package-info" + ClassFileLocator.CLASS_FILE_EXTENSION; /** * The name of the file that contains declares Byte Buddy plugins for discovery. */ String PLUGIN_FILE = "META-INF/net.bytebuddy/build.plugins"; - /** - * The prefix folder for {@code META-INF/versions/} which contains multi-release files. - */ - String META_INF_VERSIONS = "META-INF/versions/"; - /** * Defines a new Byte Buddy instance for usage for type creation. * @@ -3012,11 +3002,11 @@ public static Source ofTypes( ) { Map storage = new HashMap(); for (Map.Entry entry : binaryRepresentations.entrySet()) { - storage.put(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION, entry.getValue()); + storage.put(entry.getKey().getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION, entry.getValue()); } for (Map.Entry> versioned : versionedBinaryRepresentations.entrySet()) { for (Map.Entry entry : versioned.getValue().entrySet()) { - storage.put(META_INF_VERSIONS + versioned.getKey().getJavaVersion() + "/" + entry.getKey().getInternalName() + CLASS_FILE_EXTENSION, entry.getValue()); + storage.put(ClassFileLocator.META_INF_VERSIONS + versioned.getKey().getJavaVersion() + "/" + entry.getKey().getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION, entry.getValue()); } } return new InMemory(storage); @@ -3386,7 +3376,7 @@ public ForJarOutputStream(JarOutputStream outputStream) { */ public void store(Map binaryRepresentations) throws IOException { for (Map.Entry entry : binaryRepresentations.entrySet()) { - outputStream.putNextEntry(new JarEntry(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION)); + outputStream.putNextEntry(new JarEntry(entry.getKey().getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION)); outputStream.write(entry.getValue()); outputStream.closeEntry(); } @@ -3397,7 +3387,7 @@ public void store(Map binaryRepresentations) throws IOE */ public void store(int version, Map binaryRepresentations) throws IOException { for (Map.Entry entry : binaryRepresentations.entrySet()) { - outputStream.putNextEntry(new JarEntry(META_INF_VERSIONS + version + "/" + entry.getKey().getInternalName() + CLASS_FILE_EXTENSION)); + outputStream.putNextEntry(new JarEntry(ClassFileLocator.META_INF_VERSIONS + version + "/" + entry.getKey().getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION)); outputStream.write(entry.getValue()); outputStream.closeEntry(); } @@ -3526,7 +3516,7 @@ public Sink write(@MaybeNull Manifest manifest) throws IOException { */ public void store(Map binaryRepresentations) { for (Map.Entry entry : binaryRepresentations.entrySet()) { - storage.put(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION, entry.getValue()); + storage.put(entry.getKey().getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION, entry.getValue()); } } @@ -3535,7 +3525,7 @@ public void store(Map binaryRepresentations) { */ public void store(int version, Map binaryRepresentations) throws IOException { for (Map.Entry entry : binaryRepresentations.entrySet()) { - storage.put(META_INF_VERSIONS + version + "/" + entry.getKey().getInternalName() + CLASS_FILE_EXTENSION, entry.getValue()); + storage.put(ClassFileLocator.META_INF_VERSIONS + version + "/" + entry.getKey().getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION, entry.getValue()); } } @@ -3588,9 +3578,9 @@ public Map getStorage() { public Map toTypeMap() { Map binaryRepresentations = new HashMap(); for (Map.Entry entry : storage.entrySet()) { - if (entry.getKey().endsWith(CLASS_FILE_EXTENSION) && !entry.getKey().startsWith(META_INF_VERSIONS)) { + if (entry.getKey().endsWith(ClassFileLocator.CLASS_FILE_EXTENSION) && !entry.getKey().startsWith(ClassFileLocator.META_INF_VERSIONS)) { binaryRepresentations.put(entry.getKey() - .substring(0, entry.getKey().length() - CLASS_FILE_EXTENSION.length()) + .substring(0, entry.getKey().length() - ClassFileLocator.CLASS_FILE_EXTENSION.length()) .replace('/', '.'), entry.getValue()); } } @@ -3607,13 +3597,13 @@ public Map toTypeMap(ClassFileVersion classFileVersion) { Map binaryRepresentations = new HashMap(); Map versions = new HashMap(); for (Map.Entry entry : storage.entrySet()) { - if (entry.getKey().endsWith(CLASS_FILE_EXTENSION)) { + if (entry.getKey().endsWith(ClassFileLocator.CLASS_FILE_EXTENSION)) { String suffix; int version; - if (entry.getKey().startsWith(META_INF_VERSIONS)) { - suffix = entry.getKey().substring(entry.getKey().indexOf('/', META_INF_VERSIONS.length()) + 1); + if (entry.getKey().startsWith(ClassFileLocator.META_INF_VERSIONS)) { + suffix = entry.getKey().substring(entry.getKey().indexOf('/', ClassFileLocator.META_INF_VERSIONS.length()) + 1); try { - int candidate = Integer.parseInt(entry.getKey().substring(META_INF_VERSIONS.length(), entry.getKey().indexOf('/', META_INF_VERSIONS.length()))); + int candidate = Integer.parseInt(entry.getKey().substring(ClassFileLocator.META_INF_VERSIONS.length(), entry.getKey().indexOf('/', ClassFileLocator.META_INF_VERSIONS.length()))); if (candidate < 7 || candidate > classFileVersion.getJavaVersion()) { continue; } @@ -3629,7 +3619,7 @@ public Map toTypeMap(ClassFileVersion classFileVersion) { if (current == null || current < version) { versions.put(suffix, version); binaryRepresentations.put(suffix - .substring(0, suffix.length() - CLASS_FILE_EXTENSION.length()) + .substring(0, suffix.length() - ClassFileLocator.CLASS_FILE_EXTENSION.length()) .replace('/', '.'), entry.getValue()); } } @@ -3667,7 +3657,7 @@ public ForFolder(File folder) { */ private static void doStore(File folder, Map binaryRepresentations) throws IOException { for (Map.Entry entry : binaryRepresentations.entrySet()) { - File target = new File(folder, entry.getKey().getInternalName() + CLASS_FILE_EXTENSION); + File target = new File(folder, entry.getKey().getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION); if (!target.getParentFile().isDirectory() && !target.getParentFile().mkdirs()) { throw new IOException("Could not create directory: " + target.getParent()); } @@ -3710,7 +3700,7 @@ public void store(Map binaryRepresentations) throws IOE * {@inheritDoc} */ public void store(int version, Map binaryRepresentations) throws IOException { - doStore(new File(folder, META_INF_VERSIONS + version), binaryRepresentations); + doStore(new File(folder, ClassFileLocator.META_INF_VERSIONS + version), binaryRepresentations); } /** @@ -4894,14 +4884,14 @@ public Summary apply(Source source, Target target, List enumeration = jarFile.entries(); while (enumeration.hasMoreElements()) { String name = enumeration.nextElement().getName(); - if (name.endsWith(CLASS_FILE_EXTENSION) && name.startsWith(MultiReleaseAware.MULTI_RELEASE_PREFIX)) { + if (name.endsWith(CLASS_FILE_EXTENSION) && name.startsWith(META_INF_VERSIONS)) { try { - int candidate = Integer.parseInt(name.substring(MultiReleaseAware.MULTI_RELEASE_PREFIX.length(), name.indexOf('/', MultiReleaseAware.MULTI_RELEASE_PREFIX.length()))); + int candidate = Integer.parseInt(name.substring(META_INF_VERSIONS.length(), name.indexOf('/', META_INF_VERSIONS.length()))); if (candidate > 7 && candidate <= classFileVersion.getJavaVersion()) { versions.add(candidate); } @@ -1255,7 +1255,7 @@ public static ClassFileLocator of(File folder, ClassFileVersion classFileVersion } int[] version; if (multiRelease) { - File[] file = new File(folder, MultiReleaseAware.MULTI_RELEASE_PREFIX).listFiles(); + File[] file = new File(folder, META_INF_VERSIONS).listFiles(); if (file != null) { SortedSet versions = new TreeSet(); for (int index = 0; index < file.length; index++) { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultOtherTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultOtherTest.java index af2ba0fb98..30cf3a8f37 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultOtherTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultOtherTest.java @@ -61,7 +61,7 @@ public void testMissingDependency() throws IOException { PluginEngineDefaultOtherTest.class, TypeWithDependency.class, TypeWithoutDependency.class}) { - outputStream.putNextEntry(new JarEntry(type.getName().replace(".", "/") + ".class")); + outputStream.putNextEntry(new JarEntry(type.getName().replace(".", "/") + ClassFileLocator.CLASS_FILE_EXTENSION)); outputStream.write(ClassFileLocator.ForClassLoader.read(type)); outputStream.closeEntry(); } diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultTest.java index 571f67dda0..73b256b7f1 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineDefaultTest.java @@ -281,7 +281,7 @@ public void testUnresolved() throws Exception { ? new SimplePlugin() : new PreprocessingPlugin(new SimplePlugin()); Plugin.Engine.Source source = new Plugin.Engine.Source.InMemory(Collections.singletonMap( - Sample.class.getName().replace('.', '/') + ".class", + Sample.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION, ClassFileLocator.ForClassLoader.read(Sample.class))) { @Override public ClassFileLocator toClassFileLocator(ClassFileVersion classFileVersion) { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineSourceInMemoryTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineSourceInMemoryTest.java index a2fb7980ee..51fc369b53 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineSourceInMemoryTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineSourceInMemoryTest.java @@ -47,7 +47,7 @@ public void testOfTypes() throws Exception { Iterator iterator = origin.iterator(); assertThat(iterator.hasNext(), is(true)); Plugin.Engine.Source.Element element = iterator.next(); - assertThat(element.getName(), is(Foo.class.getName().replace('.', '/') + ".class")); + assertThat(element.getName(), is(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION)); assertThat(element.resolveAs(Object.class), nullValue(Object.class)); assertThat(StreamDrainer.DEFAULT.drain(element.getInputStream()), is(ClassFileLocator.ForClassLoader.read(Foo.class))); assertThat(iterator.hasNext(), is(false)); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForFolderTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForFolderTest.java index 60fee7d78b..2c0380897c 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForFolderTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForFolderTest.java @@ -1,6 +1,7 @@ package net.bytebuddy.build; import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.test.utility.JavaVersionRule; import net.bytebuddy.utility.StreamDrainer; import org.junit.Before; @@ -45,7 +46,7 @@ public void testWriteType() throws Exception { } finally { sink.close(); } - File file = new File(folder, TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ".class"); + File file = new File(folder, TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION); assertThat(file.isFile(), is(true)); InputStream inputStream = new FileInputStream(file); try { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForJarFileTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForJarFileTest.java index 9595d017f2..33d5a0ba45 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForJarFileTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetForJarFileTest.java @@ -1,6 +1,7 @@ package net.bytebuddy.build; import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.utility.StreamDrainer; import org.junit.Before; import org.junit.Rule; @@ -50,7 +51,7 @@ public void testWriteType() throws Exception { try { assertThat(inputStream.getManifest(), nullValue(Manifest.class)); JarEntry entry = inputStream.getNextJarEntry(); - assertThat(entry.getName(), is(TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ".class")); + assertThat(entry.getName(), is(TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION)); assertThat(StreamDrainer.DEFAULT.drain(inputStream), is(new byte[]{1, 2, 3})); assertThat(inputStream.getNextJarEntry(), nullValue(JarEntry.class)); } finally { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetInMemoryTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetInMemoryTest.java index 60187cbc41..6cc33591f6 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetInMemoryTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineTargetInMemoryTest.java @@ -2,6 +2,7 @@ import net.bytebuddy.ClassFileVersion; import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.ClassFileLocator; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -25,7 +26,7 @@ public void testWriteType() throws Exception { sink.store(Collections.singletonMap(TypeDescription.ForLoadedType.of(Object.class), new byte[]{1, 2, 3})); sink.close(); assertThat(target.getStorage().size(), is(1)); - assertThat(target.getStorage().get(TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ".class"), is(new byte[]{1, 2, 3})); + assertThat(target.getStorage().get(TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION), is(new byte[]{1, 2, 3})); assertThat(target.toTypeMap().size(), is(1)); assertThat(target.toTypeMap().get(TypeDescription.ForLoadedType.of(Object.class).getName()), is(new byte[]{1, 2, 3})); } @@ -78,9 +79,9 @@ public void testMultiVersion() throws Exception { sink.store(17, Collections.singletonMap(TypeDescription.ForLoadedType.of(Object.class), new byte[]{7, 8, 9})); sink.close(); assertThat(target.getStorage().size(), is(3)); - assertThat(target.getStorage().get(TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ".class"), is(new byte[]{1, 2, 3})); - assertThat(target.getStorage().get(Plugin.Engine.META_INF_VERSIONS + "11/" + TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ".class"), is(new byte[]{4, 5, 6})); - assertThat(target.getStorage().get(Plugin.Engine.META_INF_VERSIONS + "17/" + TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ".class"), is(new byte[]{7, 8, 9})); + assertThat(target.getStorage().get(TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION), is(new byte[]{1, 2, 3})); + assertThat(target.getStorage().get(ClassFileLocator.META_INF_VERSIONS + "11/" + TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION), is(new byte[]{4, 5, 6})); + assertThat(target.getStorage().get(ClassFileLocator.META_INF_VERSIONS + "17/" + TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ClassFileLocator.CLASS_FILE_EXTENSION), is(new byte[]{7, 8, 9})); assertThat(target.toTypeMap().size(), is(1)); assertThat(target.toTypeMap().get(TypeDescription.ForLoadedType.of(Object.class).getName()), is(new byte[]{1, 2, 3})); assertThat(target.toTypeMap(ClassFileVersion.JAVA_V11).size(), is(1)); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderTest.java index ad1464a77e..69b7f6830d 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderTest.java @@ -41,12 +41,12 @@ public void testCreation() throws Exception { @Test public void testLocatable() throws Exception { ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[]{1, 2, 3}); - when(classLoader.getResourceAsStream(FOOBAR + ".class")).thenReturn(inputStream); + when(classLoader.getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION)).thenReturn(inputStream); ClassFileLocator.Resolution resolution = new ClassFileLocator.ForClassLoader(classLoader) .locate(FOOBAR); assertThat(resolution.isResolved(), is(true)); assertThat(resolution.resolve(), is(new byte[]{1, 2, 3})); - verify(classLoader).getResourceAsStream(FOOBAR + ".class"); + verify(classLoader).getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION); verifyNoMoreInteractions(classLoader); } @@ -55,7 +55,7 @@ public void testNonLocatable() throws Exception { ClassFileLocator.Resolution resolution = new ClassFileLocator.ForClassLoader(classLoader) .locate(FOOBAR); assertThat(resolution.isResolved(), is(false)); - verify(classLoader).getResourceAsStream(FOOBAR + ".class"); + verify(classLoader).getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION); verifyNoMoreInteractions(classLoader); resolution.resolve(); fail(); @@ -66,8 +66,8 @@ public void testReadTypeBootstrapClassLoader() throws Exception { byte[] binaryRepresentation = ClassFileLocator.ForClassLoader.read(Object.class); JavaModule module = JavaModule.ofType(Object.class); InputStream inputStream = module == null - ? Object.class.getResourceAsStream(Object.class.getSimpleName() + ".class") - : module.getResourceAsStream(Object.class.getName().replace('.', '/') + ".class"); + ? Object.class.getResourceAsStream(Object.class.getSimpleName() + ClassFileLocator.CLASS_FILE_EXTENSION) + : module.getResourceAsStream(Object.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(binaryRepresentation, is(StreamDrainer.DEFAULT.drain(inputStream))); } finally { @@ -78,7 +78,7 @@ public void testReadTypeBootstrapClassLoader() throws Exception { @Test public void testReadTypeNonBootstrapClassLoader() throws Exception { byte[] binaryRepresentation = ClassFileLocator.ForClassLoader.read(Foo.class); - InputStream inputStream = getClass().getClassLoader().getResourceAsStream(Foo.class.getName().replace('.', '/') + ".class"); + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(binaryRepresentation, is(StreamDrainer.DEFAULT.drain(inputStream))); } finally { @@ -99,14 +99,14 @@ public void testReadTypesMultiple() throws Exception { assertThat(binaryRepresentations.size(), is(2)); JavaModule module = JavaModule.ofType(Object.class); InputStream objectStream = module == null - ? Object.class.getResourceAsStream(Object.class.getSimpleName() + ".class") - : module.getResourceAsStream(Object.class.getName().replace('.', '/') + ".class"); + ? Object.class.getResourceAsStream(Object.class.getSimpleName() + ClassFileLocator.CLASS_FILE_EXTENSION) + : module.getResourceAsStream(Object.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(binaryRepresentations.get(Object.class), is(StreamDrainer.DEFAULT.drain(objectStream))); } finally { objectStream.close(); } - InputStream fooStream = getClass().getClassLoader().getResourceAsStream(Foo.class.getName().replace('.', '/') + ".class"); + InputStream fooStream = getClass().getClassLoader().getResourceAsStream(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(binaryRepresentations.get(Foo.class), is(StreamDrainer.DEFAULT.drain(fooStream))); } finally { @@ -120,14 +120,14 @@ public void testReadTypesToNames() throws Exception { assertThat(binaryRepresentations.size(), is(2)); JavaModule module = JavaModule.ofType(Object.class); InputStream objectStream = module == null - ? Object.class.getResourceAsStream(Object.class.getSimpleName() + ".class") - : module.getResourceAsStream(Object.class.getName().replace('.', '/') + ".class"); + ? Object.class.getResourceAsStream(Object.class.getSimpleName() + ClassFileLocator.CLASS_FILE_EXTENSION) + : module.getResourceAsStream(Object.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(binaryRepresentations.get(Object.class.getName()), is(StreamDrainer.DEFAULT.drain(objectStream))); } finally { objectStream.close(); } - InputStream fooStream = getClass().getClassLoader().getResourceAsStream(Foo.class.getName().replace('.', '/') + ".class"); + InputStream fooStream = getClass().getClassLoader().getResourceAsStream(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(binaryRepresentations.get(Foo.class.getName()), is(StreamDrainer.DEFAULT.drain(fooStream))); } finally { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderWeaklyReferencedTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderWeaklyReferencedTest.java index e8122cc04a..c5db20076d 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderWeaklyReferencedTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForClassLoaderWeaklyReferencedTest.java @@ -36,11 +36,11 @@ public void testCreation() throws Exception { @Test public void testLocatable() throws Exception { ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[]{1, 2, 3}); - when(classLoader.getResourceAsStream(FOOBAR + ".class")).thenReturn(inputStream); + when(classLoader.getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION)).thenReturn(inputStream); ClassFileLocator.Resolution resolution = new ClassFileLocator.ForClassLoader.WeaklyReferenced(classLoader).locate(FOOBAR); assertThat(resolution.isResolved(), is(true)); assertThat(resolution.resolve(), is(new byte[]{1, 2, 3})); - verify(classLoader).getResourceAsStream(FOOBAR + ".class"); + verify(classLoader).getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION); verifyNoMoreInteractions(classLoader); } @@ -48,7 +48,7 @@ public void testLocatable() throws Exception { public void testNonLocatable() throws Exception { ClassFileLocator.Resolution resolution = new ClassFileLocator.ForClassLoader.WeaklyReferenced(classLoader).locate(FOOBAR); assertThat(resolution.isResolved(), is(false)); - verify(classLoader).getResourceAsStream(FOOBAR + ".class"); + verify(classLoader).getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION); verifyNoMoreInteractions(classLoader); resolution.resolve(); fail(); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForFolderTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForFolderTest.java index d31febb5fb..69279c864d 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForFolderTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForFolderTest.java @@ -38,7 +38,7 @@ public void setUp() throws Exception { public void testSuccessfulLocation() throws Exception { File packageFolder = new File(folder, FOO); assertThat(packageFolder.mkdir(), is(true)); - File file = new File(packageFolder, BAR + ".class"); + File file = new File(packageFolder, BAR + ClassFileLocator.CLASS_FILE_EXTENSION); assertThat(file.createNewFile(), is(true)); FileOutputStream fileOutputStream = new FileOutputStream(file); try { @@ -80,7 +80,7 @@ public void testMultiReleaseVersionLocation() throws Exception { } File packageFolder = new File(metaInf, "versions/11/" + FOO); assertThat(packageFolder.mkdirs(), is(true)); - File file = new File(packageFolder, BAR + ".class"); + File file = new File(packageFolder, BAR + ClassFileLocator.CLASS_FILE_EXTENSION); assertThat(file.createNewFile(), is(true)); outputStream = new FileOutputStream(file); try { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForJarFileTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForJarFileTest.java index ac6b4394f7..5700bea490 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForJarFileTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForJarFileTest.java @@ -44,7 +44,7 @@ public void setUp() throws Exception { public void testSuccessfulLocation() throws Exception { JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(file)); try { - JarEntry jarEntry = new JarEntry(FOO + "/" + BAR + ".class"); + JarEntry jarEntry = new JarEntry(FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION); jarOutputStream.putNextEntry(jarEntry); jarOutputStream.write(VALUE); jarOutputStream.write(VALUE * 2); @@ -129,7 +129,7 @@ public void testMultiReleaseVersionLocation() throws Exception { manifest.getMainAttributes().putValue("Multi-Release", "true"); JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(file), manifest); try { - jarOutputStream.putNextEntry(new JarEntry("META-INF/versions/11/" + FOO + "/" + BAR + ".class")); + jarOutputStream.putNextEntry(new JarEntry("META-INF/versions/11/" + FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION)); jarOutputStream.write(VALUE); jarOutputStream.write(VALUE * 2); jarOutputStream.closeEntry(); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleFileTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleFileTest.java index b9a72b9345..5017b39083 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleFileTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleFileTest.java @@ -41,7 +41,7 @@ public void setUp() throws Exception { public void testSuccessfulLocation() throws Exception { ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(file)); try { - ZipEntry zipEntry = new ZipEntry("classes/" + FOO + "/" + BAR + ".class"); + ZipEntry zipEntry = new ZipEntry("classes/" + FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION); zipOutputStream.putNextEntry(zipEntry); zipOutputStream.write(VALUE); zipOutputStream.write(VALUE * 2); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleTest.java index 676e279cc0..8dc2beea3b 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForModuleTest.java @@ -54,12 +54,12 @@ public void testCreationUnnamed() throws Exception { @Test public void testLocatable() throws Exception { ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[]{1, 2, 3}); - when(module.getResourceAsStream(FOOBAR + ".class")).thenReturn(inputStream); + when(module.getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION)).thenReturn(inputStream); ClassFileLocator.Resolution resolution = new ClassFileLocator.ForModule(module) .locate(FOOBAR); assertThat(resolution.isResolved(), is(true)); assertThat(resolution.resolve(), is(new byte[]{1, 2, 3})); - verify(module).getResourceAsStream(FOOBAR + ".class"); + verify(module).getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION); verifyNoMoreInteractions(module); } @@ -68,7 +68,7 @@ public void testNonLocatable() throws Exception { ClassFileLocator.Resolution resolution = new ClassFileLocator.ForModule(module) .locate(FOOBAR); assertThat(resolution.isResolved(), is(false)); - verify(module).getResourceAsStream(FOOBAR + ".class"); + verify(module).getResourceAsStream(FOOBAR + ClassFileLocator.CLASS_FILE_EXTENSION); verifyNoMoreInteractions(module); resolution.resolve(); fail(); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForUrlTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForUrlTest.java index 82c1e347ae..48d45601e0 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForUrlTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorForUrlTest.java @@ -43,7 +43,7 @@ public void setUp() throws Exception { public void testSuccessfulLocation() throws Exception { JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(file)); try { - JarEntry jarEntry = new JarEntry(FOO + "/" + BAR + ".class"); + JarEntry jarEntry = new JarEntry(FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION); jarOutputStream.putNextEntry(jarEntry); jarOutputStream.write(VALUE); jarOutputStream.write(VALUE * 2); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorSimpleTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorSimpleTest.java index 0100a484e8..3b7531f677 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorSimpleTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/ClassFileLocatorSimpleTest.java @@ -49,7 +49,7 @@ public void testDynamicType() throws Exception { @Test public void testOfResources() throws Exception { ClassFileLocator.Resolution resolution = ClassFileLocator.Simple - .ofResources(Collections.singletonMap(FOO + "/" + BAR + ".class", QUX)) + .ofResources(Collections.singletonMap(FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION, QUX)) .locate(FOO + "." + BAR); assertThat(resolution.isResolved(), is(true)); assertThat(resolution.resolve(), is(QUX)); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/DynamicTypeDefaultTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/DynamicTypeDefaultTest.java index 658b4ccf45..3380ed3496 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/DynamicTypeDefaultTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/DynamicTypeDefaultTest.java @@ -28,7 +28,7 @@ public class DynamicTypeDefaultTest { - private static final String CLASS_FILE_EXTENSION = ".class"; + private static final String CLASS_FILE_EXTENSION = ClassFileLocator.CLASS_FILE_EXTENSION; private static final String FOOBAR = "foo/bar", QUXBAZ = "qux/baz", BARBAZ = "bar/baz", FOO = "foo", BAR = "bar"; diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderChildFirstTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderChildFirstTest.java index 6bcb38a973..152897aac1 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderChildFirstTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderChildFirstTest.java @@ -7,6 +7,7 @@ import net.bytebuddy.description.field.FieldList; import net.bytebuddy.description.method.MethodList; import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.implementation.Implementation; import net.bytebuddy.pool.TypePool; import net.bytebuddy.utility.OpenedClassReader; @@ -38,9 +39,7 @@ @RunWith(Parameterized.class) public class ByteArrayClassLoaderChildFirstTest { - private static final String BAR = "bar", CLASS_FILE = ".class"; - - private static final ProtectionDomain DEFAULT_PROTECTION_DOMAIN = null; + private static final String BAR = "bar"; private final ByteArrayClassLoader.PersistenceHandler persistenceHandler; @@ -75,7 +74,7 @@ public void setUp() throws Exception { .visit(new RenamingWrapper(Bar.class.getName().replace('.', '/'), Foo.class.getName().replace('.', '/'))) .make() .getBytes()), - DEFAULT_PROTECTION_DOMAIN, + ClassLoadingStrategy.NO_PROTECTION_DOMAIN, persistenceHandler, PackageDefinitionStrategy.NoOp.INSTANCE); } @@ -95,7 +94,7 @@ public void testLoading() throws Exception { @Test public void testResourceStreamLookupBeforeLoading() throws Exception { - InputStream inputStream = classLoader.getResourceAsStream(Foo.class.getName().replace('.', '/') + CLASS_FILE); + InputStream inputStream = classLoader.getResourceAsStream(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(inputStream, expectedResourceLookup ? notNullValue(InputStream.class) : nullValue(InputStream.class)); } finally { @@ -108,7 +107,7 @@ public void testResourceStreamLookupBeforeLoading() throws Exception { @Test public void testResourceStreamLookupAfterLoading() throws Exception { assertThat(classLoader.loadClass(Foo.class.getName()).getClassLoader(), is(classLoader)); - InputStream inputStream = classLoader.getResourceAsStream(Foo.class.getName().replace('.', '/') + CLASS_FILE); + InputStream inputStream = classLoader.getResourceAsStream(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); try { assertThat(inputStream, expectedResourceLookup ? notNullValue(InputStream.class) : nullValue(InputStream.class)); } finally { @@ -120,7 +119,7 @@ public void testResourceStreamLookupAfterLoading() throws Exception { @Test public void testResourceLookupBeforeLoading() throws Exception { - assertThat(classLoader.getResource(Foo.class.getName().replace('.', '/') + CLASS_FILE), expectedResourceLookup + assertThat(classLoader.getResource(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION), expectedResourceLookup ? notNullValue(URL.class) : nullValue(URL.class)); } @@ -128,14 +127,14 @@ public void testResourceLookupBeforeLoading() throws Exception { @Test public void testResourceLookupAfterLoading() throws Exception { assertThat(classLoader.loadClass(Foo.class.getName()).getClassLoader(), is(classLoader)); - assertThat(classLoader.getResource(Foo.class.getName().replace('.', '/') + CLASS_FILE), expectedResourceLookup + assertThat(classLoader.getResource(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION), expectedResourceLookup ? notNullValue(URL.class) : nullValue(URL.class)); } @Test public void testResourcesLookupBeforeLoading() throws Exception { - Enumeration enumeration = classLoader.getResources(Foo.class.getName().replace('.', '/') + CLASS_FILE); + Enumeration enumeration = classLoader.getResources(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); assertThat(enumeration.hasMoreElements(), is(true)); assertThat(enumeration.nextElement(), notNullValue(URL.class)); assertThat(enumeration.hasMoreElements(), is(expectedResourceLookup)); @@ -148,7 +147,7 @@ public void testResourcesLookupBeforeLoading() throws Exception { @Test public void testResourcesLookupAfterLoading() throws Exception { assertThat(classLoader.loadClass(Foo.class.getName()).getClassLoader(), is(classLoader)); - Enumeration enumeration = classLoader.getResources(Foo.class.getName().replace('.', '/') + CLASS_FILE); + Enumeration enumeration = classLoader.getResources(Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); assertThat(enumeration.hasMoreElements(), is(true)); assertThat(enumeration.nextElement(), notNullValue(URL.class)); assertThat(enumeration.hasMoreElements(), is(expectedResourceLookup)); @@ -160,7 +159,7 @@ public void testResourcesLookupAfterLoading() throws Exception { @Test public void testResourceLookupWithPrefixBeforeLoading() throws Exception { - assertThat(classLoader.getResource("/" + Foo.class.getName().replace('.', '/') + CLASS_FILE), expectedResourceLookup + assertThat(classLoader.getResource("/" + Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION), expectedResourceLookup ? notNullValue(URL.class) : nullValue(URL.class)); } @@ -168,14 +167,14 @@ public void testResourceLookupWithPrefixBeforeLoading() throws Exception { @Test public void testResourceLookupWithPrefixAfterLoading() throws Exception { assertThat(classLoader.loadClass(Foo.class.getName()).getClassLoader(), is(classLoader)); - assertThat(classLoader.getResource("/" + Foo.class.getName().replace('.', '/') + CLASS_FILE), expectedResourceLookup + assertThat(classLoader.getResource("/" + Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION), expectedResourceLookup ? notNullValue(URL.class) : nullValue(URL.class)); } @Test public void testResourcesLookupWithPrefixBeforeLoading() throws Exception { - Enumeration enumeration = classLoader.getResources("/" + Foo.class.getName().replace('.', '/') + CLASS_FILE); + Enumeration enumeration = classLoader.getResources("/" + Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); assertThat(enumeration.hasMoreElements(), is(expectedResourceLookup)); if (expectedResourceLookup) { assertThat(enumeration.nextElement(), notNullValue(URL.class)); @@ -186,7 +185,7 @@ public void testResourcesLookupWithPrefixBeforeLoading() throws Exception { @Test public void testResourcesLookupWithPrefixAfterLoading() throws Exception { assertThat(classLoader.loadClass(Foo.class.getName()).getClassLoader(), is(classLoader)); - Enumeration enumeration = classLoader.getResources("/" + Foo.class.getName().replace('.', '/') + CLASS_FILE); + Enumeration enumeration = classLoader.getResources("/" + Foo.class.getName().replace('.', '/') + ClassFileLocator.CLASS_FILE_EXTENSION); assertThat(enumeration.hasMoreElements(), is(expectedResourceLookup)); if (expectedResourceLookup) { assertThat(enumeration.nextElement(), notNullValue(URL.class)); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderTest.java index 270da04246..00b3226d39 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoaderTest.java @@ -33,9 +33,7 @@ @RunWith(Parameterized.class) public class ByteArrayClassLoaderTest { - private static final ProtectionDomain DEFAULT_PROTECTION_DOMAIN = null; - - private static final String FOO = "foo", BAR = "bar", QUX = "qux", CLASS_FILE = ".class"; + private static final String FOO = "foo", BAR = "bar", QUX = "qux", CLASS_FILE = ClassFileLocator.CLASS_FILE_EXTENSION; private final ByteArrayClassLoader.PersistenceHandler persistenceHandler; @@ -75,7 +73,7 @@ public void setUp() throws Exception { classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, false, ClassFileLocator.ForClassLoader.readToNames(Foo.class), - DEFAULT_PROTECTION_DOMAIN, + ClassLoadingStrategy.NO_PROTECTION_DOMAIN, persistenceHandler, packageDefinitionStrategy, classFilePostProcessor); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ClassInjectorUsingReflectionTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ClassInjectorUsingReflectionTest.java index b05b7d8402..c3f98af2ad 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ClassInjectorUsingReflectionTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/ClassInjectorUsingReflectionTest.java @@ -243,7 +243,7 @@ protected Class findClass(String name) throws ClassNotFoundException { if (name.startsWith("net.bytebuddy.") || name.startsWith("org.objectweb.")) { InputStream inputStream = ClassInjectorUsingReflectionTest.class.getResourceAsStream("/" + name.replace('.', '/') - + ".class"); + + ClassFileLocator.CLASS_FILE_EXTENSION); if (inputStream != null) { try { try { diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/PackageTypeStrategyManifestReadingTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/PackageTypeStrategyManifestReadingTest.java index 56d9c54549..e2a7b1023e 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/PackageTypeStrategyManifestReadingTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/loading/PackageTypeStrategyManifestReadingTest.java @@ -1,5 +1,6 @@ package net.bytebuddy.dynamic.loading; +import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.test.utility.IntegrationRule; import net.bytebuddy.test.utility.JavaVersionRule; import org.junit.Before; @@ -209,7 +210,7 @@ public void testSealBaseLocatorForTypeResourceUrlUnknownUrl() throws Exception { @IntegrationRule.Enforce public void testSealBaseLocatorForTypeResourceUrlFileUrl() throws Exception { URL url = URI.create("file:/foo").toURL(); - when(classLoader.getResource(FOO + "/" + BAR + ".class")).thenReturn(url); + when(classLoader.getResource(FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION)).thenReturn(url); assertThat(new PackageDefinitionStrategy.ManifestReading.SealBaseLocator.ForTypeResourceUrl(sealBaseLocator) .findSealBase(classLoader, FOO + "." + BAR), is(url)); verifyNoMoreInteractions(sealBaseLocator); @@ -219,7 +220,7 @@ public void testSealBaseLocatorForTypeResourceUrlFileUrl() throws Exception { @IntegrationRule.Enforce public void testSealBaseLocatorForTypeResourceUrlJarUrl() throws Exception { URL url = URI.create("jar:file:/foo.jar!/bar").toURL(); - when(classLoader.getResource(FOO + "/" + BAR + ".class")).thenReturn(url); + when(classLoader.getResource(FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION)).thenReturn(url); assertThat(new PackageDefinitionStrategy.ManifestReading.SealBaseLocator.ForTypeResourceUrl(sealBaseLocator) .findSealBase(classLoader, FOO + "." + BAR), is(URI.create("file:/foo.jar").toURL())); verifyNoMoreInteractions(sealBaseLocator); @@ -230,7 +231,7 @@ public void testSealBaseLocatorForTypeResourceUrlJarUrl() throws Exception { @JavaVersionRule.Enforce(9) public void testSealBaseLocatorForTypeResourceUrlJavaRuntimeImageUrl() throws Exception { URL url = URI.create("jrt:/foo/bar").toURL(); - when(classLoader.getResource(FOO + "/" + BAR + ".class")).thenReturn(url); + when(classLoader.getResource(FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION)).thenReturn(url); assertThat(new PackageDefinitionStrategy.ManifestReading.SealBaseLocator.ForTypeResourceUrl(sealBaseLocator) .findSealBase(classLoader, FOO + "." + BAR), is(URI.create("jrt:/foo").toURL())); verifyNoMoreInteractions(sealBaseLocator); @@ -241,7 +242,7 @@ public void testSealBaseLocatorForTypeResourceUrlJavaRuntimeImageUrl() throws Ex @JavaVersionRule.Enforce(9) public void testSealBaseLocatorForTypeResourceUrlJavaRuntimeImageUrlRawModule() throws Exception { URL url = URI.create("jrt:/foo").toURL(); - when(classLoader.getResource(FOO + "/" + BAR + ".class")).thenReturn(url); + when(classLoader.getResource(FOO + "/" + BAR + ClassFileLocator.CLASS_FILE_EXTENSION)).thenReturn(url); assertThat(new PackageDefinitionStrategy.ManifestReading.SealBaseLocator.ForTypeResourceUrl(sealBaseLocator) .findSealBase(classLoader, FOO + "." + BAR), is(URI.create("jrt:/foo").toURL())); verifyNoMoreInteractions(sealBaseLocator);