Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8338468: [TestBug] Convert controls tests to JUnit 5 #1561

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,7 +25,9 @@

package test.com.sun.javafx.scene.control;

import com.sun.javafx.scene.control.LabeledImpl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.net.URL;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Labeled;
Expand All @@ -34,17 +36,13 @@
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import org.junit.Test;

import java.net.URL;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.jupiter.api.Test;
import com.sun.javafx.scene.control.LabeledImpl;

public class LabeledImplOtherTest {


@Test public void test_RT_21357() {
@Test
public void test_RT_21357() {

final Labeled labeled = new Label("label");
final LabeledImpl labeledImpl = new LabeledImpl(labeled);
Expand All @@ -60,8 +58,8 @@ public class LabeledImplOtherTest {
assertNotNull(labeled.getGraphic());
}

@Test public void test_RT_21617() {

@Test
public void test_RT_21617() {
MenuButton mb = new MenuButton();
mb.setText("SomeText");
MenuButtonSkin mbs = new MenuButtonSkin(mb);
Expand All @@ -87,5 +85,4 @@ public class LabeledImplOtherTest {
assertEquals(1, mb.getOpacity(), 0.00001);
assertEquals(.5, labeledImpl.getOpacity(), 0.00001);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,18 +25,13 @@

package test.com.sun.javafx.scene.control;

import test.com.sun.javafx.pgstub.StubImageLoaderFactory;
import test.com.sun.javafx.pgstub.StubPlatformImageInfo;
import test.com.sun.javafx.pgstub.StubToolkit;
import com.sun.javafx.scene.control.LabeledImpl;
import com.sun.javafx.scene.control.LabeledImplShim;
import com.sun.javafx.tk.Toolkit;
import javafx.css.CssMetaData;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;

import java.util.Collection;
import java.util.List;
import javafx.beans.value.WritableValue;
import javafx.css.CssMetaData;
import javafx.css.Styleable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand All @@ -50,19 +45,20 @@
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import com.sun.javafx.scene.control.LabeledImpl;
import com.sun.javafx.scene.control.LabeledImplShim;
import com.sun.javafx.tk.Toolkit;
import test.com.sun.javafx.pgstub.StubImageLoaderFactory;
import test.com.sun.javafx.pgstub.StubPlatformImageInfo;
import test.com.sun.javafx.pgstub.StubToolkit;

import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import org.junit.Test;
import static org.junit.Assert.*;

@RunWith(Parameterized.class)
public class LabeledImplTest {

@BeforeClass
@BeforeAll
public static void configureImageLoaderFactory() {
final StubImageLoaderFactory imageLoaderFactory =
((StubToolkit) Toolkit.getToolkit()).getImageLoaderFactory();
Expand Down Expand Up @@ -155,9 +151,6 @@ private static Configuration config(CssMetaData styleable) {
return null;
}

private final Configuration configuration;

@Parameters
public static Collection<Configuration[]> data() {

Collection<Configuration[]> data = new ArrayList<>();
Expand All @@ -180,20 +173,14 @@ public static Collection<Configuration[]> data() {
return data;
}

@Test
public void testMirrorReflectsSource() {
@ParameterizedTest
@MethodSource("data")
public void testMirrorReflectsSource(Configuration configuration) {
final WritableValue source = configuration.source;
final WritableValue mirror = configuration.mirror;
final Object expected = configuration.value;

source.setValue(expected);
assertEquals(mirror.toString(), expected, mirror.getValue());
}

public LabeledImplTest(Configuration configuration) {
this.configuration = configuration;
}

static {
assertEquals(expected, mirror.getValue(), mirror.toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,7 +25,12 @@

package test.com.sun.javafx.scene.control;

import com.sun.javafx.scene.control.LabeledText;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import javafx.css.CssMetaData;
import javafx.css.Stylesheet;
import javafx.scene.Cursor;
Expand All @@ -39,8 +44,9 @@
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;
import org.junit.*;
import static org.junit.Assert.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.sun.javafx.scene.control.LabeledText;

/**
*
Expand All @@ -57,7 +63,8 @@ public class LabeledTextTest {
public LabeledTextTest() {
}

@Before public void setup() {
@BeforeEach
public void setup() {
label =
new Label("\"A computer once beat me at chess, "
+ "but it was no match for me at kick boxing.\" Emo Philips");
Expand Down Expand Up @@ -111,13 +118,11 @@ public void testLabeledTextFontIsBound() {

@Test
public void testLabeledTextFillStyleAffectsLabeledText() {

label.setStyle("-fx-text-fill: rgb(255,0,0);");
label.applyCss();
Color expected = Color.rgb(255, 0, 0);
assertEquals(expected, label.getTextFill());
assertEquals(expected, labeledText.getFill());

}

@Test
Expand All @@ -132,12 +137,10 @@ public void testLabeledTextFillIsBound() {

@Test
public void testLabeledUnderlineStyleAffectsLabeledText() {

label.setStyle("-fx-underline: true;");
label.applyCss();
assert(label.isUnderline() == true);
assert(labeledText.isUnderline() == true);

}

@Test
Expand Down Expand Up @@ -253,7 +256,6 @@ private static CssMetaData getCssMetaData(String prop) {

@Test
public void testLabeledTextFillIsSettableByCss() {

CssMetaData sp = getCssMetaData("-fx-fill");
assertTrue(sp.isSettable(labeledText));
}
Expand All @@ -263,10 +265,8 @@ public void testCanStyleFillOnLabeledText() {
assertEquals(Color.GREEN, labeledText.getFill());
}


@Test
public void testLabeledTextTextAlignmentIsSettableByCss() {

CssMetaData sp = getCssMetaData("-fx-text-alignment");
assertTrue(sp.isSettable(labeledText));
}
Expand All @@ -276,10 +276,8 @@ public void testCanStyleTextAlignmentOnLabeledText() {
assertEquals(TextAlignment.RIGHT, labeledText.getTextAlignment());
}


@Test
public void testLabeledTextFontIsSettableByCss() {

CssMetaData sp = getCssMetaData("-fx-font");
assertTrue(sp.isSettable(labeledText));
}
Expand All @@ -289,10 +287,8 @@ public void testCanStyleFontOnLabeledText() {
assertEquals(Font.font("Amble", 10), labeledText.getFont());
}


@Test
public void testLabeledTextUnderlineIsSettableByCss() {

CssMetaData sp = getCssMetaData("-fx-underline");
assertTrue(sp.isSettable(labeledText));
}
Expand Down Expand Up @@ -371,9 +367,8 @@ public void testLabeledSetUnderlineNotOverridenByUAStyleOnLabeledText() {
assertTrue(labeledText.isUnderline());
}


@Test public void test_RT_37787() {

@Test
public void test_RT_37787() {
label = new Label("test_RT_37787");
label.getStyleClass().clear();
label.setId("test-rt-37787");
Expand All @@ -392,11 +387,10 @@ public void testLabeledSetUnderlineNotOverridenByUAStyleOnLabeledText() {
double expected = Font.getDefault().getSize() * 1.5;
double actual = label.getFont().getSize();
assertEquals(expected, actual, .1);

}

@Test public void test_RT_37787_with_inline_style() {

@Test
public void test_RT_37787_with_inline_style() {
label = new Label("test_RT_37787_with_inline_style");
label.setStyle("-fx-font-size: 1.231em;");
label.getStyleClass().clear();
Expand All @@ -412,7 +406,5 @@ public void testLabeledSetUnderlineNotOverridenByUAStyleOnLabeledText() {
double expected = Font.getDefault().getSize() * 1.5 * 1.231;
double actual = label.getFont().getSize();
assertEquals(expected, actual, .1);

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,25 +25,24 @@

package test.com.sun.javafx.scene.control;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static test.com.sun.javafx.scene.control.infrastructure.ControlSkinFactory.attemptGC;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import org.junit.Before;
import org.junit.Test;

import com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler;

import static org.junit.Assert.*;
import static test.com.sun.javafx.scene.control.infrastructure.ControlSkinFactory.*;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler;

/**
* Test support of listChange listeners.
Expand Down Expand Up @@ -89,9 +88,8 @@ public void testUnregistersMultipleConsumers() {
// remove listener chain
Consumer<Change<?>> removedChain = handler.unregisterListChangeListeners(items);
items.add("added after removed");
assertEquals("none of the removed listeners must be notified",
0, changes.size() + secondChanges.size());
// manually add the chained listener
assertEquals(0, changes.size() + secondChanges.size(), "none of the removed listeners must be notified");
// manually add the chained listener
items.addListener((ListChangeListener)(c -> removedChain.accept(c)));
items.add("added");
assertEquals(1, changes.size());
Expand Down Expand Up @@ -190,10 +188,10 @@ public void testDispose() {
handler.registerListChangeListener(items, consumer);
handler.dispose();
items.add("added");
assertEquals("listener must not be invoked after dispose", 0, changes.size());
assertEquals(0, changes.size(), "listener must not be invoked after dispose");
handler.registerListChangeListener(items, consumer);
items.add("added");
assertEquals("listener must be invoked when re-registered after dispose", 1, changes.size());
assertEquals(1, changes.size(), "listener must be invoked when re-registered after dispose");
}


Expand All @@ -213,15 +211,15 @@ public void testRegisterMemoryLeak() {
assertEquals(1, changes.size());
handler = null;
attemptGC(ref);
assertNull("handler must be gc'ed", ref.get());
assertNull(ref.get(), "handler must be gc'ed");
items.add("another");
assertEquals("listener must not be invoked after gc", 1, changes.size());
assertEquals(1, changes.size(), "listener must not be invoked after gc");
}


//----------- setup and intial

@Before
@BeforeEach
public void setup() {
handler = new LambdaMultiplePropertyChangeListenerHandler();
items = FXCollections.observableArrayList("one", "two", "four");
Expand All @@ -242,8 +240,8 @@ public void testInvalidationOfListValuedObservable() {
itemsProperty.addListener((obs, ov, nv) -> changes[0]++);
itemsProperty.set(FXCollections.observableArrayList(data));
// notifications when newList.equals(oldList)
assertEquals("changeListener not notified", 0, changes[0]);
assertEquals("invalidationListener notified", 1, invalidations[0]);
assertEquals(0, changes[0], "changeListener not notified");
assertEquals(1, invalidations[0], "invalidationListener notified");
itemsProperty.get().add("added");
// sanity: no notification on modifications to the list
assertEquals(0, changes[0]);
Expand Down
Loading