Issue #23507 Fixed mistakes spotted in my own review
- formatting
- trivialities
- renamed AppTest to JavaEETransactionManagerTest (it tests behavior of the class)
diff --git a/appserver/admin/admin-core/src/test/java/com/sun/enterprise/admin/tests/UpgradeTest.java b/appserver/admin/admin-core/src/test/java/com/sun/enterprise/admin/tests/UpgradeTest.java
index 295501c..6567ae6 100644
--- a/appserver/admin/admin-core/src/test/java/com/sun/enterprise/admin/tests/UpgradeTest.java
+++ b/appserver/admin/admin-core/src/test/java/com/sun/enterprise/admin/tests/UpgradeTest.java
@@ -76,7 +76,7 @@
@BeforeEach
public void setup() {
System.clearProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY);
- locator.getService(StartupContext.class).getArguments().clear();
+ startupContext.getArguments().clear();
Domain domain = locator.getService(Domain.class);
assertNotNull(domain);
diff --git a/appserver/admingui/core/src/test/java/org/glassfish/admingui/handlers/WoodstockHandlerTest.java b/appserver/admingui/core/src/test/java/org/glassfish/admingui/handlers/WoodstockHandlerTest.java
index 11d5887..9f119a6 100644
--- a/appserver/admingui/core/src/test/java/org/glassfish/admingui/handlers/WoodstockHandlerTest.java
+++ b/appserver/admingui/core/src/test/java/org/glassfish/admingui/handlers/WoodstockHandlerTest.java
@@ -19,13 +19,13 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
public class WoodstockHandlerTest {
@Test
public void testMessageForNullName() {
- assertNotNull(WoodstockHandler.prepareFileNotDeletedMessage(null));
+ var actual = WoodstockHandler.prepareFileNotDeletedMessage(null);
+ assertEquals("file Couldn't be found at null, proceeding execution without deletion.", actual);
}
diff --git a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandlerTest.java b/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandlerTest.java
index 612e660..73c5155 100644
--- a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandlerTest.java
+++ b/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandlerTest.java
@@ -78,6 +78,9 @@
@AfterEach
public void shutdown() {
+ if (Globals.getStaticBaseServiceLocator() != null) {
+ Globals.getStaticBaseServiceLocator().shutdown();
+ }
if (registry != null) {
registry.shutdown();
}
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java
index aa8a03c..e528ef1 100644
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java
@@ -22,6 +22,7 @@
import com.sun.enterprise.v3.common.PropsFileActionReporter;
import com.sun.logging.LogDomains;
+import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
@@ -43,12 +44,13 @@
import jakarta.inject.Inject;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- *
* @author Jennifer
*/
@ExtendWith(JdbcAdminJunit5Extension.class)
@@ -99,7 +101,7 @@
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
- assertEquals(origNum, list.size());
+ assertThat(list, hasSize(origNum));
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -125,7 +127,7 @@
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
- assertEquals(origNum, list.size());
+ assertThat(list, hasSize(origNum));
// Check the exit code is Success
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -169,7 +171,7 @@
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
- assertEquals(origNum + 1, list.size());
+ assertThat(list, hasSize(origNum + 1));
List<String> listStr = new java.util.ArrayList();
for (MessagePart mp : list) {
@@ -240,9 +242,9 @@
}
}
- assertEquals(numResources, list.size());
+ assertThat(list, hasSize(origNum));
- List<String> listStr = new java.util.ArrayList();
+ List<String> listStr = new ArrayList<>();
for (MessagePart mp : list) {
listStr.add(mp.getMessage());
}
@@ -272,7 +274,7 @@
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
- assertEquals(0, list.size());
+ assertThat(list, hasSize(0));
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
@@ -293,7 +295,7 @@
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
- assertEquals(1, list.size());
+ assertThat(list, hasSize(1));
for (MessagePart mp : list) {
assertEquals("Usage: list-jdbc-resources [target] ", mp.getMessage());
diff --git a/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/AppTest.java b/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/JavaEETransactionManagerTest.java
similarity index 89%
rename from appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/AppTest.java
rename to appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/JavaEETransactionManagerTest.java
index b716890..32ff933 100644
--- a/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/AppTest.java
+++ b/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/JavaEETransactionManagerTest.java
@@ -28,7 +28,6 @@
import com.sun.enterprise.transaction.TransactionServiceConfigListener;
import com.sun.enterprise.transaction.TransactionSynchronizationRegistryImpl;
import com.sun.enterprise.transaction.UserTransactionImpl;
-import com.sun.enterprise.transaction.api.JavaEETransactionManager;
import com.sun.enterprise.transaction.spi.JavaEETransactionManagerDelegate;
import java.beans.PropertyChangeEvent;
import javax.transaction.xa.XAException;
@@ -65,9 +64,9 @@
/**
* Unit test for simple App.
*/
-public class AppTest {
+public class JavaEETransactionManagerTest {
- private JavaEETransactionManager txManager;
+ private JavaEETransactionManagerSimplified txManager;
@BeforeEach
public void setUp() {
@@ -84,7 +83,7 @@
public void testReplaceDelegate() {
JavaEETransactionManagerDelegate d = new JavaEETransactionManagerSimplifiedDelegate();
txManager.setDelegate(d);
- assertFalse(((JavaEETransactionManagerSimplified)txManager).isDelegate(d));
+ assertFalse(txManager.isDelegate(d));
}
/**
@@ -853,183 +852,183 @@
static class TestResource implements XAResource {
- // allow only one resource in use at a time
- private boolean inUse;
- private boolean _forgetCalled = false;
- private boolean _isHeuristic = false;
+ // allow only one resource in use at a time
+ private boolean inUse;
+ private boolean _forgetCalled = false;
+ private boolean _isHeuristic = false;
- private int commitErrorCode = 9999;
- private int rollbackErrorCode = 9999;
- private int prepareErrorCode = 9999;
- private int startErrorCode = 9999;
+ private int commitErrorCode = 9999;
+ private int rollbackErrorCode = 9999;
+ private int prepareErrorCode = 9999;
+ private int startErrorCode = 9999;
- private Transaction tx;
- private int commit_status = -1;
- private int rollback_status = -1;
- private int prepare_status = -1;
+ private Transaction tx;
+ private int commit_status = -1;
+ private int rollback_status = -1;
+ private int prepare_status = -1;
- private static long id0 = System.currentTimeMillis();
- private long id = ++id0;
+ private static long id0 = System.currentTimeMillis();
+ private long id = ++id0;
- TestResource() {}
+ TestResource() {}
- TestResource(Transaction tx) {
- this.tx = tx;
+ TestResource(Transaction tx) {
+ this.tx = tx;
- }
+ }
- TestResource(Transaction tx, long id) {
- this.tx = tx;
- this.id = id;
- }
+ TestResource(Transaction tx, long id) {
+ this.tx = tx;
+ this.id = id;
+ }
- // to test different xaexception error codes
- public void setCommitErrorCode(int errorCode) {
- this.commitErrorCode = errorCode;
- setHeuristic(errorCode);
- }
+ // to test different xaexception error codes
+ public void setCommitErrorCode(int errorCode) {
+ this.commitErrorCode = errorCode;
+ setHeuristic(errorCode);
+ }
- public void setStartErrorCode(int errorCode) {
- this.startErrorCode = errorCode;
- }
+ public void setStartErrorCode(int errorCode) {
+ this.startErrorCode = errorCode;
+ }
- public void setRollbackErrorCode(int errorCode) {
- this.rollbackErrorCode = errorCode;
- setHeuristic(errorCode);
- }
+ public void setRollbackErrorCode(int errorCode) {
+ this.rollbackErrorCode = errorCode;
+ setHeuristic(errorCode);
+ }
- public void setPrepareErrorCode(int errorCode) {
- this.prepareErrorCode = errorCode;
- }
+ public void setPrepareErrorCode(int errorCode) {
+ this.prepareErrorCode = errorCode;
+ }
- private void setHeuristic(int errorCode) {
- if (errorCode == XAException.XA_HEURCOM ||
+ private void setHeuristic(int errorCode) {
+ if (errorCode == XAException.XA_HEURCOM ||
errorCode == XAException.XA_HEURHAZ ||
errorCode == XAException.XA_HEURMIX ||
errorCode == XAException.XA_HEURRB) {
- _isHeuristic = true;
- }
- }
-
- @Override
- public void commit(Xid xid, boolean onePhase) throws XAException{
- // test goes here
- System.out.println("in XA commit");
- commit_status = getStatus("COMMIT");
- if (commitErrorCode != 9999) {
- System.out.println("throwing XAException." + commitErrorCode + " during commit of " + (onePhase? "1" : "2") + "pc");
- throw new XAException(commitErrorCode);
+ _isHeuristic = true;
+ }
}
- }
- @Override
- public boolean isSameRM(XAResource xaresource)
- throws XAException {
- return xaresource == this || this.id == ((TestResource)xaresource).id;
- }
-
-
- @Override
- public void rollback(Xid xid)
- throws XAException {
- System.out.println("in XA rollback");
- rollback_status = getStatus("ROLLBACK");
- if (rollbackErrorCode != 9999) {
- System.out.println("throwing XAException." + rollbackErrorCode + " during rollback" );
- throw new XAException(rollbackErrorCode);
+ @Override
+ public void commit(Xid xid, boolean onePhase) throws XAException{
+ // test goes here
+ System.out.println("in XA commit");
+ commit_status = getStatus("COMMIT");
+ if (commitErrorCode != 9999) {
+ System.out.println("throwing XAException." + commitErrorCode + " during commit of " + (onePhase? "1" : "2") + "pc");
+ throw new XAException(commitErrorCode);
+ }
}
- }
- @Override
- public int prepare(Xid xid)
+ @Override
+ public boolean isSameRM(XAResource xaresource)
throws XAException {
- System.out.println("in XA prepare");
- prepare_status = getStatus("PREPARE");
- if (prepareErrorCode != 9999) {
- System.out.println("throwing XAException." + prepareErrorCode + " during prepare" );
- throw new XAException(prepareErrorCode);
+ return xaresource == this || this.id == ((TestResource)xaresource).id;
}
- return XAResource.XA_OK;
- }
- @Override
- public boolean setTransactionTimeout(int i)
+
+ @Override
+ public void rollback(Xid xid)
throws XAException {
- return true;
- }
+ System.out.println("in XA rollback");
+ rollback_status = getStatus("ROLLBACK");
+ if (rollbackErrorCode != 9999) {
+ System.out.println("throwing XAException." + rollbackErrorCode + " during rollback" );
+ throw new XAException(rollbackErrorCode);
+ }
+ }
- @Override
- public int getTransactionTimeout()
+ @Override
+ public int prepare(Xid xid)
+ throws XAException {
+ System.out.println("in XA prepare");
+ prepare_status = getStatus("PREPARE");
+ if (prepareErrorCode != 9999) {
+ System.out.println("throwing XAException." + prepareErrorCode + " during prepare" );
+ throw new XAException(prepareErrorCode);
+ }
+ return XAResource.XA_OK;
+ }
+
+ @Override
+ public boolean setTransactionTimeout(int i)
+ throws XAException {
+ return true;
+ }
+
+ @Override
+ public int getTransactionTimeout()
throws XAException {
return 0;
}
- @Override
- public void forget(Xid xid)
+ @Override
+ public void forget(Xid xid)
throws XAException {
_forgetCalled = true;
inUse = false;
}
- @Override
- public void start(Xid xid, int flags)
+ @Override
+ public void start(Xid xid, int flags)
throws XAException {
- if (inUse) {
+ if (inUse) {
throw new XAException(XAException.XAER_NOTA);
}
- inUse = true;
- if (startErrorCode != 9999) {
+ inUse = true;
+ if (startErrorCode != 9999) {
System.out.println("throwing XAException." + startErrorCode + " during start" );
throw new XAException(startErrorCode);
- }
- }
-
-
- @Override
- public void end(Xid xid, int flags)
- throws XAException {
- inUse = false;
+ }
}
- @Override
- public Xid[] recover(int flags)
+ @Override
+ public void end(Xid xid, int flags)
+ throws XAException {
+ inUse = false;
+ }
+
+
+ @Override
+ public Xid[] recover(int flags)
throws XAException {
return null;
}
- public boolean forgetCalled() {
+ public boolean forgetCalled() {
return !_isHeuristic || _forgetCalled;
- }
+ }
- public boolean commitStatusOK() {
+ public boolean commitStatusOK() {
return commit_status==Status.STATUS_COMMITTING;
- }
+ }
- public boolean rollbackStatusOK() {
+ public boolean rollbackStatusOK() {
return rollback_status==Status.STATUS_ROLLING_BACK;
- }
+ }
- public boolean prepareStatusOK() {
+ public boolean prepareStatusOK() {
return prepare_status==Status.STATUS_PREPARING;
- }
+ }
- public boolean isAssociated() {
+ public boolean isAssociated() {
return inUse;
- }
+ }
- private int getStatus(String name) {
- int status = -1;
- try {
- if (tx != null) {
- status = tx.getStatus();
- System.out.println("Status in " + name + ": " + JavaEETransactionManagerSimplified.getStatusAsString(status));
+ private int getStatus(String name) {
+ int status = -1;
+ try {
+ if (tx != null) {
+ status = tx.getStatus();
+ System.out.println("Status in " + name + ": " + JavaEETransactionManagerSimplified.getStatusAsString(status));
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return status;
- }
+ return status;
+ }
}
@@ -1038,48 +1037,48 @@
private static PoolManagerImpl poolMgr = new PoolManagerImpl();
public TestResourceHandle(XAResource resource) {
- super(null,new ResourceSpec("testResource",0) ,null,null);
- this.resource = resource;
+ super(null,new ResourceSpec("testResource",0) ,null,null);
+ this.resource = resource;
}
@Override
public boolean isTransactional() {
- return true;
+ return true;
}
@Override
public boolean isShareable() {
- return true;
+ return true;
}
@Override
public boolean supportsXA() {
- return true;
+ return true;
}
@Override
public ResourceAllocator getResourceAllocator() {
- return null;
+ return null;
}
@Override
public Object getResource() {
- return resource;
+ return resource;
}
@Override
public XAResource getXAResource() {
- return resource;
+ return resource;
}
@Override
public Object getUserConnection() {
- return null;
+ return null;
}
@Override
public ClientSecurityInfo getClientSecurityInfo() {
- return null;
+ return null;
}
@Override
@@ -1091,5 +1090,4 @@
poolMgr.resourceEnlisted(tran, this);
}
}
-
}
diff --git a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java
index f62c271..704ef88 100644
--- a/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java
+++ b/nucleus/admin/config-api/src/test/java/com/sun/enterprise/configapi/tests/UnprocessedEventsTest.java
@@ -52,8 +52,7 @@
@Inject
private ServiceLocator locator;
@Inject
- private NetworkConfig service
- ;
+ private NetworkConfig service;
private UnprocessedChangeEvents unprocessed;
@Test
diff --git a/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConfigViewWrapper.java b/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConfigViewWrapper.java
index 43d5f85..8a47bd3 100644
--- a/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConfigViewWrapper.java
+++ b/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConfigViewWrapper.java
@@ -58,7 +58,7 @@
@Override
public ConfigView getMasterView() {
- return masterView; //To change body of implemented methods use File | Settings | File Templates.
+ return masterView;
}
@Override
@@ -73,14 +73,13 @@
@Override
public <T extends ConfigBeanProxy> T getProxy(Class<T> proxyType) {
- return proxyType.cast(Proxy.newProxyInstance(proxyType.getClassLoader(), new Class[]{proxyType},
- this));
+ return proxyType.cast(Proxy.newProxyInstance(proxyType.getClassLoader(), new Class[] {proxyType}, this));
}
static ServiceLocator habitat;
public static void setHabitat(ServiceLocator h) {
- habitat = h;
+ habitat = h;
}
/**
@@ -89,24 +88,23 @@
* @param propName The property name to resolve. ex. ${ALIAS=aliasname}.
* @return The aliasname or null.
*/
- static public String getAlias(String propName)
- {
- String aliasName=null;
- String starter = "${" + ALIAS_TOKEN + "="; //no space is allowed in starter
- String ender = "}";
+ static public String getAlias(String propName) {
+ String aliasName = null;
+ String starter = "${" + ALIAS_TOKEN + "="; // no space is allowed in starter
+ String ender = "}";
propName = propName.trim();
- if (propName.startsWith(starter) && propName.endsWith(ender) ) {
- propName = propName.substring(starter.length() );
+ if (propName.startsWith(starter) && propName.endsWith(ender)) {
+ propName = propName.substring(starter.length());
int lastIdx = propName.length() - 1;
if (lastIdx > 1) {
- propName = propName.substring(0,lastIdx);
- if (propName!=null) {
- aliasName = propName.trim();
- }
+ propName = propName.substring(0, lastIdx);
+ if (propName != null) {
+ aliasName = propName.trim();
+ }
}
}
return aliasName;
- }
+ }
}
diff --git a/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConnector.java b/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConnector.java
index 71f1f67..083a7aa 100644
--- a/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConnector.java
+++ b/nucleus/hk2/hk2-config/src/test/java/org/jvnet/hk2/config/test/example/SimpleConnector.java
@@ -77,11 +77,13 @@
*/
void setPort(String value) throws PropertyVetoException;
- @Element EjbContainerAvailability getEjbContainerAvailability();
+ @Element
+ EjbContainerAvailability getEjbContainerAvailability();
void setEjbContainerAvailability(EjbContainerAvailability v);
- @Element WebContainerAvailability getWebContainerAvailability();
+ @Element
+ WebContainerAvailability getWebContainerAvailability();
void setWebContainerAvailability(WebContainerAvailability v);