Skip to content

Commit 331b232

Browse files
committed
Repair image-related Swing tests
Those tests reference the JDK-internal "JavaCup16.png" file, which is no longer accessible with Java 9. Instead, the test now create and use a local project file.
1 parent c144865 commit 331b232

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/AbstractJavaProjectTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,24 @@ public static IFile setFileContent(String path, String content) throws Exception
430430
}
431431

432432
/**
433-
* Creates/updates {@link IFile} with given folder/name, relative to "src" folder.
433+
* Creates/updates {@link IFile} with given path, relative to "src" folder.
434+
*/
435+
public static IFile setFileContentSrc(String path, byte[] content) throws Exception {
436+
return setFileContent("src/" + path, content);
437+
}
438+
439+
/**
440+
* Creates/updates {@link IFile} with given path, relative to {@link IProject}.
441+
*/
442+
public static IFile setFileContent(String path, byte[] content) throws Exception {
443+
IFile file = getFile(path);
444+
setFileContent(file, content);
445+
return file;
446+
}
447+
448+
/**
449+
* Creates/updates {@link IFile} with given folder/name, relative to "src"
450+
* folder.
434451
*
435452
* @return the created/updated {@link IFile}.
436453
*/

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/bean/ActionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc. and others.
2+
* Copyright (c) 2011, 2025 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
@@ -36,6 +36,7 @@
3636
import org.eclipse.wb.internal.swing.model.component.ContainerInfo;
3737
import org.eclipse.wb.internal.swing.model.component.JToolBarInfo;
3838
import org.eclipse.wb.internal.swing.palette.ActionUseEntryInfo;
39+
import org.eclipse.wb.tests.designer.TestUtils;
3940
import org.eclipse.wb.tests.designer.swing.SwingModelTest;
4041
import org.eclipse.wb.tests.designer.swing.SwingTestUtils;
4142

@@ -55,7 +56,6 @@
5556

5657
import org.assertj.core.api.Assertions;
5758
import org.assertj.core.util.Lists;
58-
import org.junit.jupiter.api.Disabled;
5959
import org.junit.jupiter.api.Test;
6060

6161
import java.util.ArrayList;
@@ -1594,18 +1594,18 @@ public void test_anonymous_properties_inConstructorArgument() throws Exception {
15941594
/**
15951595
* Test for {@link ActionInfo#getPresentation()}.
15961596
*/
1597-
@Disabled
15981597
@Test
15991598
public void test_presentation() throws Exception {
16001599
m_waitForAutoBuild = true;
1600+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
16011601
ContainerInfo panel =
16021602
parseContainer(
16031603
"public class Test extends JPanel {",
16041604
" private Action action_1 = new Action_1();",
16051605
" private Action action_2 = new Action_2();",
16061606
" private class Action_1 extends AbstractAction {",
16071607
" public Action_1() {",
1608-
" putValue(SMALL_ICON, new ImageIcon(Test.class.getResource('/javax/swing/plaf/basic/icons/JavaCup16.png')));",
1608+
" putValue(SMALL_ICON, new ImageIcon(Test.class.getResource('/Test.png')));",
16091609
" }",
16101610
" public void actionPerformed(ActionEvent e) {",
16111611
" }",

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/IconPropertyEditorTest.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2025 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
@@ -99,28 +99,30 @@ public void test_getText_fromFile_2() throws Exception {
9999

100100
@Test
101101
public void test_getText_Class_getResource_1() throws Exception {
102+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
102103
assertIconPropertyText(
103-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
104+
"Classpath: /Test.png",
104105
new String[]{
105106
"public class Test extends JPanel {",
106107
" public Test() {",
107108
" JButton button = new JButton();",
108-
" button.setIcon(new ImageIcon(Test.class.getResource(\"/javax/swing/plaf/basic/icons/JavaCup16.png\")));",
109+
" button.setIcon(new ImageIcon(Test.class.getResource(\"/Test.png\")));",
109110
" add(button);",
110111
" }",
111112
"}"});
112113
}
113114

114115
@Test
115116
public void test_getText_Class_getResource_2() throws Exception {
117+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
116118
assertIconPropertyText(
117-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
119+
"Classpath: /Test.png",
118120
new String[]{
119121
"public class Test extends JPanel {",
120122
" public Test() {",
121123
" JButton button = new JButton();",
122124
" button.setIcon("
123-
+ " new ImageIcon(Test.class.getResource(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"), "
125+
+ " new ImageIcon(Test.class.getResource(\"/Test.png\"), "
124126
+ " \"Some description\"));",
125127
" add(button);",
126128
" }",
@@ -129,13 +131,14 @@ public void test_getText_Class_getResource_2() throws Exception {
129131

130132
@Test
131133
public void test_getText_Class_getResource_3() throws Exception {
134+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
132135
assertIconPropertyText(
133-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
136+
"Classpath: /Test.png",
134137
new String[]{
135138
"public class Test extends JPanel {",
136139
" public Test() {",
137140
" JButton button = new JButton();",
138-
" Icon icon = new ImageIcon(Test.class.getResource(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"));",
141+
" Icon icon = new ImageIcon(Test.class.getResource(\"/Test.png\"));",
139142
" button.setIcon(icon);",
140143
" add(button);",
141144
" }",
@@ -144,13 +147,14 @@ public void test_getText_Class_getResource_3() throws Exception {
144147

145148
@Test
146149
public void test_getText_Class_getResource_4() throws Exception {
150+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
147151
assertIconPropertyText(
148-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
152+
"Classpath: /Test.png",
149153
new String[]{
150154
"public class Test extends JPanel {",
151155
" public Test() {",
152156
" JButton button = new JButton();",
153-
" java.net.URL url = Test.class.getResource(\"/javax/swing/plaf/basic/icons/JavaCup16.png\");",
157+
" java.net.URL url = Test.class.getResource(\"/Test.png\");",
154158
" Icon icon = new ImageIcon(url);",
155159
" button.setIcon(icon);",
156160
" add(button);",

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/property/ImagePropertyEditorTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2025 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
@@ -20,7 +20,6 @@
2020

2121
import org.eclipse.core.resources.IFile;
2222

23-
import org.junit.jupiter.api.Disabled;
2423
import org.junit.jupiter.api.Test;
2524

2625
/**
@@ -69,42 +68,42 @@ public void test_getText_fromFile() throws Exception {
6968
}
7069
}
7170

72-
@Disabled
7371
@Test
7472
public void test_getText_Class_getResource_1() throws Exception {
73+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
7574
assertImagePropertyText(
76-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
75+
"Classpath: /Test.png",
7776
new String[]{
7877
"public class Test extends JFrame {",
7978
" public Test() {",
80-
" setIconImage(Toolkit.getDefaultToolkit().getImage(Test.class.getResource(\"/javax/swing/plaf/basic/icons/JavaCup16.png\")));",
79+
" setIconImage(Toolkit.getDefaultToolkit().getImage(Test.class.getResource(\"/Test.png\")));",
8180
" }",
8281
"}"});
8382
}
8483

85-
@Disabled
8684
@Test
8785
public void test_getText_Class_getResource_2() throws Exception {
86+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
8887
assertImagePropertyText(
89-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
88+
"Classpath: /Test.png",
9089
new String[]{
9190
"public class Test extends JFrame {",
9291
" public Test() {",
93-
" Image icon = Toolkit.getDefaultToolkit().getImage(Test.class.getResource(\"/javax/swing/plaf/basic/icons/JavaCup16.png\"));",
92+
" Image icon = Toolkit.getDefaultToolkit().getImage(Test.class.getResource(\"/Test.png\"));",
9493
" setIconImage(icon);",
9594
" }",
9695
"}"});
9796
}
9897

99-
@Disabled
10098
@Test
10199
public void test_getText_Class_getResource_3() throws Exception {
100+
setFileContentSrc("Test.png", TestUtils.createImagePNG(1, 1));
102101
assertImagePropertyText(
103-
"Classpath: /javax/swing/plaf/basic/icons/JavaCup16.png",
102+
"Classpath: /Test.png",
104103
new String[]{
105104
"public class Test extends JFrame {",
106105
" public Test() {",
107-
" java.net.URL url = Test.class.getResource(\"/javax/swing/plaf/basic/icons/JavaCup16.png\");",
106+
" java.net.URL url = Test.class.getResource(\"/Test.png\");",
108107
" Image icon = Toolkit.getDefaultToolkit().getImage(url);",
109108
" setIconImage(icon);",
110109
" }",

0 commit comments

Comments
 (0)