Skip to content

Commit

Permalink
Convert graphics tests to JUnit5 - part 1/4
Browse files Browse the repository at this point in the history
  • Loading branch information
lukostyra committed Sep 12, 2024
1 parent 4647367 commit 1834fcd
Show file tree
Hide file tree
Showing 101 changed files with 1,413 additions and 1,199 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 @@ -26,11 +26,11 @@
package test.com.sun.javafx.css;

import com.sun.javafx.css.ParsedValueImpl;
import static org.junit.Assert.assertEquals;
import javafx.css.ParsedValue;
import javafx.scene.text.Font;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import javafx.css.converter.BooleanConverter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 @@ -26,12 +26,12 @@
package test.com.sun.javafx.css;

import com.sun.javafx.css.ParsedValueImpl;
import static org.junit.Assert.*;
import javafx.css.ParsedValue;
import javafx.scene.Cursor;
import javafx.scene.text.Font;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import javafx.css.converter.CursorConverter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 @@ -26,7 +26,6 @@
package test.com.sun.javafx.css;

import com.sun.javafx.css.ParsedValueImpl;
import static org.junit.Assert.assertEquals;
import javafx.css.ParsedValue;
import javafx.css.Size;
import javafx.css.SizeUnits;
Expand All @@ -37,7 +36,8 @@
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import javafx.css.converter.EffectConverter;
import javafx.css.converter.DeriveColorConverter;
Expand Down Expand Up @@ -124,29 +124,29 @@ ParsedValue<ParsedValue[], Effect> getDropShadowValue(DropShadow ds, boolean col
return new ParsedValueImpl<>(vals, EffectConverter.DropShadowConverter.getInstance());
}

void checkColor(String msg, Color c1, Color c2) {
assertEquals(msg + ".red", c1.getRed(), c2.getRed(), 0.001);
assertEquals(msg + ".blue", c1.getBlue(), c2.getBlue(), 0.001);
assertEquals(msg + ".green", c1.getGreen(), c2.getGreen(), 0.001);
assertEquals(msg + ".opacity", c1.getOpacity(), c2.getOpacity(), 0.001);
void checkColor(Color c1, Color c2, String msg) {
assertEquals(c1.getRed(), c2.getRed(), 0.001, msg + ".red");
assertEquals(c1.getBlue(), c2.getBlue(), 0.001, msg + ".blue");
assertEquals(c1.getGreen(), c2.getGreen(), 0.001, msg + ".green");
assertEquals(c1.getOpacity(), c2.getOpacity(), 0.001, msg + ".opacity");
}

void checkInnerShadow(String msg, InnerShadow o1, InnerShadow o2) {
assertEquals(msg + "innershadow.offsetX", o1.getOffsetX(), o2.getOffsetX(), 0.001);
assertEquals(msg + "innershadow.offsety", o1.getOffsetY(), o2.getOffsetY(), 0.001);
assertEquals(msg + "innershadow.choke", o1.getChoke(), o2.getChoke(), 0.001);
assertEquals(msg + "innershadow.radius", o1.getRadius(), o2.getRadius(), 0.001);
checkColor(msg + "innershadow", o1.getColor(), o2.getColor());
assertEquals(msg + "innershadow.blurType", o1.getBlurType(), o2.getBlurType());
assertEquals(o1.getOffsetX(), o2.getOffsetX(), 0.001, msg + "innershadow.offsetX");
assertEquals(o1.getOffsetY(), o2.getOffsetY(), 0.001, msg + "innershadow.offsety");
assertEquals(o1.getChoke(), o2.getChoke(), 0.001, msg + "innershadow.choke");
assertEquals(o1.getRadius(), o2.getRadius(), 0.001, msg + "innershadow.radius");
checkColor(o1.getColor(), o2.getColor(), msg + "innershadow");
assertEquals(o1.getBlurType(), o2.getBlurType(), msg + "innershadow.blurType");
}

void checkDropShadow(String msg, DropShadow o1, DropShadow o2) {
assertEquals(msg + "DropShadow.offsetX", o1.getOffsetX(), o2.getOffsetX(), 0.001);
assertEquals(msg + "DropShadow.offsety", o1.getOffsetY(), o2.getOffsetY(), 0.001);
assertEquals(msg + "DropShadow.spread", o1.getSpread(), o2.getSpread(), 0.001);
assertEquals(msg + "DropShadow.radius", o1.getRadius(), o2.getRadius(), 0.001);
checkColor(msg + "DropShadow", o1.getColor(), o2.getColor());
assertEquals(msg + "DropShadow.blurType", o1.getBlurType(), o2.getBlurType());
assertEquals(o1.getOffsetX(), o2.getOffsetX(), 0.001, msg + "DropShadow.offsetX");
assertEquals(o1.getOffsetY(), o2.getOffsetY(), 0.001, msg + "DropShadow.offsety");
assertEquals(o1.getSpread(), o2.getSpread(), 0.001, msg + "DropShadow.spread");
assertEquals(o1.getRadius(), o2.getRadius(), 0.001, msg + "DropShadow.radius");
checkColor(o1.getColor(), o2.getColor(), msg + "DropShadow");
assertEquals(o1.getBlurType(), o2.getBlurType(), msg + "DropShadow.blurType");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 @@ -26,14 +26,14 @@
package test.com.sun.javafx.css;

import com.sun.javafx.css.ParsedValueImpl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import javafx.css.ParsedValue;
import javafx.css.SizeUnits;
import javafx.css.StyleConverter;
import javafx.scene.text.Font;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import javafx.css.converter.EnumConverter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 Down Expand Up @@ -32,8 +32,9 @@
import javafx.css.SizeUnits;
import javafx.css.SizeUnitsShim;
import javafx.scene.text.Font;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class FontSizeTypeTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, 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 Down Expand Up @@ -38,12 +38,19 @@
import javafx.collections.ObservableSet;
import javafx.collections.SetChangeListener;
import javafx.css.PseudoClass;
import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
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.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
*
Expand All @@ -70,21 +77,21 @@ public class PseudoClassTest {
* that happen to use a broken pseudo-class instance to fail undeterministically,
* depending on whether or not they are executed before or after this class.
*/
@BeforeClass
public static void beforeClass() {
@BeforeAll
public static void beforeAll() {
initialPseudoClassMap = new HashMap<>(PseudoClassStateShim.pseudoClassMap);
initialPseudoClasses = new ArrayList<>(PseudoClassStateShim.pseudoClasses);
}

@AfterClass
public static void afterClass() {
@AfterAll
public static void afterAll() {
PseudoClassStateShim.pseudoClassMap.clear();
PseudoClassStateShim.pseudoClassMap.putAll(initialPseudoClassMap);
PseudoClassStateShim.pseudoClasses.clear();
PseudoClassStateShim.pseudoClasses.addAll(initialPseudoClasses);
}

@Before
@BeforeEach
public void before() {
PseudoClassStateShim.pseudoClassMap.clear();
PseudoClassStateShim.pseudoClasses.clear();
Expand Down Expand Up @@ -771,13 +778,13 @@ public void testPseudoClassState_toString() {
while(iter.hasNext()) {

iterations += 1;
assertTrue (iterations+">"+pseudoClasses.length, iterations <= pseudoClasses.length);
assertTrue (iterations <= pseudoClasses.length, iterations+">"+pseudoClasses.length);

PseudoClass pseudoClass = iter.next();
assertEquals (pseudoClass, pseudoClasses[iterations-1]);
}

assertTrue (pseudoClasses.length+"!="+iterations, pseudoClasses.length == iterations);
assertTrue (pseudoClasses.length == iterations, pseudoClasses.length+"!="+iterations);

}

Expand All @@ -796,13 +803,13 @@ public void testPseudoClassState_toString() {
while(iter.hasNext()) {

iterations += 1;
assertTrue (iterations+">"+pseudoClasses.length, iterations <= pseudoClasses.length);
assertTrue (iterations <= pseudoClasses.length, iterations+">"+pseudoClasses.length);

PseudoClass pseudoClass = iter.next();
assertEquals (pseudoClass, pseudoClasses[iterations-1]);
}

assertTrue (pseudoClasses.length+"!="+iterations, pseudoClasses.length == iterations);
assertTrue (pseudoClasses.length == iterations, pseudoClasses.length+"!="+iterations);

}

Expand Down Expand Up @@ -830,7 +837,7 @@ public void testPseudoClassState_toString() {
}
}

assertTrue (nPseudoClasses+"!="+BitSetShim.size(states), nPseudoClasses == BitSetShim.size(states));
assertTrue (nPseudoClasses == BitSetShim.size(states), nPseudoClasses+"!="+BitSetShim.size(states));

}

Expand Down Expand Up @@ -858,7 +865,7 @@ public void testPseudoClassState_toString() {
}
}

assertTrue (nPseudoClasses+"!="+BitSetShim.size(states), nPseudoClasses == BitSetShim.size(states));
assertTrue (nPseudoClasses == BitSetShim.size(states), nPseudoClasses+"!="+BitSetShim.size(states));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 @@ -26,16 +26,15 @@
package test.com.sun.javafx.css;

import com.sun.javafx.css.ParsedValueImpl;
import static org.junit.Assert.assertEquals;

import javafx.css.ParsedValue;
import javafx.css.Size;
import javafx.css.SizeUnits;
import javafx.css.StyleConverter;
import javafx.scene.text.Font;

import org.junit.Test;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class SizeTypeTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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 Down Expand Up @@ -30,22 +30,23 @@
import javafx.css.ParsedValue;
import javafx.css.StyleConverter;
import javafx.scene.text.Font;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class StringTypeTest {

public StringTypeTest() {
}

@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
}

@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
}

Expand Down
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 Down Expand Up @@ -43,9 +43,6 @@
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;

import java.net.URL;
import java.util.ArrayList;
Expand All @@ -55,7 +52,14 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.junit.Assert.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
*
Expand All @@ -75,12 +79,12 @@ private static void resetStyleManager() {
sm.set_hasDefaultUserAgentStylesheet(false);
}

@Before
@BeforeEach
public void setUp() {
resetStyleManager();
}

@AfterClass
@AfterAll
public static void cleanupOnce() {
resetStyleManager();
}
Expand Down Expand Up @@ -1109,7 +1113,7 @@ public void testConcurrentAccess() {
fail("Unexpected exception waiting for threads to finish");
}

assertFalse("Exception during CSS processing on BG thread", err.get());
assertFalse(err.get(), "Exception during CSS processing on BG thread");
}

@Test
Expand Down
Loading

0 comments on commit 1834fcd

Please sign in to comment.