@GwtIncompatible // weak references private WeakReference<?> doTestClassUnloading() throws Exception { URLClassLoader shadowLoader = new URLClassLoader(getClassPathUrls(), null); @SuppressWarnings("unchecked") Class<TestEnum> shadowTestEnum = (Class<TestEnum>) Class.forName(TestEnum.class.getName(), false, shadowLoader); assertNotSame(shadowTestEnum, TestEnum.class); // We can't write Set<TestEnum> because that is a Set of the TestEnum from the original // ClassLoader. Set<Object> shadowConstants = new HashSet<>(); for (TestEnum constant : TestEnum.values()) { Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, constant.name()); assertThat(result).isPresent(); shadowConstants.add(result.get()); } assertEquals(ImmutableSet.<Object>copyOf(shadowTestEnum.getEnumConstants()), shadowConstants); Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, "blibby"); assertThat(result).isAbsent(); return new WeakReference<>(shadowLoader); }
@GwtIncompatible // weak references private WeakReference<?> doTestClassUnloading() throws Exception { URLClassLoader shadowLoader = new URLClassLoader(getClassPathUrls(), null); @SuppressWarnings("unchecked") Class<TestEnum> shadowTestEnum = (Class<TestEnum>) Class.forName(TestEnum.class.getName(), false, shadowLoader); assertNotSame(shadowTestEnum, TestEnum.class); // We can't write Set<TestEnum> because that is a Set of the TestEnum from the original // ClassLoader. Set<Object> shadowConstants = new HashSet<>(); for (TestEnum constant : TestEnum.values()) { Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, constant.name()); assertThat(result).isPresent(); shadowConstants.add(result.get()); } assertEquals(ImmutableSet.<Object>copyOf(shadowTestEnum.getEnumConstants()), shadowConstants); Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, "blibby"); assertThat(result).isAbsent(); return new WeakReference<>(shadowLoader); }