Skip to content

Commit dcdb209

Browse files
committed
Repair and execute Swing FormLayout tests
These tests were disabled with 2f300b9 and have been adapted to be platform-independent by using a stubbed UnitConverter class. Additional note: `test_oneRow` was wrongfully adapted with ddb982e, which has been reverted as well.
1 parent 2eb57de commit dcdb209

9 files changed

Lines changed: 71 additions & 32 deletions

File tree

org.eclipse.wb.swing.FormLayout/src/org/eclipse/wb/internal/swing/FormLayout/model/FormLayoutInfo.java

Lines changed: 3 additions & 3 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
@@ -62,7 +62,7 @@
6262
import com.jgoodies.forms.layout.FormSpec;
6363
import com.jgoodies.forms.layout.FormSpecs;
6464
import com.jgoodies.forms.layout.RowSpec;
65-
import com.jgoodies.forms.util.DefaultUnitConverter;
65+
import com.jgoodies.forms.util.UnitConverter;
6666

6767
import org.apache.commons.collections4.BidiMap;
6868
import org.apache.commons.collections4.bidimap.DualHashBidiMap;
@@ -1456,7 +1456,7 @@ protected void refresh_afterCreate2() throws Exception {
14561456
}
14571457
// initialize default sizes in pixels
14581458
{
1459-
DefaultUnitConverter converter = DefaultUnitConverter.getInstance();
1459+
UnitConverter converter = FormSizeConstantInfo.getUnitConverter();
14601460
//
14611461
m_defaultColumnSize = converter.millimeterAsPixel(DEFAULT_SIZE, container);
14621462
m_defaultRowSize = converter.millimeterAsPixel(DEFAULT_SIZE, container);

org.eclipse.wb.swing.FormLayout/src/org/eclipse/wb/internal/swing/FormLayout/model/FormSizeConstantInfo.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2025 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
@@ -26,6 +26,7 @@
2626
import java.text.DecimalFormat;
2727
import java.text.DecimalFormatSymbols;
2828
import java.util.Locale;
29+
import java.util.Objects;
2930

3031
import javax.swing.JFrame;
3132

@@ -36,6 +37,7 @@
3637
* @coverage swing.FormLayout.model
3738
*/
3839
public final class FormSizeConstantInfo {
40+
private static UnitConverter m_unitConverter = DefaultUnitConverter.getInstance();
3941
private double m_value;
4042
private Unit m_unit;
4143

@@ -112,6 +114,20 @@ public void setUnit(Unit unit) throws Exception {
112114
m_unit = unit;
113115
}
114116

117+
/**
118+
* @return the {@link UnitConverter}
119+
*/
120+
public static UnitConverter getUnitConverter() {
121+
return m_unitConverter;
122+
}
123+
124+
/**
125+
* Sets the {@link UnitConverter}.
126+
*/
127+
public static void setUnitConverter(UnitConverter unitConverter) {
128+
m_unitConverter = Objects.requireNonNull(unitConverter);
129+
}
130+
115131
////////////////////////////////////////////////////////////////////////////
116132
//
117133
// Object
@@ -182,7 +198,7 @@ private static double convertValue(double value, Unit oldUnit, Unit newUnit) thr
182198
* @return the value in pixels for value in given {@link Unit}.
183199
*/
184200
public static int convertToPixels(double value, Unit unit) {
185-
UnitConverter converter = DefaultUnitConverter.getInstance();
201+
UnitConverter converter = getUnitConverter();
186202
//
187203
int pixels = 0;
188204
if (unit == ConstantSize.PIXEL) {
@@ -231,7 +247,7 @@ public static double convertFromPixels(int pixels, Unit unit) throws Exception {
231247
* in pixels.
232248
*/
233249
private static int convertFromPixelsInt(int pixels, String methodName) throws Exception {
234-
UnitConverter converter = DefaultUnitConverter.getInstance();
250+
UnitConverter converter = getUnitConverter();
235251
Method method =
236252
UnitConverter.class.getMethod(methodName, new Class[]{int.class, Component.class});
237253
int result = 0;
@@ -251,7 +267,7 @@ private static int convertFromPixelsInt(int pixels, String methodName) throws Ex
251267
* in pixels.
252268
*/
253269
private static double convertFromPixelsDouble(int pixels, String methodName) throws Exception {
254-
UnitConverter converter = DefaultUnitConverter.getInstance();
270+
UnitConverter converter = getUnitConverter();
255271
Method method =
256272
UnitConverter.class.getMethod(methodName, new Class[]{double.class, Component.class});
257273
double result = 0;

org.eclipse.wb.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Export-Package: org.eclipse.wb.tests.designer;x-internal:=true,
150150
org.eclipse.wb.tests.utils;x-internal:=true
151151
Import-Package: com.jgoodies.forms.factories;version="[1.9.0,2.0.0]",
152152
com.jgoodies.forms.layout;version="[1.9.0,2.0.0]",
153+
com.jgoodies.forms.util;version="[1.9.0,2.0.0)",
153154
net.miginfocom.layout;version="[11.3.0,12.0.0]",
154155
net.miginfocom.swing;version="[11.3.0,12.0.0]",
155156
org.apache.commons.collections4;version="[4.4.0,5.0.0)",

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/AbstractFormLayoutTest.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 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
@@ -13,13 +13,20 @@
1313
package org.eclipse.wb.tests.designer.swing.model.layout.FormLayout;
1414

1515
import org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils;
16+
import org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo;
1617
import org.eclipse.wb.internal.swing.laf.LafSupport;
1718
import org.eclipse.wb.tests.designer.swing.model.layout.AbstractLayoutTest;
1819

1920
import com.jgoodies.forms.layout.FormLayout;
21+
import com.jgoodies.forms.util.AbstractUnitConverter;
22+
import com.jgoodies.forms.util.DefaultUnitConverter;
2023

24+
import org.junit.jupiter.api.AfterAll;
25+
import org.junit.jupiter.api.BeforeAll;
2126
import org.junit.jupiter.api.BeforeEach;
2227

28+
import java.awt.Component;
29+
2330
/**
2431
* Abstract test for {@link FormLayout}.
2532
*
@@ -33,6 +40,16 @@ public abstract class AbstractFormLayoutTest extends AbstractLayoutTest {
3340
// Life cycle
3441
//
3542
////////////////////////////////////////////////////////////////////////////
43+
@BeforeAll
44+
public static void setUpUnitConverter() {
45+
FormSizeConstantInfo.setUnitConverter(new UnitConverterStub());
46+
}
47+
48+
@AfterAll
49+
public static void tearDownUnitConverter() {
50+
FormSizeConstantInfo.setUnitConverter(DefaultUnitConverter.getInstance());
51+
}
52+
3653
@Override
3754
@BeforeEach
3855
public void setUp() throws Exception {
@@ -66,4 +83,23 @@ public String getTestSource(String... lines) {
6683
}
6784
return super.getTestSource(lines);
6885
}
86+
87+
private static class UnitConverterStub extends AbstractUnitConverter {
88+
private static final long serialVersionUID = 1L;
89+
90+
@Override
91+
protected double getDialogBaseUnitsX(Component component) {
92+
return 6;
93+
}
94+
95+
@Override
96+
protected double getDialogBaseUnitsY(Component component) {
97+
return 12;
98+
}
99+
100+
@Override
101+
protected int getScreenResolution(Component c) {
102+
return 96;
103+
}
104+
}
69105
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/DefaultComponentFactoryTest.java

Lines changed: 1 addition & 3 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
@@ -29,7 +29,6 @@
2929
import com.jgoodies.forms.factories.DefaultComponentFactory;
3030

3131
import org.assertj.core.api.Assertions;
32-
import org.junit.jupiter.api.Disabled;
3332
import org.junit.jupiter.api.Test;
3433

3534
/**
@@ -109,7 +108,6 @@ public void test_createLabel() throws Exception {
109108
* Test for {@link DefaultComponentFactoryCreateLabelEntryInfo}.
110109
*/
111110
@DisposeProjectAfter
112-
@Disabled
113111
@Test
114112
public void test_createLabel_tool() throws Exception {
115113
do_projectDispose();

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormDimensionInfoTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.jgoodies.forms.layout.Size;
2525
import com.jgoodies.forms.layout.Sizes;
2626

27-
import org.junit.jupiter.api.Disabled;
2827
import org.junit.jupiter.api.Test;
2928

3029
import java.lang.reflect.Method;
@@ -264,7 +263,6 @@ public void test_rowTemplates() throws Exception {
264263
// Convert to GAP template
265264
//
266265
////////////////////////////////////////////////////////////////////////////
267-
@Disabled
268266
@Test
269267
public void test_convertToNearestGap_columns() throws Exception {
270268
check_convertToNearestGap_column("4px", 5, "LABEL_COMPONENT_GAP_COLSPEC");
@@ -279,7 +277,6 @@ public void test_convertToNearestGap_columns() throws Exception {
279277
check_convertToNearestGap_column("20px", 5, null);
280278
}
281279

282-
@Disabled
283280
@Test
284281
public void test_convertToNearestGap_rows() throws Exception {
285282
check_convertToNearestGap_row("4px", 5, "LABEL_COMPONENT_GAP_ROWSPEC");

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormLayoutConverterTest.java

Lines changed: 8 additions & 12 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
@@ -18,7 +18,6 @@
1818

1919
import com.jgoodies.forms.layout.FormLayout;
2020

21-
import org.junit.jupiter.api.Disabled;
2221
import org.junit.jupiter.api.Test;
2322

2423
/**
@@ -60,7 +59,6 @@ public void test_empty() throws Exception {
6059
"}");
6160
}
6261

63-
@Disabled
6462
@Test
6563
public void test_oneRow() throws Exception {
6664
ContainerInfo panel =
@@ -96,7 +94,7 @@ public void test_oneRow() throws Exception {
9694
" setLayout(new FormLayout(new ColumnSpec[] {",
9795
" FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,",
9896
" ColumnSpec.decode('100px'),",
99-
" ColumnSpec.decode('16px'),",
97+
" FormSpecs.UNRELATED_GAP_COLSPEC,",
10098
" ColumnSpec.decode('80px'),},",
10199
" new RowSpec[] {",
102100
" FormSpecs.UNRELATED_GAP_ROWSPEC,",
@@ -118,7 +116,6 @@ public void test_oneRow() throws Exception {
118116
}
119117
}
120118

121-
@Disabled
122119
@Test
123120
public void test_twoRows_spanColumns() throws Exception {
124121
ContainerInfo panel =
@@ -181,7 +178,6 @@ public void test_twoRows_spanColumns() throws Exception {
181178
"}");
182179
}
183180

184-
@Disabled
185181
@Test
186182
public void test_Switching_fromGridBagLayout() throws Exception {
187183
ContainerInfo panel =
@@ -243,17 +239,17 @@ public void test_Switching_fromGridBagLayout() throws Exception {
243239
"public class Test extends JPanel {",
244240
" public Test() {",
245241
" setLayout(new FormLayout(new ColumnSpec[] {",
246-
" ColumnSpec.decode('46px'),",
242+
" ColumnSpec.decode('60px'),",
247243
" FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,",
248-
" ColumnSpec.decode('305px'),",
244+
" ColumnSpec.decode('275px'),",
249245
" FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,",
250-
" ColumnSpec.decode('89px'),},",
246+
" ColumnSpec.decode('105px'),},",
251247
" new RowSpec[] {",
252-
" RowSpec.decode('20px'),",
248+
" RowSpec.decode('26px'),",
253249
" FormSpecs.LINE_GAP_ROWSPEC,",
254-
" RowSpec.decode('20px'),",
250+
" RowSpec.decode('21px'),",
255251
" FormSpecs.LINE_GAP_ROWSPEC,",
256-
" RowSpec.decode('23px'),}));",
252+
" RowSpec.decode('27px'),}));",
257253
" {",
258254
" JComboBox comboBox = new JComboBox();",
259255
" add(comboBox, '3, 1, fill, center');",

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormLayoutGefTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2025 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
@@ -861,7 +861,6 @@ public Test() {
861861
{
862862
ComponentInfo button_2 = getJavaInfoByName("button_2");
863863
canvas.target(button_2).inX(0.5).outY(ROW_GAP + 1).move();
864-
waitEventLoop(1000 * 5);
865864
canvas.assertCommandNull();
866865
}
867866
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/FormLayout/FormSizeInfoTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.jgoodies.forms.layout.Sizes;
2424

2525
import org.junit.jupiter.api.BeforeEach;
26-
import org.junit.jupiter.api.Disabled;
2726
import org.junit.jupiter.api.Test;
2827

2928
/**
@@ -61,7 +60,6 @@ public void _test_exit() throws Exception {
6160
/**
6261
* Test for {@link FormSizeConstantInfo}.
6362
*/
64-
@Disabled
6563
@Test
6664
public void test_FormSizeConstantInfo() throws Exception {
6765
FormSizeConstantInfo size = new FormSizeConstantInfo(25, ConstantSize.PIXEL);
@@ -131,7 +129,6 @@ public void test_FormSizeConstantInfo_convertSpecial() throws Exception {
131129
/**
132130
* Test for {@link FormSizeConstantInfo#convertFromPixels(int, Unit)}
133131
*/
134-
@Disabled
135132
@Test
136133
public void test_FormSizeConstantInfo_convertFromPixels() throws Exception {
137134
{
@@ -171,7 +168,6 @@ private void check_convertFromPixels(int pixels, Unit unit, double expected) thr
171168
/**
172169
* Test for {@link FormSizeConstantInfo#convertToPixels(double, Unit)}
173170
*/
174-
@Disabled
175171
@Test
176172
public void test_FormSizeConstantInfo_convertToPixels() throws Exception {
177173
{

0 commit comments

Comments
 (0)