From 13c78f6487fbb16edbbeab14dbebf99414e28eca Mon Sep 17 00:00:00 2001 From: Laurent Caron Date: Sat, 4 May 2024 18:55:22 +0200 Subject: [PATCH] Issue XXX - Stupid PR --- .../compositetable/CompositeTableTest.java | 129 +++++++++--------- 1 file changed, 61 insertions(+), 68 deletions(-) diff --git a/widgets/compositetable/org.eclipse.nebula.widgets.compositetable.tests/src/org/eclipse/nebula/widgets/compositetable/CompositeTableTest.java b/widgets/compositetable/org.eclipse.nebula.widgets.compositetable.tests/src/org/eclipse/nebula/widgets/compositetable/CompositeTableTest.java index 675819fa7..7195b6fb6 100644 --- a/widgets/compositetable/org.eclipse.nebula.widgets.compositetable.tests/src/org/eclipse/nebula/widgets/compositetable/CompositeTableTest.java +++ b/widgets/compositetable/org.eclipse.nebula.widgets.compositetable.tests/src/org/eclipse/nebula/widgets/compositetable/CompositeTableTest.java @@ -5,19 +5,14 @@ * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: - * compeople AG - initial API and implementation + * compeople AG - initial API and implementation ******************************************************************************/ package org.eclipse.nebula.widgets.compositetable; -import junit.framework.TestCase; - -import org.eclipse.nebula.widgets.compositetable.CompositeTable; -import org.eclipse.nebula.widgets.compositetable.IRowContentProvider; -import org.eclipse.nebula.widgets.compositetable.ResizableGridRowLayout; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FillLayout; @@ -27,29 +22,32 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import junit.framework.TestCase; + public class CompositeTableTest extends TestCase { private boolean createdDisplay = false; - private static final class Row extends Composite { - private Text text; + private static final class Row extends Composite { + private final Text text; - public Row(Composite parent, int style) { - super(parent, style); - setLayout(new ResizableGridRowLayout()); - text = new Text(this, SWT.BORDER | SWT.SINGLE); - } + public Row(final Composite parent, final int style) { + super(parent, style); + setLayout(new ResizableGridRowLayout()); + text = new Text(this, SWT.BORDER | SWT.SINGLE); + } - public String toString() { - return text.getText(); + @Override + public String toString() { + return text.getText(); + } } - } - private Display display; - private Shell shell; - private CompositeTable table; - private String[] words; + private Display display; + private Shell shell; + private CompositeTable table; + private String[] words; - @Override + @Override protected void setUp() throws Exception { display = Display.getCurrent(); if (display == null) { @@ -63,18 +61,13 @@ protected void setUp() throws Exception { table = new CompositeTable(shell, SWT.NONE); new Row(table, SWT.NONE); - words = new String[] { "Basic", "Bash", "C", "C++", "Clipper", "Cobol", - "Java", "ML", "Pascal", "Perl", "Python", "Ruby", "Scheme", - "Smalltalk", }; - table.addRowContentProvider(new IRowContentProvider() { - public void refresh(CompositeTable sender, int currentObjectOffset, - Control rowControl) { - Row row = (Row) rowControl; - String word = words[currentObjectOffset]; - // System.out.println("refresh: " + currentObjectOffset + " " + - // word); - row.text.setText(word); - } + words = new String[] { "Basic", "Bash", "C", "C++", "Clipper", "Cobol", "Java", "ML", "Pascal", "Perl", "Python", "Ruby", "Scheme", "Smalltalk", }; + table.addRowContentProvider((sender, currentObjectOffset, rowControl) -> { + final Row row = (Row) rowControl; + final String word = words[currentObjectOffset]; + // System.out.println("refresh: " + currentObjectOffset + " " + + // word); + row.text.setText(word); }); table.setNumRowsInCollection(words.length); table.setRunTime(true); @@ -82,7 +75,7 @@ public void refresh(CompositeTable sender, int currentObjectOffset, shell.open(); } - @Override + @Override protected void tearDown() throws Exception { shell.dispose(); if (createdDisplay) { @@ -90,52 +83,52 @@ protected void tearDown() throws Exception { } } - // test methods - // ///////////// + // test methods + // ///////////// - public void testGetRowControlsWithTopRowZero() throws Exception { - assertEquals(0, table.getTopRow()); - Control[] rowControls = table.getRowControls(); - for (int i = 0; i < rowControls.length; i++) { - Row row = (Row) rowControls[i]; - assertEquals(words[i], row.toString()); + public void testGetRowControlsWithTopRowZero() throws Exception { + assertEquals(0, table.getTopRow()); + final Control[] rowControls = table.getRowControls(); + for (int i = 0; i < rowControls.length; i++) { + final Row row = (Row) rowControls[i]; + assertEquals(words[i], row.toString()); + } } - } - public void testSetSelection() { - table.setSelection(0, 0); - readAndDispatch(); + public void testSetSelection() { + table.setSelection(0, 0); + readAndDispatch(); - assertEquals(new Point(0, 0), table.getSelection()); + assertEquals(new Point(0, 0), table.getSelection()); - table.setSelection(0, 1); - readAndDispatch(); + table.setSelection(0, 1); + readAndDispatch(); - assertEquals(new Point(0, 1), table.getSelection()); + assertEquals(new Point(0, 1), table.getSelection()); - table.setSelection(0, 10); - readAndDispatch(); + table.setSelection(0, 10); + readAndDispatch(); - assertEquals(new Point(0, 10 - table.getTopRow()), table.getSelection()); - } + assertEquals(new Point(0, 10 - table.getTopRow()), table.getSelection()); + } - public void testClearSelection() { - // shell.open() will set the selection to the first row - assertEquals(new Point(-1, 0), table.getSelection()); + public void testClearSelection() { + // shell.open() will set the selection to the first row + assertEquals(new Point(-1, 0), table.getSelection()); - table.clearSelection(); - readAndDispatch(); + table.clearSelection(); + readAndDispatch(); - assertEquals(null, table.getSelection()); - } + assertEquals(null, table.getSelection()); + } - // helping methods - // //////////////// + // helping methods + // //////////////// - private void readAndDispatch() { - while (display.readAndDispatch()) { - // next + private void readAndDispatch() { + while (display.readAndDispatch()) { + // next + } } - } }