Skip to content

Commit

Permalink
fix jakartaee#267, migrating JUnit 4 to JUnit 5
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Santos Izaguirre <[email protected]>
  • Loading branch information
antoniosanct committed Feb 16, 2024
1 parent c87d01c commit 77f536f
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 150 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/xml/bind/JAXBIntrospector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -73,7 +73,7 @@ protected JAXBIntrospector() {}
*/
public static Object getValue(Object jaxbElement) {
if (jaxbElement instanceof JAXBElement) {
return ((JAXBElement)jaxbElement).getValue();
return ((JAXBElement<?>)jaxbElement).getValue();
} else {
// assume that class of this instance is
// annotated with @XmlRootElement.
Expand Down
9 changes: 5 additions & 4 deletions jaxb-api-test/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2018, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -30,9 +30,9 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -103,6 +103,7 @@
src/test/resources/logging.properties
</java.util.logging.config.file>
</systemPropertyVariables>
<useModulePath>false</useModulePath>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/**
* Tests for jaxb API.
*/
package jakarta.xml.bind.test;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;

@ParameterizedTest
@CsvFileSource(resources = "/jakarta/xml/bind/test/allScenarios.csv",
numLinesToSkip = 0,
nullValues = "**")
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface JAXBContextOldParameterized {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@

package jakarta.xml.bind.test;

import org.junit.Before;
import org.junit.Test;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBContextFactory;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;

import jakarta.xml.bind.*;
import java.util.Map;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.TestCase.fail;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


/**
* regression test for
Expand Down Expand Up @@ -57,27 +60,27 @@ public Marshaller createMarshaller() throws JAXBException {
public void testContextPath() {
try {
JAXBContext ctx = JAXBContext.newInstance("whatever", ClassLoader.getSystemClassLoader());
assertNotNull("Expected non-null instance to be returned from the test Factory", ctx);
assertEquals("Expected MyContext instance to be returned from the test Factory", MyContext.class, ctx.getClass());
Assertions.assertNotNull(ctx,"Expected non-null instance to be returned from the test Factory");
Assertions.assertEquals(MyContext.class, ctx.getClass(), "Expected MyContext instance to be returned from the test Factory");
} catch (Throwable t) {
t.printStackTrace();
fail("Not expected to fail!");
Assertions.fail("Not expected to fail!");
}
}

@Test
public void testClasses() {
try {
JAXBContext ctx = JAXBContext.newInstance(new Class[0]);
assertNotNull("Expected non-null instance to be returned from the test Factory", ctx);
assertEquals("Expected MyContext instance to be returned from the test Factory", MyContext.class, ctx.getClass());
JAXBContext ctx = JAXBContext.newInstance(new Class<?>[0]);
Assertions.assertNotNull(ctx, "Expected non-null instance to be returned from the test Factory");
Assertions.assertEquals(MyContext.class, ctx.getClass(), "Expected MyContext instance to be returned from the test Factory");
} catch (Throwable t) {
t.printStackTrace();
fail("Not expected to fail!");
Assertions.fail("Not expected to fail!");
}
}

@Before
@BeforeEach
public void setup() {
System.setProperty("jakarta.xml.bind.JAXBContextFactory", "jakarta.xml.bind.test.JAXBContextServiceProviderNPETest$Factory");
}
Expand Down
Loading

0 comments on commit 77f536f

Please sign in to comment.