Skip to content

Commit ccda5c8

Browse files
committed
Cleanup and enable ResourceManager tests
With recent Java versions, JDK-internal JavaCup16.png is no longer in the classpath, which is why those tests were disabled. This image has to be replaced with a "test" image, similar to what was already done in the past with 331b232.
1 parent e0982b4 commit ccda5c8

6 files changed

Lines changed: 84 additions & 57 deletions

File tree

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/property/ImageDescriptorPropertyEditorTestNoManager.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2023 Google, Inc.
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -18,6 +18,7 @@
1818
import org.eclipse.wb.internal.rcp.ToolkitProvider;
1919
import org.eclipse.wb.internal.swt.model.property.editor.image.ImageDescriptorPropertyEditor;
2020
import org.eclipse.wb.internal.swt.preferences.IPreferenceConstants;
21+
import org.eclipse.wb.tests.designer.TestUtils;
2122
import org.eclipse.wb.tests.designer.tests.common.GenericPropertyNoValue;
2223

2324
import org.eclipse.jface.resource.ImageDescriptor;
@@ -106,10 +107,11 @@ public void test_textSource_absolutePath() throws Exception {
106107
*/
107108
@Test
108109
public void test_textSource_image_over_classpath() throws Exception {
110+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
109111
assert_getText_getClipboardSource_forSource(
110-
getInvocationSource("getClass()", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
111-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
112-
getInvocationSource("{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
112+
getInvocationSource("getClass()", "\"/Test.png\""),
113+
"Classpath: /Test.png",
114+
getInvocationSource("{wbp_classTop}", "\"/Test.png\""));
113115
}
114116

115117
/**
@@ -118,9 +120,10 @@ public void test_textSource_image_over_classpath() throws Exception {
118120
*/
119121
@Test
120122
public void test_textSource_image_over_classpath_OtherClass() throws Exception {
123+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
121124
assert_getText_getClipboardSource_forSource(
122-
getInvocationSource("String.class", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
123-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
124-
getInvocationSource("{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
125+
getInvocationSource("String.class", "\"/Test.png\""),
126+
"Classpath: /Test.png",
127+
getInvocationSource("{wbp_classTop}", "\"/Test.png\""));
125128
}
126129
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/property/ImageDescriptorPropertyEditorTestWithManager.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2023 Google, Inc.
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -18,6 +18,7 @@
1818
import org.eclipse.wb.internal.rcp.ToolkitProvider;
1919
import org.eclipse.wb.internal.swt.model.property.editor.image.ImageDescriptorPropertyEditor;
2020
import org.eclipse.wb.internal.swt.preferences.IPreferenceConstants;
21+
import org.eclipse.wb.tests.designer.TestUtils;
2122
import org.eclipse.wb.tests.designer.tests.common.GenericPropertyNoValue;
2223

2324
import org.eclipse.jface.resource.ImageDescriptor;
@@ -106,10 +107,11 @@ public void test_textSource_absolutePath() throws Exception {
106107
*/
107108
@Test
108109
public void test_textSource_image_over_classpath() throws Exception {
110+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
109111
assert_getText_getClipboardSource_forSource(
110-
getInvocationSource("getClass()", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
111-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
112-
getInvocationSource("{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
112+
getInvocationSource("getClass()", "\"/Test.png\""),
113+
"Classpath: /Test.png",
114+
getInvocationSource("{wbp_classTop}", "\"/Test.png\""));
113115
}
114116

115117
/**
@@ -118,10 +120,11 @@ public void test_textSource_image_over_classpath() throws Exception {
118120
*/
119121
@Test
120122
public void test_textSource_image_over_classpath_OtherClass() throws Exception {
123+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
121124
assert_getText_getClipboardSource_forSource(
122-
getInvocationSource("String.class", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
123-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
124-
getInvocationSource("{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
125+
getInvocationSource("String.class", "\"/Test.png\""),
126+
"Classpath: /Test.png",
127+
getInvocationSource("{wbp_classTop}", "\"/Test.png\""));
125128
}
126129

127130
////////////////////////////////////////////////////////////////////////////
@@ -151,10 +154,11 @@ public void test_textSource_absolutePath2() throws Exception {
151154
*/
152155
@Test
153156
public void test_textSource_image_over_classpath2() throws Exception {
157+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
154158
assert_getText_getClipboardSource_forSource(
155-
getInvocationSource("getClass()", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
156-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
157-
getInvocationSource("{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
159+
getInvocationSource("getClass()", "\"/Test.png\""),
160+
"Classpath: /Test.png",
161+
getInvocationSource("{wbp_classTop}", "\"/Test.png\""));
158162
}
159163

160164
/**
@@ -163,9 +167,10 @@ public void test_textSource_image_over_classpath2() throws Exception {
163167
*/
164168
@Test
165169
public void test_textSource_image_over_classpath_OtherClass2() throws Exception {
170+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
166171
assert_getText_getClipboardSource_forSource(
167-
getInvocationSource("String.class", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
168-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
169-
getInvocationSource("{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
172+
getInvocationSource("String.class", "\"/Test.png\""),
173+
"Classpath: /Test.png",
174+
getInvocationSource("{wbp_classTop}", "\"/Test.png\""));
170175
}
171176
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/property/ImagePropertyEditorTestNoManager.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2023 Google, Inc.
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -16,13 +16,13 @@
1616
import org.eclipse.wb.internal.rcp.ToolkitProvider;
1717
import org.eclipse.wb.internal.swt.model.property.editor.image.ImagePropertyEditor;
1818
import org.eclipse.wb.internal.swt.preferences.IPreferenceConstants;
19+
import org.eclipse.wb.tests.designer.TestUtils;
1920
import org.eclipse.wb.tests.designer.tests.common.GenericPropertyNoValue;
2021

2122
import org.eclipse.jface.resource.LocalResourceManager;
2223

2324
import org.apache.commons.io.FilenameUtils;
2425
import org.junit.jupiter.api.BeforeEach;
25-
import org.junit.jupiter.api.Disabled;
2626
import org.junit.jupiter.api.Test;
2727

2828
import java.io.File;
@@ -97,24 +97,29 @@ public void test_textSource_absolutePath() throws Exception {
9797
/**
9898
* Image creation using constructor with input stream (over class resource).
9999
*/
100-
@Disabled
101100
@Test
102101
public void test_textSource_image_over_classpath() throws Exception {
102+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
103103
assert_getText_getClipboardSource_forSource(
104-
"new Image(null, getClass().getResourceAsStream(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"))",
105-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
106-
"new org.eclipse.swt.graphics.Image(null, {wbp_classTop}.getResourceAsStream(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"))");
104+
"new Image(null, getClass().getResourceAsStream(\"/Test.png\"))",
105+
"Classpath: /Test.png",
106+
"new org.eclipse.swt.graphics.Image(null, {wbp_classTop}.getResourceAsStream(\"/Test.png\"))");
107107
}
108108

109109
/**
110110
* Image creation using constructor with input stream (over class resource).
111111
*/
112-
@Disabled
113112
@Test
114113
public void test_textSource_image_over_classpath_OtherClass() throws Exception {
114+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
115+
setFileContentSrc("test", "OtherClass.java", """
116+
package test;
117+
public class OtherClass {}
118+
""");
119+
waitForAutoBuild();
115120
assert_getText_getClipboardSource_forSource(
116-
"new Image(null, java.lang.String.class.getResourceAsStream(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"))",
117-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
118-
"new org.eclipse.swt.graphics.Image(null, {wbp_classTop}.getResourceAsStream(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"))");
121+
"new Image(null, OtherClass.class.getResourceAsStream(\"/Test.png\"))",
122+
"Classpath: /Test.png",
123+
"new org.eclipse.swt.graphics.Image(null, {wbp_classTop}.getResourceAsStream(\"/Test.png\"))");
119124
}
120125
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/property/ImagePropertyEditorTestWithManager.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
import org.eclipse.wb.internal.swt.model.property.editor.image.ImagePropertyEditor;
2121
import org.eclipse.wb.internal.swt.model.widgets.CompositeInfo;
2222
import org.eclipse.wb.internal.swt.preferences.IPreferenceConstants;
23+
import org.eclipse.wb.tests.designer.TestUtils;
2324
import org.eclipse.wb.tests.designer.tests.common.GenericPropertyNoValue;
2425

2526
import org.eclipse.jface.resource.LocalResourceManager;
2627

2728
import org.apache.commons.io.FilenameUtils;
2829
import org.junit.jupiter.api.BeforeEach;
29-
import org.junit.jupiter.api.Disabled;
3030
import org.junit.jupiter.api.Test;
3131

3232
import java.io.File;
@@ -103,25 +103,29 @@ public void test_textSource_absolutePath() throws Exception {
103103
/**
104104
* Image creation using constructor with input stream (over class resource).
105105
*/
106-
@Disabled
107106
@Test
108107
public void test_textSource_image_over_classpath() throws Exception {
108+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
109109
assert_getText_getClipboardSource_forSource(
110-
"new Image(null, getClass().getResourceAsStream(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"))",
111-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
112-
getInvocationSource(shell(), "{wbp_classTop}", "/javax/swing/plaf/basic/icons/JavaCup16.png"));
110+
"new Image(null, getClass().getResourceAsStream(\"/Test.png\"))",
111+
"Classpath: /Test.png",
112+
getInvocationSource(shell(), "{wbp_classTop}", "\"/Test.png\""));
113113
}
114114

115115
/**
116116
* Image creation using constructor with input stream (over class resource).
117117
*/
118-
@Disabled
119118
@Test
120119
public void test_textSource_image_over_classpath_OtherClass() throws Exception {
120+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
121+
setFileContentSrc("test", "OtherClass.java", """
122+
package test;
123+
public class OtherClass {}
124+
""");
121125
assert_getText_getClipboardSource_forSource(
122-
"new Image(null, java.lang.String.class.getResourceAsStream(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"))",
123-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
124-
getInvocationSource(shell(), "{wbp_classTop}", "/javax/swing/plaf/basic/icons/JavaCup16.png"));
126+
"new Image(null, OtherClass.class.getResourceAsStream(\"/Test.png\"))",
127+
"Classpath: /Test.png",
128+
getInvocationSource(shell(), "{wbp_classTop}", "\"/Test.png\""));
125129
}
126130

127131
////////////////////////////////////////////////////////////////////////////
@@ -152,23 +156,25 @@ public void test_textSource_absolutePath2() throws Exception {
152156
*/
153157
@Test
154158
public void test_textSource_image_over_classpath2() throws Exception {
159+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
155160
CompositeInfo shell = shell();
156161
assert_getText_getClipboardSource_forSource2(
157-
getInvocationSource(shell, "getClass()", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
158-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
159-
getInvocationSource(shell, "{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
162+
getInvocationSource(shell, "getClass()", "\"/Test.png\""),
163+
"Classpath: /Test.png",
164+
getInvocationSource(shell, "{wbp_classTop}", "\"/Test.png\""));
160165
}
161166

162167
/**
163168
* Image creation using constructor with input stream (over class resource).
164169
*/
165170
@Test
166171
public void test_textSource_image_over_classpath_OtherClass2() throws Exception {
172+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
167173
CompositeInfo shell = shell();
168174
assert_getText_getClipboardSource_forSource2(
169-
getInvocationSource(shell, "java.lang.String.class", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""),
170-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
171-
getInvocationSource(shell, "{wbp_classTop}", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
175+
getInvocationSource(shell, "java.lang.String.class", "\"/Test.png\""),
176+
"Classpath: /Test.png",
177+
getInvocationSource(shell, "{wbp_classTop}", "\"/Test.png\""));
172178
}
173179

174180
/**
@@ -201,6 +207,7 @@ public Test() {
201207
*/
202208
@Test
203209
public void test_textSource_order() throws Exception {
210+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
204211
CompositeInfo shell = parseComposite("""
205212
// filler filler filler
206213
public class Test extends Shell {
@@ -209,15 +216,15 @@ public Test() {
209216
}""");
210217
ManagerContainerInfo.getResourceManagerInfo(shell);
211218
shell.addMethodInvocation("setImage(org.eclipse.swt.graphics.Image)",
212-
getInvocationSource(shell, "java.lang.String.class", "\"/javax/swing/plaf/basic/icons/JavaCup16.png\""));
219+
getInvocationSource(shell, "java.lang.String.class", "\"/Test.png\""));
213220
shell.refresh();
214221
assertEditor("""
215222
// filler filler filler
216223
public class Test extends Shell {
217224
private LocalResourceManager localResourceManager;
218225
public Test() {
219226
createResourceManager();
220-
setImage(localResourceManager.create(ImageDescriptor.createFromFile(String.class, \"/javax/swing/plaf/basic/icons/JavaCup16.png\")));
227+
setImage(localResourceManager.create(ImageDescriptor.createFromFile(String.class, \"/Test.png\")));
221228
}
222229
private void createResourceManager() {
223230
localResourceManager = new LocalResourceManager(JFaceResources.getResources(),this);

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swt/model/property/ResourceManagerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
1616
import org.eclipse.wb.internal.swt.model.widgets.CompositeInfo;
1717
import org.eclipse.wb.internal.swt.utils.ManagerUtils;
18+
import org.eclipse.wb.tests.designer.TestUtils;
1819
import org.eclipse.wb.tests.designer.rcp.RcpModelTest;
1920

2021
import org.eclipse.swt.SWT;
@@ -95,13 +96,14 @@ public void _test_exit() throws Exception {
9596
////////////////////////////////////////////////////////////////////////////
9697
@Test
9798
public void test_getImageDescriptor() throws Exception {
99+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
98100
// create image descriptor
99101
Object imageDescriptor =
100102
ReflectionUtils.invokeMethod(
101103
ManagerClass,
102104
"getImageDescriptor(java.lang.Class,java.lang.String)",
103105
ManagerClass,
104-
"/javax/swing/plaf/basic/icons/JavaCup16.png");
106+
"/Test.png");
105107
// check create
106108
assertNotNull(imageDescriptor);
107109
}
@@ -119,13 +121,14 @@ public void test_getImage_null() throws Exception {
119121

120122
@Test
121123
public void test_getImage() throws Exception {
124+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
122125
// create image descriptor
123126
Object imageDescriptor =
124127
ReflectionUtils.invokeMethod(
125128
ImageDescriptorClass,
126129
"createFromFile(java.lang.Class,java.lang.String)",
127130
ManagerClass,
128-
"/javax/swing/plaf/basic/icons/JavaCup16.png");
131+
"/Test.png");
129132
// check create
130133
assertNotNull(imageDescriptor);
131134
//

0 commit comments

Comments
 (0)