From 9c7dd7d2fee08060558528c90b9cfcd579ccfc26 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Tue, 24 Sep 2024 23:58:01 +0200 Subject: [PATCH] Extend test. --- .../build/PluginEngineTargetInMemoryTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 81f07196a58..ebcec21a9a2 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 @@ -1,5 +1,6 @@ package net.bytebuddy.build; +import net.bytebuddy.ClassFileVersion; import net.bytebuddy.description.type.TypeDescription; import org.junit.Test; @@ -67,4 +68,31 @@ public void testIgnoreFolderElement() throws Exception { verify(element).getName(); verifyNoMoreInteractions(element); } + + @Test + public void testMultiVersion() throws Exception { + Plugin.Engine.Target.InMemory target = new Plugin.Engine.Target.InMemory(ClassFileVersion.JAVA_V11); + Plugin.Engine.Target.Sink sink = target.write(Plugin.Engine.Source.Origin.NO_MANIFEST); + sink.store(Collections.singletonMap(TypeDescription.ForLoadedType.of(Object.class), new byte[]{1, 2, 3})); + sink.store(11, Collections.singletonMap(TypeDescription.ForLoadedType.of(Object.class), new byte[]{4, 5, 6})); + sink.store(17, Collections.singletonMap(TypeDescription.ForLoadedType.of(Object.class), new byte[]{7, 8, 9})); + sink.close(); + assertThat(target.getStorage().size(), is(1)); + assertThat(target.getStorage().get(TypeDescription.ForLoadedType.of(Object.class).getInternalName() + ".class"), is(new byte[]{4, 5, 6})); + assertThat(target.toTypeMap().size(), is(1)); + assertThat(target.toTypeMap().get(TypeDescription.ForLoadedType.of(Object.class).getName()), is(new byte[]{4, 5, 6})); + } + + @Test + public void testNoMultiVersion() throws Exception { + Plugin.Engine.Target.InMemory target = new Plugin.Engine.Target.InMemory(); + Plugin.Engine.Target.Sink sink = target.write(Plugin.Engine.Source.Origin.NO_MANIFEST); + sink.store(Collections.singletonMap(TypeDescription.ForLoadedType.of(Object.class), new byte[]{1, 2, 3})); + sink.store(11, Collections.singletonMap(TypeDescription.ForLoadedType.of(Object.class), new byte[]{4, 5, 6})); + 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.toTypeMap().size(), is(1)); + assertThat(target.toTypeMap().get(TypeDescription.ForLoadedType.of(Object.class).getName()), is(new byte[]{1, 2, 3})); + } }