Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2015 IBM Corporation and others.
* Copyright (c) 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,19 +11,25 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.icu.text;
package org.eclipse.ant.core;

import java.io.Serializable;

/**
* Used by the
* {@link org.eclipse.core.internal.expressions.tests.ExpressionTestsPluginUnloading}
* test.
* <p>
* <strong>Note:</strong> This class uses the 'com.ibm.icu.text' namespace for
* test purposes only and does not copy or implement anything from ICU.
* <strong>Note:</strong> This class uses the 'org.eclipse.ant.core' namespace
* for test purposes only and does not copy or implement anything from the real
* AntRunner class.
* </p>
*/
public class DecimalFormat implements Runnable {
public class AntRunner implements Runnable, Serializable {
private static final long serialVersionUID = 1L;

@Override
public void run() {
// Empty implementation for testing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
/**
* Tests for cache used in {@link Expressions#isInstanceOf(Object, String)}.
* <p>
* <b>WARNING:</b> These tests start, stop, and re-start the <code>com.ibm.icu</code> bundle.
* <b>WARNING:</b> These tests start, stop, and re-start the <code>org.eclipse.ant.core</code> bundle.
* Don't include these in another test suite!
*/
@SuppressWarnings("restriction")
@TestMethodOrder(MethodOrderer.MethodName.class)
public class ExpressionTestsPluginUnloading {

private static final String ANT_CORE_BUNDLE_ID = "org.eclipse.ant.core";
private static final String ANT_RUNNER_CLASS_NAME = "org.eclipse.ant.core.AntRunner";

private String name;

@BeforeEach
Expand All @@ -49,13 +52,13 @@ public void setupTestName(TestInfo testInfo) {

@Test
public void test01PluginStopping() throws Exception {
Bundle bundle= getBundle("com.ibm.icu");
Bundle bundle= getBundle(ANT_CORE_BUNDLE_ID);
bundle.start();
int state = bundle.getState();
assertThat(state).withFailMessage("Unexpected bundle state: " + stateToString(state) + " for bundle " + bundle)
.isEqualTo(Bundle.ACTIVE);

doTestInstanceofICUDecimalFormat(bundle);
doTestInstanceofAntRunner(bundle);
assertThat(bundle.getState()).as("Instanceof with bundle-local class should load extra bundle")
.isEqualTo(state);

Expand All @@ -69,26 +72,26 @@ public void test01PluginStopping() throws Exception {
.withFailMessage("Unexpected bundle state: " + stateToString(state) + " for bundle " + bundle)
.isEqualTo(Bundle.ACTIVE);

doTestInstanceofICUDecimalFormat(bundle);
doTestInstanceofAntRunner(bundle);
}

@Test
public void test02MultipleClassloaders() throws Exception {
Bundle expr= getBundle("org.eclipse.core.expressions.tests");
Bundle icu= getBundle("com.ibm.icu");
Bundle ant= getBundle(ANT_CORE_BUNDLE_ID);

Class<?> exprClass = expr.loadClass("com.ibm.icu.text.DecimalFormat");
Class<?> icuClass = icu.loadClass("com.ibm.icu.text.DecimalFormat");
assertThat(exprClass).isNotSameAs(icuClass);
Class<?> exprClass = expr.loadClass(ANT_RUNNER_CLASS_NAME);
Class<?> antClass = ant.loadClass(ANT_RUNNER_CLASS_NAME);
assertThat(exprClass).isNotSameAs(antClass);

Object exprObj = exprClass.getDeclaredConstructor().newInstance();
Object icuObj = icuClass.getDeclaredConstructor().newInstance();
Object antObj = antClass.getDeclaredConstructor().newInstance();

assertInstanceOf(exprObj, "java.lang.Runnable", "java.lang.String");
assertInstanceOf(exprObj, "java.lang.Object", "java.io.Serializable");
assertInstanceOf(exprObj, "java.io.Serializable", "org.eclipse.equinox.app.IApplication");

assertInstanceOf(icuObj, "java.io.Serializable", "java.lang.String");
assertInstanceOf(icuObj, "java.text.Format", "java.lang.Runnable");
assertInstanceOf(antObj, "org.eclipse.equinox.app.IApplication", "java.lang.Runnable");
assertInstanceOf(antObj, "java.lang.Object", "java.io.Serializable");
}

static String stateToString(int state) {
Expand Down Expand Up @@ -125,10 +128,10 @@ private void assertInstanceOf(Object obj, String isInstance, String isNotInstanc
}
}

private void doTestInstanceofICUDecimalFormat(Bundle bundle) throws Exception {
Class<?> clazz = bundle.loadClass("com.ibm.icu.text.DecimalFormat");
Object decimalFormat = clazz.getDeclaredConstructor().newInstance();
assertInstanceOf(decimalFormat, "com.ibm.icu.text.DecimalFormat", "java.text.NumberFormat");
private void doTestInstanceofAntRunner(Bundle bundle) throws Exception {
Class<?> clazz = bundle.loadClass(ANT_RUNNER_CLASS_NAME);
Object antRunner = clazz.getDeclaredConstructor().newInstance();
assertInstanceOf(antRunner, ANT_RUNNER_CLASS_NAME, "java.lang.Runnable");
}

private static Bundle getBundle(String bundleName) {
Expand Down
Loading