Skip to content

Commit

Permalink
Migrate win32 unit tests to JUnit 5 and reduce test visibility #1298
Browse files Browse the repository at this point in the history
This migrates the unit tests placed in the SWT win32 production
fragments to JUnit 5. The visibility of the test classes is reduced to
`packaged protected` as allowed by JUnit 5.

Fixes #1298
  • Loading branch information
HeikoKlare committed Jun 26, 2024
1 parent f40502d commit e386c7a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.widgets.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class GCWin32Tests extends Win32AutoscaleTestBase {
class GCWin32Tests extends Win32AutoscaleTestBase {

@Test
public void gcZoomLevelMustChangeOnShellZoomChange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gdip.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class PathWin32Tests extends Win32AutoscaleTestBase {
class PathWin32Tests extends Win32AutoscaleTestBase {

int zoom = 100;
int scaledZoom = 200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import static org.junit.Assert.assertEquals;

import org.eclipse.swt.internal.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class TextLayoutWin32Tests extends Win32AutoscaleTestBase {
class TextLayoutWin32Tests extends Win32AutoscaleTestBase {
final static String text = "This is a text for testing.";

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
*******************************************************************************/
package org.eclipse.swt.graphics;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gdip.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class TransformWin32Tests extends Win32AutoscaleTestBase {
class TransformWin32Tests extends Win32AutoscaleTestBase {

@Test
public void testShouldHaveDifferentHandlesAtDifferentZoomLevels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.junit.jupiter.api.*;

public class DefaultSWTFontRegistryTests {
class DefaultSWTFontRegistryTests {
private static String TEST_FONT = "Helvetica";
private Display display;
private SWTFontRegistry fontRegistry;

@BeforeClass
@BeforeAll
public static void assumeIsFittingPlatform() {
PlatformSpecificExecution.assumeIsFittingPlatform();
}

@Before
@BeforeEach
public void setUp() {
this.display = Display.getDefault();
this.fontRegistry = new DefaultSWTFontRegistry(display);
}

@After
@AfterEach
public void tearDown() {
if (this.fontRegistry != null) {
this.fontRegistry.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@
*******************************************************************************/
package org.eclipse.swt.internal;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.junit.jupiter.api.*;

public class ScalingSWTFontRegistryTests {
class ScalingSWTFontRegistryTests {
private static String TEST_FONT = "Helvetica";
private SWTFontRegistry fontRegistry;

@BeforeClass
@BeforeAll
public static void assumeIsFittingPlatform() {
PlatformSpecificExecution.assumeIsFittingPlatform();
}

@Before
@BeforeEach
public void setUp() {
this.fontRegistry = new ScalingSWTFontRegistry(Display.getDefault());
}

@After
@AfterEach
public void tearDown() {
if (this.fontRegistry != null) {
this.fontRegistry.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public abstract class Win32AutoscaleTestBase {
protected Display display;
protected Shell shell;
private boolean autoScaleOnRuntime;

@BeforeClass
@BeforeAll
public static void assumeIsFittingPlatform() {
PlatformSpecificExecution.assumeIsFittingPlatform();
}

@Before
@BeforeEach
public void setUpTest() {
autoScaleOnRuntime = DPITestUtil.isAutoScaleOnRuntimeActive();
display = Display.getDefault();
autoScaleOnRuntime(true);
shell = new Shell(display);
}

@After
@AfterEach
public void tearDownTest() {
if (shell != null) {
shell.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@
*******************************************************************************/
package org.eclipse.swt.widgets;


import static org.junit.Assert.*;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.junit.*;
import org.junit.jupiter.api.*;

/**
* Automated Tests for class org.eclipse.swt.widgets.Control
* for Windows specific behavior
*
* @see org.eclipse.swt.widgets.Control
*/
public class ControlWin32Tests extends Win32AutoscaleTestBase {
class ControlWin32Tests extends Win32AutoscaleTestBase {

@Test
public void testScaleFontCorrectlyInAutoScaleSzenario() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class WidgetWin32Tests extends Win32AutoscaleTestBase {
class WidgetWin32Tests extends Win32AutoscaleTestBase {

@Test
public void testWidgetZoomShouldChangeOnZoomLevelChange() {
Expand Down

0 comments on commit e386c7a

Please sign in to comment.