From 496a7c6dd28b70b4388d0971d60ac508fb523445 Mon Sep 17 00:00:00 2001 From: Aleksandar Kurtakov Date: Tue, 20 May 2025 18:56:07 +0300 Subject: [PATCH] Simplify Spinner test * Use assertThrows * Do not override parent test method so it actually gets executed --- .../Test_org_eclipse_swt_widgets_Spinner.java | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Spinner.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Spinner.java index 14c91d7387e..680908edf5c 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Spinner.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Spinner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 Red Hat, Inc. and others. + * Copyright (c) 2000, 2025 Red Hat, Inc. and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,7 +15,7 @@ package org.eclipse.swt.tests.junit; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Spinner; @@ -37,23 +37,13 @@ public void setUp() { @Override @Test public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() { - try { - spinner = new Spinner(null, 0); - fail("No exception thrown for parent == null"); - } - catch (IllegalArgumentException e) { - } - int[] cases = {0, SWT.READ_ONLY, SWT.WRAP}; + assertThrows("No exception thrown for parent == null", IllegalArgumentException.class, + () -> new Spinner(null, 0)); + int[] cases = { 0, SWT.READ_ONLY, SWT.WRAP }; for (int style : cases) spinner = new Spinner(shell, style); } - @Override - @Test - public void test_computeSizeIIZ() { - // super class test is sufficient - } - @Test public void test_getIncrement() { int [] cases = {5,100,1000,1}; @@ -72,13 +62,9 @@ public void test_getDigits() { spinner.setDigits(digits); assertEquals(digits, spinner.getDigits()); } - try{ - spinner.setDigits(-1); - fail("setDigits should have failed with illegal Argument"); - } - catch(IllegalArgumentException e){ - assertEquals(cases[cases.length-1], spinner.getDigits()); - } + assertThrows("setDigits should have failed with illegal Argument", IllegalArgumentException.class, + () -> spinner.setDigits(-1)); + assertEquals(cases[cases.length-1], spinner.getDigits()); } @Test @@ -132,11 +118,8 @@ public void test_getTextLimit() { spinner.setTextLimit(value); assertEquals(value, spinner.getTextLimit()); } - try { - spinner.setTextLimit(0); - fail("setTextLimit should have caused an expection with value 0"); - } catch (Exception e) { - } + assertThrows("setTextLimit should have caused an expection with value 0", IllegalArgumentException.class, + () -> spinner.setTextLimit(0)); } @Test