Cleanup formatting and update to junit5 testing
git-svn-id: https://svn.apache.org/repos/asf/turbine/fulcrum/trunk/factory@1851033 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f55c121..f58ffcb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -26,6 +26,9 @@
<body>
<release version="1.1.1" date="in SVN">
<action dev="painter" type="update">
+ Update to junit 5 test cases
+ </action>
+ <action dev="painter" type="update">
Addressed all PMD static code analyzer issues and corrected where appropriate
</action>
<action dev="painter" type="update">
diff --git a/src/java/org/apache/fulcrum/factory/DefaultFactoryService.java b/src/java/org/apache/fulcrum/factory/DefaultFactoryService.java
index 69532f0..3fd26a6 100644
--- a/src/java/org/apache/fulcrum/factory/DefaultFactoryService.java
+++ b/src/java/org/apache/fulcrum/factory/DefaultFactoryService.java
@@ -45,8 +45,7 @@
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
* @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
- * @version $Id: DefaultFactoryService.java 1844842 2018-10-25 15:33:42Z painter
- * $
+ * @version $Id$
*
*/
public class DefaultFactoryService extends AbstractLogEnabled
@@ -247,7 +246,8 @@
* @throws FactoryException if test fails.
*/
@Override
- public boolean isLoaderSupported(String className) throws FactoryException {
+ public boolean isLoaderSupported(String className) throws FactoryException
+ {
Factory<?> factory = getFactory(className);
return factory != null ? factory.isLoaderSupported() : true;
}
@@ -261,7 +261,8 @@
* @throws FactoryException if instantiation fails.
*/
@Override
- public <T> T getInstance(Class<T> clazz) throws FactoryException {
+ public <T> T getInstance(Class<T> clazz) throws FactoryException
+ {
try {
return clazz.newInstance();
} catch (Exception x) {
@@ -281,7 +282,9 @@
* @return the instance
* @throws FactoryException if instantiation fails.
*/
- protected <T> T getInstance(Class<T> clazz, Object params[], String signature[]) throws FactoryException {
+ protected <T> T getInstance(Class<T> clazz, Object params[], String signature[])
+ throws FactoryException
+ {
/* Try to construct. */
try {
Class<?>[] sign = getSignature(clazz, params, signature);
@@ -303,7 +306,8 @@
* @throws ClassNotFoundException if any of the classes is not found.
*/
@Override
- public Class<?>[] getSignature(Class<?> clazz, Object params[], String signature[]) throws ClassNotFoundException
+ public Class<?>[] getSignature(Class<?> clazz, Object params[], String signature[])
+ throws ClassNotFoundException
{
if (signature != null) {
/* We have parameters. */
@@ -568,7 +572,8 @@
* Avalon component lifecycle method Clear lists and maps
*/
@Override
- public void dispose() {
+ public void dispose()
+ {
objectFactories.clear();
objectFactoryClasses.clear();
classLoaders.clear();
diff --git a/src/test/org/apache/fulcrum/factory/FactoryServiceTest.java b/src/test/org/apache/fulcrum/factory/FactoryServiceTest.java
index 1a85700..c2b04c7 100644
--- a/src/test/org/apache/fulcrum/factory/FactoryServiceTest.java
+++ b/src/test/org/apache/fulcrum/factory/FactoryServiceTest.java
@@ -1,5 +1,7 @@
package org.apache.fulcrum.factory;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,11 +22,14 @@
*/
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.ArrayList;
-import org.apache.fulcrum.testcontainer.BaseUnitTest;
-import org.junit.Before;
-import org.junit.Test;
+import org.apache.fulcrum.testcontainer.BaseUnit5Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Basic tests of the fulcrum factory service
@@ -34,25 +39,17 @@
*
* @version $Id$
*/
-public class FactoryServiceTest extends BaseUnitTest
+public class FactoryServiceTest extends BaseUnit5Test
{
+ /** Default factory service **/
private FactoryService factoryService = null;
-
- /**
- * Defines the testcase name for JUnit.
- *
- * @param name the testcase's name.
- */
- public FactoryServiceTest(String name)
- {
- super(name);
- }
- @Before
+ @BeforeEach
public void setUp() throws Exception
{
- super.setUp();
- factoryService = (FactoryService) this.resolve( FactoryService.class.getName() );
+ setConfigurationFileName("src/test/TestComponentConfig.xml");
+ setRoleFileName("src/test/TestRoleConfig.xml");
+ factoryService = (FactoryService) this.lookup(FactoryService.class.getName());
}
/**
@@ -151,6 +148,6 @@
signature[0] = "java.lang.Integer";
results = factoryService.getSignature(ArrayList.class, params, signature);
assertEquals(1, results.length);
- assertTrue("Result:" + results[0].getName(),results[0].equals(Integer.class));
+ assertTrue(results[0].equals(Integer.class));
}
}
diff --git a/src/test/org/apache/fulcrum/factory/utils/ObjectInputStreamForContextTest.java b/src/test/org/apache/fulcrum/factory/utils/ObjectInputStreamForContextTest.java
index e533e03..a08ace0 100644
--- a/src/test/org/apache/fulcrum/factory/utils/ObjectInputStreamForContextTest.java
+++ b/src/test/org/apache/fulcrum/factory/utils/ObjectInputStreamForContextTest.java
@@ -1,5 +1,7 @@
package org.apache.fulcrum.factory.utils;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -23,8 +25,9 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
-import org.apache.fulcrum.testcontainer.BaseUnitTest;
-import org.junit.Test;
+import org.apache.fulcrum.testcontainer.BaseUnit5Test;
+import org.junit.jupiter.api.Test;
+
/**
* Basic test for object input stream for fulcrum factory
@@ -32,18 +35,8 @@
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @version $Id$
*/
-public class ObjectInputStreamForContextTest extends BaseUnitTest
+public class ObjectInputStreamForContextTest extends BaseUnit5Test
{
-
- /**
- * Defines the testcase name for JUnit.
- *
- * @param name the testcase's name.
- */
- public ObjectInputStreamForContextTest(String name)
- {
- super(name);
- }
/**
*