Skip to content

Commit

Permalink
8338468: [TestBug] Convert controls tests to JUnit 5
Browse files Browse the repository at this point in the history
Reviewed-by: mhanl, lkostyra, arapte
  • Loading branch information
Andy Goryachev committed Sep 23, 2024
1 parent addf085 commit 5171753
Show file tree
Hide file tree
Showing 212 changed files with 7,782 additions and 6,196 deletions.
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.