Skip to content

Commit b21fef4

Browse files
committed
Migrate SWT Model Propert tests to use Text Blocks
1 parent e5e0a9d commit b21fef4

17 files changed

Lines changed: 737 additions & 791 deletions

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

Lines changed: 8 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, 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
@@ -52,14 +52,13 @@ public void tearDown() throws Exception {
5252
protected final void assert_getText_getClipboardSource_forSource(String colorSource,
5353
String expectedText,
5454
String expectedClipboardSource) throws Exception {
55-
CompositeInfo shell =
56-
parseComposite(
57-
"// filler filler filler",
58-
"public class Test extends Shell {",
59-
" public Test() {",
60-
" setBackground(" + colorSource + ");",
61-
" }",
62-
"}");
55+
CompositeInfo shell = parseComposite("""
56+
// filler filler filler
57+
public class Test extends Shell {
58+
public Test() {
59+
setBackground(%s);
60+
}
61+
}""".formatted(colorSource));
6362
shell.refresh();
6463
Property property = shell.getPropertyByTitle("background");
6564
assertEquals(expectedText, PropertyEditorTestUtils.getText(property));

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

Lines changed: 28 additions & 36 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
@@ -47,25 +47,21 @@ public void _test_exit() throws Exception {
4747
////////////////////////////////////////////////////////////////////////////
4848
@Test
4949
public void test_info() throws Exception {
50-
createASTCompilationUnit(
51-
"test",
52-
"MyRegistry.java",
53-
getTestSource(
54-
"public class MyRegistry extends ColorRegistry {",
55-
" public static final String R_KEY = '_r_key_';",
56-
" public MyRegistry() {",
57-
" put(R_KEY, new RGB(10, 10, 10));",
58-
" }",
59-
"}"));
50+
createASTCompilationUnit("test", "MyRegistry.java", getTestSource("""
51+
public class MyRegistry extends ColorRegistry {
52+
public static final String R_KEY = "_r_key_";
53+
public MyRegistry() {
54+
put(R_KEY, new RGB(10, 10, 10));
55+
}
56+
}"""));
6057
waitForAutoBuild();
6158
//
62-
CompositeInfo shell =
63-
parseComposite(
64-
"public class Test extends Shell {",
65-
" private MyRegistry registry = new MyRegistry();",
66-
" public Test() {",
67-
" }",
68-
"}");
59+
CompositeInfo shell = parseComposite("""
60+
public class Test extends Shell {
61+
private MyRegistry registry = new MyRegistry();
62+
public Test() {
63+
}
64+
}""");
6965
shell.refresh();
7066
//
7167
List<RegistryContainerInfo> children = shell.getChildren(RegistryContainerInfo.class);
@@ -89,26 +85,22 @@ public void test_info() throws Exception {
8985

9086
@Test
9187
public void test_value() throws Exception {
92-
createASTCompilationUnit(
93-
"test",
94-
"MyRegistry.java",
95-
getTestSource(
96-
"public class MyRegistry extends ColorRegistry {",
97-
" public static final String R_KEY = '_r_key_';",
98-
" public MyRegistry() {",
99-
" put(R_KEY, new RGB(10, 10, 10));",
100-
" }",
101-
"}"));
88+
createASTCompilationUnit("test", "MyRegistry.java", getTestSource("""
89+
public class MyRegistry extends ColorRegistry {
90+
public static final String R_KEY = "_r_key_";
91+
public MyRegistry() {
92+
put(R_KEY, new RGB(10, 10, 10));
93+
}
94+
}"""));
10295
waitForAutoBuild();
10396
//
104-
CompositeInfo shell =
105-
parseComposite(
106-
"public class Test extends Shell {",
107-
" private MyRegistry registry = new MyRegistry();",
108-
" public Test() {",
109-
" setBackground(registry.get(MyRegistry.R_KEY));",
110-
" }",
111-
"}");
97+
CompositeInfo shell = parseComposite("""
98+
public class Test extends Shell {
99+
private MyRegistry registry = new MyRegistry();
100+
public Test() {
101+
setBackground(registry.get(MyRegistry.R_KEY));
102+
}
103+
}""");
112104
shell.refresh();
113105
//
114106
Property property = shell.getPropertyByTitle("background");

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,27 @@ private CompositeInfo shell() throws Exception {
101101
*/
102102
@Test
103103
public void test_textSource_order() throws Exception {
104-
CompositeInfo shell = parseComposite(
105-
"// filler filler filler",
106-
"public class Test extends Shell {",
107-
" public Test() {",
108-
" }",
109-
"}");
104+
CompositeInfo shell = parseComposite("""
105+
// filler filler filler
106+
public class Test extends Shell {
107+
public Test() {
108+
}
109+
}""");
110110
ManagerContainerInfo.getResourceManagerInfo(shell);
111111
shell.addMethodInvocation("setBackground(org.eclipse.swt.graphics.Color)",
112112
ColorPropertyEditor.getInvocationSource(shell, 1, 2, 3));
113113
shell.refresh();
114-
assertEditor(
115-
"// filler filler filler",
116-
"public class Test extends Shell {",
117-
" private LocalResourceManager localResourceManager;",
118-
" public Test() {",
119-
" createResourceManager();",
120-
" setBackground(localResourceManager.create(ColorDescriptor.createFrom(new RGB(1, 2, 3))));",
121-
" }",
122-
" private void createResourceManager() {",
123-
" localResourceManager = new LocalResourceManager(JFaceResources.getResources(),this);",
124-
" }",
125-
"}");
114+
assertEditor("""
115+
// filler filler filler
116+
public class Test extends Shell {
117+
private LocalResourceManager localResourceManager;
118+
public Test() {
119+
createResourceManager();
120+
setBackground(localResourceManager.create(ColorDescriptor.createFrom(new RGB(1, 2, 3))));
121+
}
122+
private void createResourceManager() {
123+
localResourceManager = new LocalResourceManager(JFaceResources.getResources(),this);
124+
}
125+
}""");
126126
}
127127
}

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

Lines changed: 7 additions & 8 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, 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
@@ -42,13 +42,12 @@ public class ConvertersTest extends RcpModelTest {
4242
@BeforeEach
4343
public void setUp() throws Exception {
4444
super.setUp();
45-
shell =
46-
parseComposite(
47-
"// filler filler filler",
48-
"public class Test extends Shell {",
49-
" public Test() {",
50-
" }",
51-
"}");
45+
shell = parseComposite("""
46+
// filler filler filler
47+
public class Test extends Shell {
48+
public Test() {
49+
}
50+
}""");
5251
}
5352

5453
@Override

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

Lines changed: 8 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, 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
@@ -35,14 +35,13 @@ public abstract class FontPropertyEditorTest extends RcpModelTest {
3535
protected final void assert_getText_getClipboardSource_forSource(String fontSource,
3636
String expectedText,
3737
String expectedClipboardSource) throws Exception {
38-
CompositeInfo shell =
39-
parseComposite(
40-
"// filler filler filler",
41-
"public class Test extends Shell {",
42-
" public Test() {",
43-
" setFont(" + fontSource + ");",
44-
" }",
45-
"}");
38+
CompositeInfo shell = parseComposite("""
39+
// filler filler filler
40+
public class Test extends Shell {
41+
public Test() {
42+
setFont(%s);
43+
}
44+
}""".formatted(fontSource));
4645
shell.refresh();
4746
//
4847
Property property = shell.getPropertyByTitle("font");

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

Lines changed: 56 additions & 72 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
@@ -38,25 +38,21 @@ public class FontPropertyEditorTestRegistry extends FontPropertyEditorTest {
3838
////////////////////////////////////////////////////////////////////////////
3939
@Test
4040
public void test_info() throws Exception {
41-
createASTCompilationUnit(
42-
"test",
43-
"MyRegistry.java",
44-
getTestSource(
45-
"public class MyRegistry extends FontRegistry {",
46-
" public static final String R_KEY = '_r_key_';",
47-
" public MyRegistry() {",
48-
" put(R_KEY, new FontData[]{new FontData('Courier New', 14, SWT.NONE)});",
49-
" }",
50-
"}"));
41+
createASTCompilationUnit("test", "MyRegistry.java", getTestSource("""
42+
public class MyRegistry extends FontRegistry {
43+
public static final String R_KEY = "_r_key_";
44+
public MyRegistry() {
45+
put(R_KEY, new FontData[]{new FontData("Courier New", 14, SWT.NONE)});
46+
}
47+
}"""));
5148
waitForAutoBuild();
5249
//
53-
CompositeInfo shell =
54-
parseComposite(
55-
"public class Test extends Shell {",
56-
" private MyRegistry registry = new MyRegistry();",
57-
" public Test() {",
58-
" }",
59-
"}");
50+
CompositeInfo shell = parseComposite("""
51+
public class Test extends Shell {
52+
private MyRegistry registry = new MyRegistry();
53+
public Test() {
54+
}
55+
}""");
6056
shell.refresh();
6157
//
6258
List<RegistryContainerInfo> children = shell.getChildren(RegistryContainerInfo.class);
@@ -80,26 +76,22 @@ public void test_info() throws Exception {
8076

8177
@Test
8278
public void test_value() throws Exception {
83-
createASTCompilationUnit(
84-
"test",
85-
"MyRegistry.java",
86-
getTestSource(
87-
"public class MyRegistry extends FontRegistry {",
88-
" public static final String R_KEY = '_r_key_';",
89-
" public MyRegistry() {",
90-
" put(R_KEY, new FontData[]{new FontData('Courier New', 14, SWT.NONE)});",
91-
" }",
92-
"}"));
79+
createASTCompilationUnit("test", "MyRegistry.java", getTestSource("""
80+
public class MyRegistry extends FontRegistry {
81+
public static final String R_KEY = "_r_key_";
82+
public MyRegistry() {
83+
put(R_KEY, new FontData[]{new FontData("Courier New", 14, SWT.NONE)});
84+
}
85+
}"""));
9386
waitForAutoBuild();
9487
//
95-
CompositeInfo shell =
96-
parseComposite(
97-
"public class Test extends Shell {",
98-
" private MyRegistry registry = new MyRegistry();",
99-
" public Test() {",
100-
" setFont(registry.get(MyRegistry.R_KEY));",
101-
" }",
102-
"}");
88+
CompositeInfo shell = parseComposite("""
89+
public class Test extends Shell {
90+
private MyRegistry registry = new MyRegistry();
91+
public Test() {
92+
setFont(registry.get(MyRegistry.R_KEY));
93+
}
94+
}""");
10395
shell.refresh();
10496
assertNoErrors(shell);
10597
//
@@ -123,26 +115,22 @@ public void test_value() throws Exception {
123115

124116
@Test
125117
public void test_value_bold() throws Exception {
126-
createASTCompilationUnit(
127-
"test",
128-
"MyRegistry.java",
129-
getTestSource(
130-
"public class MyRegistry extends FontRegistry {",
131-
" public static final String R_KEY = '_r_key_';",
132-
" public MyRegistry() {",
133-
" put(R_KEY, new FontData[]{new FontData('Courier New', 14, SWT.NONE)});",
134-
" }",
135-
"}"));
118+
createASTCompilationUnit("test", "MyRegistry.java", getTestSource("""
119+
public class MyRegistry extends FontRegistry {
120+
public static final String R_KEY = "_r_key_";
121+
public MyRegistry() {
122+
put(R_KEY, new FontData[]{new FontData("Courier New", 14, SWT.NONE)});
123+
}
124+
}"""));
136125
waitForAutoBuild();
137126
//
138-
CompositeInfo shell =
139-
parseComposite(
140-
"public class Test extends Shell {",
141-
" private MyRegistry registry = new MyRegistry();",
142-
" public Test() {",
143-
" setFont(registry.getBold(MyRegistry.R_KEY));",
144-
" }",
145-
"}");
127+
CompositeInfo shell = parseComposite("""
128+
public class Test extends Shell {
129+
private MyRegistry registry = new MyRegistry();
130+
public Test() {
131+
setFont(registry.getBold(MyRegistry.R_KEY));
132+
}
133+
}""");
146134
shell.refresh();
147135
assertNoErrors(shell);
148136
//
@@ -159,26 +147,22 @@ public void test_value_bold() throws Exception {
159147

160148
@Test
161149
public void test_value_italic() throws Exception {
162-
createASTCompilationUnit(
163-
"test",
164-
"MyRegistry.java",
165-
getTestSource(
166-
"public class MyRegistry extends FontRegistry {",
167-
" public static final String R_KEY = '_r_key_';",
168-
" public MyRegistry() {",
169-
" put(R_KEY, new FontData[]{new FontData('Courier New', 14, SWT.NONE)});",
170-
" }",
171-
"}"));
150+
createASTCompilationUnit("test", "MyRegistry.java", getTestSource("""
151+
public class MyRegistry extends FontRegistry {
152+
public static final String R_KEY = "_r_key_";
153+
public MyRegistry() {
154+
put(R_KEY, new FontData[]{new FontData("Courier New", 14, SWT.NONE)});
155+
}
156+
}"""));
172157
waitForAutoBuild();
173158
//
174-
CompositeInfo shell =
175-
parseComposite(
176-
"public class Test extends Shell {",
177-
" private MyRegistry registry = new MyRegistry();",
178-
" public Test() {",
179-
" setFont(registry.getItalic(MyRegistry.R_KEY));",
180-
" }",
181-
"}");
159+
CompositeInfo shell = parseComposite("""
160+
public class Test extends Shell {
161+
private MyRegistry registry = new MyRegistry();
162+
public Test() {
163+
setFont(registry.getItalic(MyRegistry.R_KEY));
164+
}
165+
}""");
182166
shell.refresh();
183167
assertNoErrors(shell);
184168
//

0 commit comments

Comments
 (0)