From dfb7d9d25d09e21de9b0ae7b880f7613cc271b96 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Wed, 21 Jun 2023 18:59:52 +0200 Subject: [PATCH] OF-2612: Migrate unit test implementation to JUnit 5 Most unit tests are refactored to use JUnit 5 instead of 4. Notable exceptions: - FlattenNestedGroupsTest, which uses org.zapodot:embedded-ldap-junit which currently is based on JUnit 4 (JUnit 5 support being tracked in https://github.com/zapodot/embedded-ldap-junit/issues/57 ) - DBUnit-based tests --- .../java/dom/io/XMPPPacketReaderTest.java | 52 ++--- .../admin/AuthCheckFilterTest.java | 62 ++++-- .../admin/LoginLimitManagerTest.java | 36 ++-- ...MinderServletRequestAuthenticatorTest.java | 38 +++- .../openfire/OfflineMessageStoreTest.java | 21 +- .../openfire/SessionPacketRouterTest.java | 26 +-- .../admin/GroupBasedAdminProviderTest.java | 30 ++- .../openfire/archive/ArchiverTest.java | 8 +- .../openfire/auth/JDBCAuthProviderTest.java | 47 ++-- .../openfire/carbons/MessageCarbonsTest.java | 19 +- .../openfire/cluster/ClusterMonitorTest.java | 44 ++-- .../openfire/container/PluginManagerTest.java | 8 +- .../EntityCapabilitiesListenerTest.java | 18 +- .../openfire/forward/ForwardTest.java | 20 +- .../group/AbstractGroupProviderTest.java | 5 +- .../group/DefaultGroupProviderTest.java | 8 +- .../openfire/group/GroupJIDTest.java | 23 +- .../openfire/group/GroupManagerTest.java | 45 ++-- .../handler/IQEntityTimeHandlerTest.java | 25 ++- .../openfire/http/HttpSessionDeliverable.java | 19 +- .../keystore/CertificateUtilsTest.java | 55 +++-- .../OpenfireX509TrustManagerTest.java | 59 +++-- .../openfire/ldap/LdapManagerTest.java | 19 +- .../openfire/ldap/VCardTemplateTest.java | 9 +- .../jivesoftware/openfire/ldap/VCardTest.java | 9 +- .../openfire/muc/HistoryStrategyTest.java | 6 +- .../openfire/muc/MUCRoleTest.java | 18 +- .../openfire/muc/MUCRoomTest.java | 16 +- .../openfire/muc/spi/MucPrivilegesTest.java | 40 +++- .../openfire/muc/spi/OccupantManagerTest.java | 19 +- .../openfire/net/DNSUtilTest.java | 86 +++++--- .../nio/XMLLightweightParserTest.java | 8 +- .../nio/XmlNumericCharacterReferenceTest.java | 29 ++- .../openfire/pubsub/CollectionNodeTest.java | 6 +- .../openfire/pubsub/LeafNodeTest.java | 11 +- .../openfire/session/SessionTest.java | 5 +- .../openfire/spi/ConnectionTypeTest.java | 76 ++++--- .../spi/EncryptionArtifactFactoryTest.java | 28 ++- .../openfire/stanzaid/StanzaIDUtilTest.java | 46 ++-- .../streammanagement/StreamManagerTest.java | 6 +- .../openfire/user/UserManagerTest.java | 48 ++--- .../jivesoftware/util/AdminConsoleTest.java | 29 ++- .../jivesoftware/util/AesEncryptorTest.java | 27 ++- .../util/BlowfishEncryptorTest.java | 29 ++- .../org/jivesoftware/util/CacheUtilTest.java | 6 +- .../util/CacheableOptionalTest.java | 21 +- .../util/CertificateManagerTest.java | 29 ++- .../jivesoftware/util/CertificateTest.java | 27 ++- .../util/CollectionUtilsTest.java | 7 +- .../util/EntityCapabilitiesManagerTest.java | 12 +- .../jivesoftware/util/GraphicsUtilsTest.java | 7 +- .../java/org/jivesoftware/util/JIDTest.java | 31 ++- .../util/JavaSpecVersionTest.java | 22 +- .../java/org/jivesoftware/util/LDAPTest.java | 49 +++-- .../org/jivesoftware/util/ListPagerTest.java | 35 ++- .../jivesoftware/util/LocaleUtilsTest.java | 23 +- .../jivesoftware/util/SAXReaderUtilTest.java | 6 +- .../jivesoftware/util/StringUtilsTest.java | 21 +- .../jivesoftware/util/SystemPropertyTest.java | 201 ++++++++++-------- .../org/jivesoftware/util/VersionTest.java | 24 ++- .../jivesoftware/util/WebXmlUtilsTest.java | 19 +- .../jivesoftware/util/XMLPropertiesTest.java | 9 +- .../util/XMPPDateTimeFormatTest.java | 19 +- .../org/jivesoftware/util/XPPWriterTest.java | 8 +- .../cache/DefaultExternalizableUtilTest.java | 10 +- ...LookupComputingCacheEntryListenerTest.java | 20 +- 66 files changed, 1188 insertions(+), 656 deletions(-) diff --git a/xmppserver/src/test/java/dom/io/XMPPPacketReaderTest.java b/xmppserver/src/test/java/dom/io/XMPPPacketReaderTest.java index b40c2e6619..813af0d33f 100644 --- a/xmppserver/src/test/java/dom/io/XMPPPacketReaderTest.java +++ b/xmppserver/src/test/java/dom/io/XMPPPacketReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2017-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ package dom.io; @@ -20,14 +19,15 @@ import org.dom4j.Document; import org.dom4j.Namespace; import org.dom4j.io.XMPPPacketReader; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.xmlpull.v1.XmlPullParser; import java.io.StringReader; import java.util.Set; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests that verify the functionality of {@link XMPPPacketReader} * @@ -37,7 +37,7 @@ public class XMPPPacketReaderTest { private XMPPPacketReader packetReader; - @Before + @BeforeEach public void setup() { packetReader = new XMPPPacketReader(); @@ -61,7 +61,7 @@ public void testStripContentNamespace() throws Exception final Document result = packetReader.read( new StringReader( input ) ); // Verify result. - Assert.assertFalse( result.asXML().contains( "jabber:client" ) ); + assertFalse( result.asXML().contains( "jabber:client" ) ); } /** @@ -82,7 +82,7 @@ public void testStripPrefixFreeCanonicalization() throws Exception final Document result = packetReader.read( new StringReader( input ) ); // Verify result. - Assert.assertFalse( result.asXML().contains( "jabber:client" ) ); + assertFalse( result.asXML().contains( "jabber:client" ) ); } /** @@ -111,8 +111,8 @@ public void testAvoidStrippingInternalContentNamespace() throws Exception final Document result = packetReader.read( new StringReader( input ) ); // Verify result. - Assert.assertFalse( "'jabber:client' should not occur before 'something:else'", result.asXML().substring( 0, result.asXML().indexOf("something:else") ).contains( "jabber:client" ) ); - Assert.assertTrue( "'jabber:client' should occur after 'something:else'", result.asXML().substring( result.asXML().indexOf("something:else") ).contains( "jabber:client" ) ); + assertFalse( result.asXML().substring( 0, result.asXML().indexOf("something:else") ).contains( "jabber:client" ), "'jabber:client' should not occur before 'something:else'" ); + assertTrue( result.asXML().substring( result.asXML().indexOf("something:else") ).contains( "jabber:client" ), "'jabber:client' should occur after 'something:else'" ); } /** @@ -141,8 +141,8 @@ public void testAvoidStrippingPrefixFreeCanonicalization() throws Exception final Document result = packetReader.read( new StringReader( input ) ); // Verify result. - Assert.assertFalse( "'jabber:client' should not occur before 'something:else'", result.asXML().substring( 0, result.asXML().indexOf("something:else") ).contains( "jabber:client" ) ); - Assert.assertTrue( "'jabber:client' should occur after 'something:else'", result.asXML().substring( result.asXML().indexOf("something:else") ).contains( "jabber:client" ) ); + assertFalse( result.asXML().substring( 0, result.asXML().indexOf("something:else") ).contains( "jabber:client" ), "'jabber:client' should not occur before 'something:else'" ); + assertTrue( result.asXML().substring( result.asXML().indexOf("something:else") ).contains( "jabber:client" ), "'jabber:client' should occur after 'something:else'" ); } /** @@ -161,8 +161,8 @@ public void testStripNamespacesForWebsocket() throws Exception final Document result = packetReader.read( new StringReader( input ) ); // Verify result. - Assert.assertFalse( "'jabber:client' should not occur before 'something:else'", result.asXML().substring( 0, result.asXML().indexOf("something:else") ).contains( "jabber:client" ) ); - Assert.assertTrue( "'jabber:client' should occur after 'something:else'", result.asXML().substring( result.asXML().indexOf("something:else") ).contains( "jabber:client" ) ); + assertFalse( result.asXML().substring( 0, result.asXML().indexOf("something:else") ).contains( "jabber:client" ), "'jabber:client' should not occur before 'something:else'" ); + assertTrue( result.asXML().substring( result.asXML().indexOf("something:else") ).contains( "jabber:client" ), "'jabber:client' should occur after 'something:else'" ); } /** @@ -186,8 +186,8 @@ public void test_GetNamespacesOnCurrentElement_CustomNamespace() throws Exceptio final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(1, namespacesOnCurrentElement.size()); - Assert.assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); + assertEquals(1, namespacesOnCurrentElement.size()); + assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); } /** @@ -211,7 +211,7 @@ public void test_GetNamespacesOnCurrentElement_XmlLang() throws Exception final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(0, namespacesOnCurrentElement.size()); + assertEquals(0, namespacesOnCurrentElement.size()); } /** @@ -235,7 +235,7 @@ public void test_GetNamespacesOnCurrentElement_DefaultNamespace() throws Excepti final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(0, namespacesOnCurrentElement.size()); + assertEquals(0, namespacesOnCurrentElement.size()); } /** @@ -260,7 +260,7 @@ public void test_GetNamespacesOnCurrentElement_IgnoredNamespace() throws Excepti final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(0, namespacesOnCurrentElement.size()); + assertEquals(0, namespacesOnCurrentElement.size()); } /** @@ -285,7 +285,7 @@ public void test_GetNamespacesOnCurrentElement_IgnoredStreamNamespace() throws E final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(0, namespacesOnCurrentElement.size()); + assertEquals(0, namespacesOnCurrentElement.size()); } /** @@ -310,8 +310,8 @@ public void test_GetNamespacesOnCurrentElement_MixedNamespace() throws Exception final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(1, namespacesOnCurrentElement.size()); - Assert.assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); + assertEquals(1, namespacesOnCurrentElement.size()); + assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); } /** @@ -337,8 +337,8 @@ public void test_GetNamespacesOnCurrentElement_MixedNamespace_WithChildElement() final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(1, namespacesOnCurrentElement.size()); - Assert.assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); + assertEquals(1, namespacesOnCurrentElement.size()); + assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); } /** @@ -364,7 +364,7 @@ public void test_GetNamespacesOnCurrentElement_MixedNamespace_OnChildElement() t final Set namespacesOnCurrentElement = XMPPPacketReader.getPrefixedNamespacesOnCurrentElement(packetReader.getXPPParser()); // Verify results. - Assert.assertEquals(1, namespacesOnCurrentElement.size()); - Assert.assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); + assertEquals(1, namespacesOnCurrentElement.size()); + assertEquals(Namespace.get("unittest", "custom:namespace"), namespacesOnCurrentElement.iterator().next()); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/admin/AuthCheckFilterTest.java b/xmppserver/src/test/java/org/jivesoftware/admin/AuthCheckFilterTest.java index d5d15a6d1c..1b2948932a 100644 --- a/xmppserver/src/test/java/org/jivesoftware/admin/AuthCheckFilterTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/admin/AuthCheckFilterTest.java @@ -1,31 +1,47 @@ -package org.jivesoftware.admin; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import javax.servlet.FilterChain; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +package org.jivesoftware.admin; import org.jivesoftware.Fixtures; import org.jivesoftware.openfire.admin.AdminManager; import org.jivesoftware.openfire.auth.AuthToken; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import javax.servlet.FilterChain; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import java.util.Collections; import java.util.HashSet; import java.util.Set; -@RunWith(MockitoJUnitRunner.class) +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) public class AuthCheckFilterTest { private static final String adminUser = "test-admin-user"; @@ -39,22 +55,22 @@ public class AuthCheckFilterTest { @Mock private AdminManager adminManager; @Mock private LoginLimitManager loginLimitManager; - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { Fixtures.reconfigureOpenfireHome(); } - @Before + @BeforeEach public void setUp() { Fixtures.clearExistingProperties(); - doReturn("/uri/to/page").when(request).getRequestURI(); - doReturn(httpSession).when(request).getSession(); - doReturn(remoteAddr).when(request).getRemoteAddr(); + lenient().doReturn("/uri/to/page").when(request).getRequestURI(); + lenient().doReturn(httpSession).when(request).getSession(); + lenient().doReturn(remoteAddr).when(request).getRemoteAddr(); - doReturn(true).when(adminManager).isUserAdmin(adminUser, true); - doReturn(false).when(adminManager).isUserAdmin(normalUser, true); + lenient().doReturn(true).when(adminManager).isUserAdmin(adminUser, true); + lenient().doReturn(false).when(adminManager).isUserAdmin(normalUser, true); } diff --git a/xmppserver/src/test/java/org/jivesoftware/admin/LoginLimitManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/admin/LoginLimitManagerTest.java index fe24afaba3..ff81c5951d 100644 --- a/xmppserver/src/test/java/org/jivesoftware/admin/LoginLimitManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/admin/LoginLimitManagerTest.java @@ -1,22 +1,34 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jivesoftware.admin; import org.jivesoftware.openfire.security.SecurityAuditManager; -import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.StringUtils; -import org.jivesoftware.util.SystemProperty; import org.jivesoftware.util.TaskEngine; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Random; +import org.mockito.junit.jupiter.MockitoExtension; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class LoginLimitManagerTest { private LoginLimitManager loginLimitManager; @@ -24,7 +36,7 @@ public class LoginLimitManagerTest { @Mock private SecurityAuditManager securityAuditManager; @Mock private TaskEngine taskEngine; - @Before + @BeforeEach public void setUp() { loginLimitManager = new LoginLimitManager(securityAuditManager, taskEngine); } diff --git a/xmppserver/src/test/java/org/jivesoftware/admin/SiteMinderServletRequestAuthenticatorTest.java b/xmppserver/src/test/java/org/jivesoftware/admin/SiteMinderServletRequestAuthenticatorTest.java index 4d6e12c41b..425f8c0355 100644 --- a/xmppserver/src/test/java/org/jivesoftware/admin/SiteMinderServletRequestAuthenticatorTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/admin/SiteMinderServletRequestAuthenticatorTest.java @@ -1,28 +1,44 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jivesoftware.admin; +import org.jivesoftware.Fixtures; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.servlet.http.HttpServletRequest; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.doReturn; -import javax.servlet.http.HttpServletRequest; - -import org.jivesoftware.Fixtures; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SiteMinderServletRequestAuthenticatorTest { private SiteMinderServletRequestAuthenticator authenticator; @Mock private HttpServletRequest request; - @Before + @BeforeEach public void setUp() throws Exception { Fixtures.reconfigureOpenfireHome(); authenticator = new SiteMinderServletRequestAuthenticator(); diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/OfflineMessageStoreTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/OfflineMessageStoreTest.java index 3032f41ed8..ef3e067de3 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/OfflineMessageStoreTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/OfflineMessageStoreTest.java @@ -1,11 +1,26 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.Message; import org.xmpp.packet.PacketExtension; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * This tests the business rules for storing messages as described in 3. Handling of Message Types. diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/SessionPacketRouterTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/SessionPacketRouterTest.java index 847ce7cfb6..6dd3d1d039 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/SessionPacketRouterTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/SessionPacketRouterTest.java @@ -16,21 +16,21 @@ package org.jivesoftware.openfire; import org.jivesoftware.Fixtures; -import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.LocalClientSession; import org.jivesoftware.openfire.session.Session; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.quality.Strictness; -import org.xmpp.packet.*; +import org.xmpp.packet.JID; +import org.xmpp.packet.Message; +import org.xmpp.packet.Packet; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.*; /** @@ -38,15 +38,15 @@ * * @author Guus der Kinderen, guus.der.kinderen@gmail.com */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SessionPacketRouterTest { - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { Fixtures.reconfigureOpenfireHome(); } - @Before + @BeforeEach public void setUp() { Fixtures.clearExistingProperties(); diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/admin/GroupBasedAdminProviderTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/admin/GroupBasedAdminProviderTest.java index cc13b96751..f0f3affb19 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/admin/GroupBasedAdminProviderTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/admin/GroupBasedAdminProviderTest.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.admin; import org.jivesoftware.Fixtures; @@ -7,9 +22,9 @@ import org.jivesoftware.openfire.group.GroupNotFoundException; import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.cache.CacheFactory; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.xmpp.packet.JID; import java.util.Arrays; @@ -18,6 +33,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -29,12 +45,12 @@ public class GroupBasedAdminProviderTest { private GroupBasedAdminProvider adminProvider; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { Fixtures.reconfigureOpenfireHome(); } - @Before + @BeforeEach public void setUp() throws Exception { Fixtures.clearExistingProperties(); CacheFactory.initialize(); @@ -64,10 +80,10 @@ public void willReturnEmptyListIfGroupIsNotFound() { assertThat(admins, is(Collections.emptyList())); } - @Test(expected = UnsupportedOperationException.class) + @Test public void willNotSetTheListOfAdmins() { assertThat(adminProvider.isReadOnly(), is(true)); - adminProvider.setAdmins(ADMINS); + assertThrows(UnsupportedOperationException.class, () -> adminProvider.setAdmins(ADMINS)); } public static class TestGroupProvider extends DefaultGroupProvider { diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/archive/ArchiverTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/archive/ArchiverTest.java index 757ea4f555..9a29923432 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/archive/ArchiverTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/archive/ArchiverTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2018-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package org.jivesoftware.openfire.archive; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.Duration; import java.time.Instant; @@ -24,9 +24,7 @@ import java.util.List; import java.util.Map; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.*; /** * Tests that verify the implementation of {@link Archiver} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/auth/JDBCAuthProviderTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/auth/JDBCAuthProviderTest.java index a8aa36025f..bc1a3e946c 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/auth/JDBCAuthProviderTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/auth/JDBCAuthProviderTest.java @@ -1,9 +1,26 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.auth; -import java.util.HashMap; import org.bouncycastle.crypto.generators.OpenBSDBCrypt; -import org.junit.Test; -import static org.junit.Assert.*; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.*; public class JDBCAuthProviderTest { @@ -27,53 +44,53 @@ private void setPasswordTypes(final String passwordTypes) { @Test public void hashPassword() throws Exception { - assertTrue(MD5_PASSWORD.equals(jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.md5))); - assertTrue(SHA1_PASSWORD.equals(jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.sha1))); - assertTrue(SHA256_PASSWORD.equals(jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.sha256))); - assertTrue(SHA512_PASSWORD.equals(jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.sha512))); - assertFalse(BCRYPTED_PASSWORD.equals(jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.bcrypt))); + assertEquals(MD5_PASSWORD, jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.md5)); + assertEquals(SHA1_PASSWORD, jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.sha1)); + assertEquals(SHA256_PASSWORD, jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.sha256)); + assertEquals(SHA512_PASSWORD, jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.sha512)); + assertNotEquals(BCRYPTED_PASSWORD, jdbcAuthProvider.hashPassword(PASSWORD, JDBCAuthProvider.PasswordType.bcrypt)); assertTrue(OpenBSDBCrypt.checkPassword(BCRYPTED_PASSWORD, PASSWORD.toCharArray())); } @Test public void comparePasswords_sha256() throws Exception { setPasswordTypes("sha256"); - assertTrue("password should be sha256", jdbcAuthProvider.comparePasswords(PASSWORD, SHA256_PASSWORD)); + assertTrue(jdbcAuthProvider.comparePasswords(PASSWORD, SHA256_PASSWORD), "password should be sha256"); } @Test public void comparePasswords_bcrypt() throws Exception { setPasswordTypes("bcrypt"); - assertTrue("password should be bcrypted", jdbcAuthProvider.comparePasswords(PASSWORD, BCRYPTED_PASSWORD)); + assertTrue(jdbcAuthProvider.comparePasswords(PASSWORD, BCRYPTED_PASSWORD), "password should be bcrypted"); } @Test public void comparePasswords_bcryptLast() throws Exception { setPasswordTypes("bcrypt,md5,plain"); - assertTrue("should ignore everything beyond bcrypt", jdbcAuthProvider.comparePasswords(PASSWORD, BCRYPTED_PASSWORD)); + assertTrue(jdbcAuthProvider.comparePasswords(PASSWORD, BCRYPTED_PASSWORD), "should ignore everything beyond bcrypt"); } @Test public void comparePasswords_ignoreUnknownDefaultPlain() throws Exception { setPasswordTypes("blowfish,puckerfish,rainbowtrout"); - assertTrue("should passively ignore unknown, add plain if empty", jdbcAuthProvider.comparePasswords(PASSWORD, PASSWORD)); + assertTrue(jdbcAuthProvider.comparePasswords(PASSWORD, PASSWORD), "should passively ignore unknown, add plain if empty"); } @Test public void comparePasswords_md5_sha1() throws Exception { setPasswordTypes("md5,sha1"); - assertTrue("password should be md5 -> sha1", jdbcAuthProvider.comparePasswords(PASSWORD, MD5_SHA1_PASSWORD)); + assertTrue(jdbcAuthProvider.comparePasswords(PASSWORD, MD5_SHA1_PASSWORD), "password should be md5 -> sha1"); } @Test public void comparePasswords_md5_sha512() throws Exception { setPasswordTypes("md5,sha512"); - assertTrue("password should be md5 -> sha512", jdbcAuthProvider.comparePasswords(PASSWORD, MD5_SHA512_PASSWORD)); + assertTrue(jdbcAuthProvider.comparePasswords(PASSWORD, MD5_SHA512_PASSWORD), "password should be md5 -> sha512"); } @Test public void comparePasswords_plain_md5_plain_plain() throws Exception { setPasswordTypes("plain,md5,plain,plain"); - assertTrue("weird password chains are fine", jdbcAuthProvider.comparePasswords(PASSWORD, MD5_PASSWORD)); + assertTrue(jdbcAuthProvider.comparePasswords(PASSWORD, MD5_PASSWORD), "weird password chains are fine"); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/carbons/MessageCarbonsTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/carbons/MessageCarbonsTest.java index 40c9a50256..1909c50c1d 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/carbons/MessageCarbonsTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/carbons/MessageCarbonsTest.java @@ -1,10 +1,25 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.carbons; import org.jivesoftware.openfire.forward.Forwarded; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.Message; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Christian Schudt diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/cluster/ClusterMonitorTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/cluster/ClusterMonitorTest.java index b7698ffbe6..1a3cfaceab 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/cluster/ClusterMonitorTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/cluster/ClusterMonitorTest.java @@ -1,23 +1,35 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.cluster; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; - import org.jivesoftware.Fixtures; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServerInfo; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ClusterMonitorTest { private static final String THIS_HOST_NAME = "test-host-name"; @@ -26,12 +38,12 @@ public class ClusterMonitorTest { @Mock private XMPPServer xmppServer; @Mock private XMPPServerInfo xmppServerInfo; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { Fixtures.reconfigureOpenfireHome(); } - @Before + @BeforeEach public void setUp() { Fixtures.clearExistingProperties(); @@ -39,9 +51,9 @@ public void setUp() { //noinspection deprecation XMPPServer.setInstance(xmppServer); - doReturn(xmppServerInfo).when(xmppServer).getServerInfo(); + lenient().doReturn(xmppServerInfo).when(xmppServer).getServerInfo(); - doReturn(THIS_HOST_NAME).when(xmppServerInfo).getHostname(); + lenient().doReturn(THIS_HOST_NAME).when(xmppServerInfo).getHostname(); clusterMonitor = new ClusterMonitor(); clusterMonitor.initialize(xmppServer); diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/container/PluginManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/container/PluginManagerTest.java index 789ec3550b..d386d073cb 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/container/PluginManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/container/PluginManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ */ package org.jivesoftware.openfire.container; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.BufferedInputStream; import java.io.InputStream; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests that verify the functionality of {@link PluginManager} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/entitycaps/EntityCapabilitiesListenerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/entitycaps/EntityCapabilitiesListenerTest.java index 0efb0ed4aa..560e82d2b9 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/entitycaps/EntityCapabilitiesListenerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/entitycaps/EntityCapabilitiesListenerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2020-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,12 @@ import org.jivesoftware.Fixtures; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.util.cache.CacheFactory; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.xmpp.packet.JID; import java.util.Collections; @@ -35,7 +35,7 @@ * * @author Guus der Kinderen, guus.der.kinderen@gmail.com */ -@RunWith( MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EntityCapabilitiesListenerTest { @Mock @@ -52,13 +52,13 @@ public class EntityCapabilitiesListenerTest private EntityCapabilitiesManager manager; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { Fixtures.reconfigureOpenfireHome(); CacheFactory.initialize(); } - @Before + @BeforeEach public void setupManager() { Fixtures.clearExistingProperties(); diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/forward/ForwardTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/forward/ForwardTest.java index 79df91e260..8631649e33 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/forward/ForwardTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/forward/ForwardTest.java @@ -1,10 +1,26 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jivesoftware.openfire.forward; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.forms.DataForm; import org.xmpp.packet.Message; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Christian Schudt diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/group/AbstractGroupProviderTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/group/AbstractGroupProviderTest.java index 029d8d4d2f..860eaad60c 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/group/AbstractGroupProviderTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/group/AbstractGroupProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2022-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,11 +28,8 @@ import org.xmpp.packet.JID; import java.lang.reflect.Field; -import java.sql.SQLException; import java.util.*; -import static org.junit.Assert.assertThrows; - /** * Unit tests that verify the functionality of {@link AbstractGroupProvider} methods not overridden by the * {@link DefaultGroupProvider}. diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/group/DefaultGroupProviderTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/group/DefaultGroupProviderTest.java index 3f8caea911..753ad8c40d 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/group/DefaultGroupProviderTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/group/DefaultGroupProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2022-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,13 +24,15 @@ import org.jivesoftware.database.DefaultConnectionProvider; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.event.GroupEventDispatcher; -import org.jivesoftware.openfire.event.GroupEventListener; import org.jivesoftware.util.cache.CacheFactory; import org.xmpp.packet.JID; import java.lang.reflect.Field; import java.net.URL; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; import static org.junit.Assert.assertThrows; diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupJIDTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupJIDTest.java index 6d1345523d..134eda53cb 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupJIDTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupJIDTest.java @@ -1,13 +1,26 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.group; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import org.jivesoftware.util.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.JID; +import static org.junit.jupiter.api.Assertions.*; + public class GroupJIDTest { @Test diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupManagerTest.java index 46d5a9294e..6d84fc6d6c 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/group/GroupManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2022-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,35 +15,32 @@ */ package org.jivesoftware.openfire.group; -import static junit.framework.TestCase.fail; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - import org.jivesoftware.Fixtures; import org.jivesoftware.util.CacheableOptional; import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.PersistableMap; import org.jivesoftware.util.cache.Cache; import org.jivesoftware.util.cache.CacheFactory; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +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 org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.xmpp.packet.JID; -@RunWith(MockitoJUnitRunner.class) +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) public class GroupManagerTest { private static final String GROUP_NAME = "test-group-name"; @@ -56,7 +53,7 @@ public class GroupManagerTest { @Mock private Group unCachedGroup; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { Fixtures.reconfigureOpenfireHome(); groupCache = CacheFactory.createCache("Group"); @@ -64,7 +61,7 @@ public static void beforeClass() throws Exception { JiveGlobals.setProperty("provider.group.className", TestGroupProvider.class.getName()); } - @Before + @BeforeEach public void setUp() { // Ensure that Openfire caches are reset before each test to avoid tests to affect each-other. Arrays.stream(CacheFactory.getAllCaches()).forEach(Map::clear); @@ -73,7 +70,7 @@ public void setUp() { groupManager = GroupManager.getInstance(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { // Reset static fields after use (to not confuse other test classes). diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/handler/IQEntityTimeHandlerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/handler/IQEntityTimeHandlerTest.java index 18fa2eb3ca..e13ded8b20 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/handler/IQEntityTimeHandlerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/handler/IQEntityTimeHandlerTest.java @@ -1,9 +1,24 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.handler; import org.dom4j.Element; import org.jivesoftware.util.XMPPDateTimeFormat; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.xmpp.packet.IQ; import javax.xml.bind.DatatypeConverter; @@ -15,8 +30,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author csh @@ -48,7 +63,7 @@ public void testUtcDate() { assertEquals(iqEntityTimeHandler.getUtcDate(date), DatatypeConverter.printDateTime(calendar)); } - @Test @Ignore + @Test @Disabled public void testPerformanceDatatypeConvertVsXMPPDateFormat() { Date date = new Date(); diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/http/HttpSessionDeliverable.java b/xmppserver/src/test/java/org/jivesoftware/openfire/http/HttpSessionDeliverable.java index 337535fb70..89fb3094f4 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/http/HttpSessionDeliverable.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/http/HttpSessionDeliverable.java @@ -1,14 +1,29 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.http; import org.dom4j.QName; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.Message; import org.xmpp.packet.Packet; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Unit tests for {@link HttpSession.Deliverable} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/CertificateUtilsTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/CertificateUtilsTest.java index a8be6229b8..4d6aa7baf7 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/CertificateUtilsTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/CertificateUtilsTest.java @@ -1,12 +1,29 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.keystore; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collection; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Unit tests that verify the functionality of {@link CertificateUtils}. * @@ -28,7 +45,7 @@ public void testFilterValidNull() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertTrue( result.isEmpty() ); + assertTrue( result.isEmpty() ); } /** @@ -45,7 +62,7 @@ public void testFilterValidEmpty() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertTrue( result.isEmpty() ); + assertTrue( result.isEmpty() ); } /** @@ -64,8 +81,8 @@ public void testFilterValidWithOneValidCert() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertEquals( 1, result.size() ); - Assert.assertTrue( result.contains( valid ) ); + assertEquals( 1, result.size() ); + assertTrue( result.contains( valid ) ); } /** @@ -84,7 +101,7 @@ public void testFilterValidWithOneInvalidCert() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertTrue( result.isEmpty() ); + assertTrue( result.isEmpty() ); } /** @@ -104,8 +121,8 @@ public void testFilterValidWithTwoDuplicateValidCerts() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertEquals( 1, result.size() ); - Assert.assertTrue( result.contains( valid ) ); + assertEquals( 1, result.size() ); + assertTrue( result.contains( valid ) ); } /** @@ -126,9 +143,9 @@ public void testFilterValidWithTwoDistinctValidCerts() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertEquals( 2, result.size() ); - Assert.assertTrue( result.contains( validA ) ); - Assert.assertTrue( result.contains( validB ) ); + assertEquals( 2, result.size() ); + assertTrue( result.contains( validA ) ); + assertTrue( result.contains( validB ) ); } /** @@ -148,7 +165,7 @@ public void testFilterValidWithTwoDuplicateInvalidCerts() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertTrue( result.isEmpty() ); + assertTrue( result.isEmpty() ); } /** @@ -169,7 +186,7 @@ public void testFilterValidWithTwoDistinctInvalidCerts() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertTrue( result.isEmpty() ); + assertTrue( result.isEmpty() ); } /** @@ -190,8 +207,8 @@ public void testFilterValidWithValidAndInvalidCerts() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertEquals( 1, result.size() ); - Assert.assertTrue( result.contains( valid ) ); + assertEquals( 1, result.size() ); + assertTrue( result.contains( valid ) ); } /** @@ -220,8 +237,8 @@ public void testFilterValidWithMixOfValidityAndDuplicates() throws Exception final Collection result = CertificateUtils.filterValid( input ); // Verify results. - Assert.assertEquals( 2, result.size() ); - Assert.assertTrue( result.contains( validA ) ); - Assert.assertTrue( result.contains( validB ) ); + assertEquals( 2, result.size() ); + assertTrue( result.contains( validA ) ); + assertTrue( result.contains( validB ) ); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/OpenfireX509TrustManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/OpenfireX509TrustManagerTest.java index 89ee9a48d8..ada2621eae 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/OpenfireX509TrustManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/keystore/OpenfireX509TrustManagerTest.java @@ -1,17 +1,36 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jivesoftware.openfire.keystore; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileOutputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.security.KeyStore; -import java.security.cert.*; -import java.util.*; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests that verify the functionality of {@link OpenfireX509TrustManager}. @@ -36,7 +55,7 @@ public class OpenfireX509TrustManagerTest private X509Certificate[] expiredRootChain; private X509Certificate[] untrustedCAChain; - @Before + @BeforeEach public void createFixture() throws Exception { // Create a fresh store in a location that holds only temporary files. @@ -75,7 +94,7 @@ private static X getLast(X[]chain) { return chain[ chain.length - 1 ]; } - @After + @AfterEach public void tearDown() throws Exception { // Attempt to delete any left-overs from the test. @@ -103,10 +122,10 @@ public void testAcceptedIssuersAreAllValid() throws Exception final X509Certificate[] result = systemUnderTest.getAcceptedIssuers(); // Verify results. - Assert.assertEquals( 2, result.length ); - Assert.assertTrue( Arrays.asList( result ).contains( getLast( validChain ) ) ); - Assert.assertTrue( Arrays.asList( result ).contains( getLast( expiredIntChain ) ) ); - Assert.assertFalse( Arrays.asList( result ).contains( getLast( expiredRootChain ) ) ); + assertEquals( 2, result.length ); + assertTrue( Arrays.asList( result ).contains( getLast( validChain ) ) ); + assertTrue( Arrays.asList( result ).contains( getLast( expiredIntChain ) ) ); + assertFalse( Arrays.asList( result ).contains( getLast( expiredRootChain ) ) ); } /** @@ -127,31 +146,31 @@ public void testValidChain() throws Exception /** * Verifies that a chain that has an intermediate certificate that is expired is rejected. */ - @Test(expected = CertificateException.class) + @Test public void testInvalidChainExpiredIntermediate() throws Exception { // Setup fixture. // Execute system under test. - systemUnderTest.checkClientTrusted( expiredIntChain, "RSA" ); + assertThrows(CertificateException.class, () -> systemUnderTest.checkClientTrusted( expiredIntChain, "RSA" ) ); } /** * Verifies that a chain that has an root certificate (trust anchor) that is expired is rejected. */ - @Test(expected = CertificateException.class) + @Test public void testInvalidChainExpiredTrustAnchor() throws Exception { // Setup fixture. // Execute system under test. - systemUnderTest.checkClientTrusted( expiredRootChain, "RSA" ); + assertThrows(CertificateException.class, () -> systemUnderTest.checkClientTrusted( expiredRootChain, "RSA" ) ); } /** * Verifies that a chain that is missing an intermediate certificate is rejected. */ - @Test(expected = CertificateException.class) + @Test public void testInvalidChainMissingIntermediate() throws Exception { // Setup fixture. @@ -162,18 +181,18 @@ public void testInvalidChainMissingIntermediate() throws Exception input[ 2 ] = validChain[ 3 ]; // Execute system under test. - systemUnderTest.checkClientTrusted( input, "RSA" ); + assertThrows(CertificateException.class, () -> systemUnderTest.checkClientTrusted( input, "RSA" ) ); } /** * Verifies that a chain that is valid, but does not have its root CA certificate in the trust store, is rejected. */ - @Test(expected = CertificateException.class) + @Test public void testInvalidChainCAnotTrusted() throws Exception { // Setup fixture. // Execute system under test. - systemUnderTest.checkClientTrusted( untrustedCAChain, "RSA" ); + assertThrows(CertificateException.class, () -> systemUnderTest.checkClientTrusted( untrustedCAChain, "RSA" ) ); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/LdapManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/LdapManagerTest.java index 34975eaa60..33600c8f6d 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/LdapManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/LdapManagerTest.java @@ -1,6 +1,21 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.ldap; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.naming.ldap.LdapName; import java.util.ArrayList; @@ -8,7 +23,7 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests that verify the functionality of {@link LdapManager}. diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTemplateTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTemplateTest.java index 17d6fbcff8..55c88045ce 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTemplateTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTemplateTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,12 @@ import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.io.SAXReader; -import org.jivesoftware.util.CertificateManager; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.InputStream; -import java.security.cert.X509Certificate; import java.util.Arrays; -import java.util.Collection; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests that verify the implementation of {@link org.jivesoftware.openfire.ldap.LdapVCardProvider.VCardTemplate} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTest.java index 0155af66ce..161346741c 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/ldap/VCardTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,14 +18,13 @@ import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.*; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Unit tests that verify the implementation of {@link LdapVCardProvider.VCard} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/HistoryStrategyTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/HistoryStrategyTest.java index 18d84a8a30..10e5bb0878 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/HistoryStrategyTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/HistoryStrategyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2021-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.jivesoftware.openfire.muc; import org.jivesoftware.util.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.JID; import org.xmpp.packet.Message; @@ -31,7 +31,7 @@ import java.util.Random; import java.util.concurrent.ConcurrentLinkedQueue; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests that verify the implementation of {@link HistoryStrategy}. diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoleTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoleTest.java index 35ce996d25..0b2f17ce97 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoleTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2021-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,23 +16,21 @@ package org.jivesoftware.openfire.muc; import org.dom4j.Element; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.xmpp.packet.JID; import org.xmpp.packet.Presence; -import javax.xml.namespace.QName; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.Field; -import java.util.ArrayList; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.doReturn; /** @@ -40,13 +38,13 @@ * * @author Guus der Kinderen, guus.der.kinderen@gmail.com */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MUCRoleTest { @Mock private MUCRoom mockRoom; - @Before + @BeforeEach public void setup() throws Exception { doReturn(new JID("testroom@conference.example.org")).when(mockRoom).getJID(); } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoomTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoomTest.java index 367a102d33..346d89b2b4 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoomTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/MUCRoomTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2021-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,11 @@ import org.jivesoftware.openfire.group.ConcurrentGroupList; import org.jivesoftware.openfire.group.ConcurrentGroupMap; import org.jivesoftware.openfire.muc.spi.FMUCMode; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.xmpp.packet.JID; import java.io.ByteArrayInputStream; @@ -35,7 +35,7 @@ import java.time.Instant; import java.util.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @@ -45,7 +45,7 @@ * * @author Guus der Kinderen, guus.der.kinderen@gmail.com */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MUCRoomTest { @Mock @@ -57,7 +57,7 @@ public class MUCRoomTest { @Mock private MultiUserChatService mockService; - @Before + @BeforeEach public void setup() throws Exception { doReturn("conference").when(mockService).getServiceName(); doReturn("conference.example.org").when(mockService).getServiceDomain(); diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/MucPrivilegesTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/MucPrivilegesTest.java index 9f33bce680..bd6d4fa69b 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/MucPrivilegesTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/MucPrivilegesTest.java @@ -1,9 +1,27 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jivesoftware.openfire.muc.spi; -import junit.framework.Assert; import org.jivesoftware.openfire.muc.MUCRole; import org.jivesoftware.openfire.muc.MUCRoom; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Christian Schudt @@ -12,46 +30,46 @@ public class MucPrivilegesTest { @Test public void ownerShouldBeAbleToDoAnything() { - Assert.assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); + assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); } @Test public void adminShouldBeAbleToRevokeModeratorPrivilegesFromOtherAdmin() { - Assert.assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.admin, MUCRole.Role.none, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.admin, MUCRole.Role.none)); + assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.admin, MUCRole.Role.none, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.admin, MUCRole.Role.none)); } @Test public void adminShouldBeAbleToGrantMembership() { - Assert.assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.admin, MUCRole.Role.none, MUCRole.Affiliation.none, MUCRole.Role.none, MUCRole.Affiliation.member, MUCRole.Role.participant)); + assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.admin, MUCRole.Role.none, MUCRole.Affiliation.none, MUCRole.Role.none, MUCRole.Affiliation.member, MUCRole.Role.participant)); } @Test public void adminModeratorShouldNotBeAbleToRevokeModeratorPrivilegesFromOwner() { - Assert.assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); + assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); } @Test public void ownerModeratorShouldBeAbleToRevokeModeratorPrivilegesFromOwner() { - Assert.assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); + assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); } @Test public void ownerModeratorShouldBeAbleToRevokeModeratorPrivilegesFromAdmin() { - Assert.assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); + assertTrue(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); } @Test public void memberModeratorShouldNotBeAbleToRevokeModeratorPrivilegesFromOwner() { - Assert.assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.member, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); + assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.member, MUCRole.Role.moderator, MUCRole.Affiliation.owner, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); } @Test public void memberModeratorShouldNotBeAbleToRevokeModeratorPrivilegesFromAdmin() { - Assert.assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.member, MUCRole.Role.moderator, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); + assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.member, MUCRole.Role.moderator, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); } @Test public void memberShouldNotBeAbleToDoAnything() { - Assert.assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.member, MUCRole.Role.participant, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); + assertFalse(MUCRoom.isPrivilegedToChangeAffiliationAndRole(MUCRole.Affiliation.member, MUCRole.Role.participant, MUCRole.Affiliation.admin, MUCRole.Role.moderator, MUCRole.Affiliation.none, MUCRole.Role.none)); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/OccupantManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/OccupantManagerTest.java index 636940c4b8..98a0416804 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/OccupantManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/muc/spi/OccupantManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Ignite Realtime Community. All rights reserved. + * Copyright (C) 2022-2023 Ignite Realtime Community. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,23 +20,24 @@ import org.jivesoftware.openfire.muc.MultiUserChatService; import org.jivesoftware.openfire.muc.cluster.OccupantAddedTask; import org.jivesoftware.openfire.muc.cluster.OccupantRemovedTask; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.xmpp.packet.JID; import java.time.Duration; import java.time.Instant; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) + +@ExtendWith(MockitoExtension.class) public class OccupantManagerTest { @Mock @@ -45,7 +46,7 @@ public class OccupantManagerTest @Mock private MultiUserChatService mockService; - @Before + @BeforeEach public void setup() throws Exception { doReturn("conference").when(mockService).getServiceName(); doReturn("conference.example.org").when(mockService).getServiceDomain(); diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/net/DNSUtilTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/net/DNSUtilTest.java index e3a52800d1..0d22d6fc69 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/net/DNSUtilTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/net/DNSUtilTest.java @@ -1,11 +1,27 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.net; -import org.jivesoftware.openfire.net.DNSUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + /** * Unit tests for {@link org.jivesoftware.openfire.net.DNSUtil}. * @@ -13,7 +29,7 @@ */ public class DNSUtilTest { - //@Test + @Test @Disabled public void testJabberDotOrg() throws Exception { for (int i=0; i<=10; i++) { final List list = DNSUtil.resolveXMPPDomain("jabber.org", 5222); @@ -39,11 +55,11 @@ public void testJabberDotOrgMock() throws Exception { final List result = DNSUtil.prioritize(new DNSUtil.WeightedHostAddress[]{fallback, hermes6, hermes}); // verify - Assert.assertEquals("There were three records in the input, the output should have contained the same amount.", 3, result.size()); - Assert.assertTrue("The 'hermes' host should have been included somewhere in the output." , result.contains(hermes)); - Assert.assertTrue("The 'hermes6' host should have been included somewhere in the output." , result.contains(hermes6)); - Assert.assertTrue("The 'fallback' host should bhave been included somewhere in the output.", result.contains(fallback)); - Assert.assertEquals("The 'fallback' host should have been the last record in the result." , fallback, result.get(2)); + assertEquals(3, result.size(), "There were three records in the input, the output should have contained the same amount."); + assertTrue(result.contains(hermes), "The 'hermes' host should have been included somewhere in the output."); + assertTrue(result.contains(hermes6), "The 'hermes6' host should have been included somewhere in the output."); + assertTrue(result.contains(fallback), "The 'fallback' host should have been included somewhere in the output."); + assertEquals(fallback, result.get(2), "The 'fallback' host should have been the last record in the result."); } /** @@ -58,8 +74,8 @@ public void testOneHost() throws Exception { final List result = DNSUtil.prioritize(new DNSUtil.WeightedHostAddress[]{host}); // verify - Assert.assertEquals( 1, result.size() ); - Assert.assertEquals(host, result.get(0)); + assertEquals( 1, result.size() ); + assertEquals(host, result.get(0)); } /** @@ -74,8 +90,8 @@ public void testOneHostZeroPiority() throws Exception { final List result = DNSUtil.prioritize(new DNSUtil.WeightedHostAddress[]{host}); // verify - Assert.assertEquals(1, result.size()); - Assert.assertEquals(host, result.get(0)); + assertEquals(1, result.size()); + assertEquals(host, result.get(0)); } /** @@ -90,8 +106,8 @@ public void testOneHostZeroWeight() throws Exception { final List result = DNSUtil.prioritize(new DNSUtil.WeightedHostAddress[]{host}); // verify - Assert.assertEquals(1, result.size()); - Assert.assertEquals(host, result.get(0)); + assertEquals(1, result.size()); + assertEquals(host, result.get(0)); } /** @@ -110,10 +126,10 @@ public void testDifferentPriorities() throws Exception { final List result = DNSUtil.prioritize(new DNSUtil.WeightedHostAddress[]{hostA, hostB, hostC}); // verify - Assert.assertEquals(3, result.size()); - Assert.assertEquals(hostA, result.get(0)); - Assert.assertEquals(hostC, result.get( 1 )); - Assert.assertEquals(hostB, result.get(2)); + assertEquals(3, result.size()); + assertEquals(hostA, result.get(0)); + assertEquals(hostC, result.get( 1 )); + assertEquals(hostB, result.get(2)); } /** @@ -130,10 +146,10 @@ public void testZeroPriority() throws Exception { final List result = DNSUtil.prioritize(new DNSUtil.WeightedHostAddress[]{hostA, hostB, hostC}); // verify - Assert.assertEquals(3, result.size()); - Assert.assertEquals(hostA, result.get(0)); - Assert.assertEquals(hostC, result.get(1)); - Assert.assertEquals(hostB, result.get(2)); + assertEquals(3, result.size()); + assertEquals(hostA, result.get(0)); + assertEquals(hostC, result.get(1)); + assertEquals(hostB, result.get(2)); } /** @@ -173,8 +189,8 @@ public void testSameWeights() throws Exception { } // verify - Assert.assertTrue( hostAWasFirst ); - Assert.assertTrue( hostBWasFirst ); + assertTrue( hostAWasFirst ); + assertTrue( hostBWasFirst ); } /** @@ -211,8 +227,8 @@ public void testZeroWeights() throws Exception { } // verify - Assert.assertTrue(hostAWasFirst); - Assert.assertTrue(hostBWasFirst); + assertTrue(hostAWasFirst); + assertTrue(hostBWasFirst); } /** @@ -230,7 +246,7 @@ public void testNameCoverageExactMatch() throws Exception final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); // verify - Assert.assertTrue( result ); + assertTrue( result ); } /** @@ -248,7 +264,7 @@ public void testNameCoverageUnequal() throws Exception final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); // verify - Assert.assertFalse( result ); + assertFalse( result ); } /** @@ -266,7 +282,7 @@ public void testNameCoverageSubdomainNoWildcard() throws Exception final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); // verify - Assert.assertFalse( result ); + assertFalse( result ); } /** @@ -284,7 +300,7 @@ public void testNameCoveragePartialMatchButNoSubdomain() throws Exception final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); // verify - Assert.assertFalse( result ); + assertFalse( result ); } /** @@ -302,7 +318,7 @@ public void testNameCoverageSubdomainWithWildcard() throws Exception final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); // verify - Assert.assertTrue( result ); + assertTrue( result ); } /** @@ -320,7 +336,7 @@ public void testNameCoverageSubSubdomainWithWildcard() throws Exception final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); // verify - Assert.assertTrue( result ); + assertTrue( result ); } /** @@ -340,7 +356,7 @@ public void testNameCoverageSubdomainWithWildcardOfSameDomain() throws Exception final boolean result = DNSUtil.isNameCoveredByPattern( name, pattern ); // verify - Assert.assertTrue( result ); + assertTrue( result ); } /** @@ -358,6 +374,6 @@ public void testConstructLookup() throws Exception final String result = DNSUtil.constructLookup(service, protocol, name); // Verify results. - Assert.assertEquals("_xmpp-client._tcp.igniterealtime.org.", result); + assertEquals("_xmpp-client._tcp.igniterealtime.org.", result); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XMLLightweightParserTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XMLLightweightParserTest.java index 58d3863841..53e7c762d5 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XMLLightweightParserTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XMLLightweightParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2021-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package org.jivesoftware.openfire.nio; import org.apache.mina.core.buffer.IoBuffer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Unit tests that verify the functionality as implemented in {@link XMLLightweightParser} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XmlNumericCharacterReferenceTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XmlNumericCharacterReferenceTest.java index eb5786119e..aebefdd09d 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XmlNumericCharacterReferenceTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/nio/XmlNumericCharacterReferenceTest.java @@ -1,9 +1,24 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.nio; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * This unit tests verifies the correct detection of numeric character references that have invalid numeric values. @@ -32,7 +47,7 @@ * * @author Guus der Kinderen, guus.der.kinderen@gmail.com * - * @see http://www.w3.org/TR/2008/REC-xml-20081126/#dt-charref + * @see Extensible Markup Language (XML) 1.0 (Fifth Edition) section 4.1 Character and Entity References */ public class XmlNumericCharacterReferenceTest { @@ -105,7 +120,7 @@ public void testLegalNumericCharacterReferences() throws Exception { final boolean result = XMLLightweightParser.hasIllegalCharacterReferences(reference); // verify - assertFalse("Value \""+reference+"\" is reported to contain an illegal numeric character reference, even though this hard-coded test value should not contain one.", result); + assertFalse(result, "Value \""+reference+"\" is reported to contain an illegal numeric character reference, even though this hard-coded test value should not contain one."); } } @@ -121,7 +136,7 @@ public void testIllegalNumericCharacterReferences() throws Exception { final boolean result = XMLLightweightParser.hasIllegalCharacterReferences(reference); // verify - assertTrue("No illegal numeric character reference was found in value \""+reference+"\", even though this hard-coded test value should contain one.", result); + assertTrue(result, "No illegal numeric character reference was found in value \""+reference+"\", even though this hard-coded test value should contain one."); } } @@ -137,7 +152,7 @@ public void testnotNumericCharacterReferences() throws Exception { final boolean result = XMLLightweightParser.hasIllegalCharacterReferences(reference); // verify - assertFalse("Value \""+reference+"\" is reported to contain an illegal numeric character reference, even though this hard-coded test value should not contain a numeric character reference at all.", result); + assertFalse(result, "Value \""+reference+"\" is reported to contain an illegal numeric character reference, even though this hard-coded test value should not contain a numeric character reference at all."); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/CollectionNodeTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/CollectionNodeTest.java index c5ee746fd4..9fb8695cf7 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/CollectionNodeTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/CollectionNodeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2020-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ import org.jivesoftware.openfire.pubsub.models.AccessModel; import org.jivesoftware.openfire.pubsub.models.PublisherModel; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.JID; import java.io.ByteArrayInputStream; @@ -25,7 +25,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Verifies the implementation of {@link CollectionNode} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/LeafNodeTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/LeafNodeTest.java index f969764456..91c2776658 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/LeafNodeTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/LeafNodeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2020-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,15 +17,10 @@ import org.jivesoftware.openfire.pubsub.models.AccessModel; import org.jivesoftware.openfire.pubsub.models.PublisherModel; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.JID; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Verifies the implementation of {@link LeafNode} diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/session/SessionTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/session/SessionTest.java index 80cf2da0cc..4f0b16c5b2 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/session/SessionTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/session/SessionTest.java @@ -15,14 +15,15 @@ */ package org.jivesoftware.openfire.session; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserFactory; import java.io.StringReader; import java.util.Locale; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Unit tests that verify the implementation of {@link Session}. diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/spi/ConnectionTypeTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/spi/ConnectionTypeTest.java index 06965473c3..974710be0d 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/spi/ConnectionTypeTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/spi/ConnectionTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2020-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,56 +15,70 @@ */ package org.jivesoftware.openfire.spi; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Test; -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Unit test that verify the implementation of {@link ConnectionType} * * @author Guus der Kinderen, guus.der.kinderen@gmail.com */ -@RunWith(Parameterized.class) public class ConnectionTypeTest { /** - * Define the expected outputs of ConnectionType.isClientOriented() for the given ConnectionType + * Verifies that the SOCKET_S2S ConnectionType returns the appropriate 'client orientated' value. */ - @Parameterized.Parameters(name = "Verify that when ConnnectionType is \"{0}\" then isClientOriented returns \"{1}\"") - public static Iterable data() { - return Arrays.asList(new Object[][] { - {ConnectionType.SOCKET_S2S, false}, - {ConnectionType.SOCKET_C2S, true}, - {ConnectionType.BOSH_C2S, true}, - {ConnectionType.WEBADMIN, true}, - {ConnectionType.COMPONENT, false}, - {ConnectionType.CONNECTION_MANAGER, false} - }); - } + @Test + public void testSOCKET_S2SConnectionTypeHasCorrectIsClientOriented() + { + assertFalse(ConnectionType.SOCKET_S2S.isClientOriented()); + } - private final ConnectionType connType; - private final boolean expected; + /** + * Verifies that the SOCKET_C2S ConnectionType returns the appropriate 'client orientated' value. + */ + @Test + public void testSOCKET_C2SConnectionTypeHasCorrectIsClientOriented() + { + assertTrue(ConnectionType.SOCKET_C2S.isClientOriented()); + } - public ConnectionTypeTest(ConnectionType connType, boolean expected){ - this.connType = connType; - this.expected = expected; + /** + * Verifies that the BOSH_C2S ConnectionType returns the appropriate 'client orientated' value. + */ + @Test + public void testBOSH_C2SConnectionTypeHasCorrectIsClientOriented() + { + assertTrue(ConnectionType.BOSH_C2S.isClientOriented()); + } + + /** + * Verifies that the WEBADMIN ConnectionType returns the appropriate 'client orientated' value. + */ + @Test + public void testWEBADMINConnectionTypeHasCorrectIsClientOriented() + { + assertTrue(ConnectionType.WEBADMIN.isClientOriented()); } /** - * Verifies that a given ConnectionType returns the appropriate 'client orientated' value. + * Verifies that the COMPONENT ConnectionType returns the appropriate 'client orientated' value. */ @Test - public void testConnectionTypeHasCorrectIsClientOriented() throws Exception + public void testCOMPONENTConnectionTypeHasCorrectIsClientOriented() { - // Execute system under test. - final boolean result = connType.isClientOriented(); + assertFalse(ConnectionType.COMPONENT.isClientOriented()); + } - // Verify result. - assertEquals(result, expected); + /** + * Verifies that the CONNECTION_MANAGER ConnectionType returns the appropriate 'client orientated' value. + */ + @Test + public void testCONNECTION_MANAGERConnectionTypeHasCorrectIsClientOriented() + { + assertFalse(ConnectionType.CONNECTION_MANAGER.isClientOriented()); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/spi/EncryptionArtifactFactoryTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/spi/EncryptionArtifactFactoryTest.java index 148c9ebbe6..2932313237 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/spi/EncryptionArtifactFactoryTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/spi/EncryptionArtifactFactoryTest.java @@ -1,10 +1,26 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.spi; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collection; +import static org.junit.jupiter.api.Assertions.assertFalse; + /** * Unit tests that verify the functionality of {@link EncryptionArtifactFactory}. * @@ -25,7 +41,7 @@ public void testHasSupportedProtocols() throws Exception final Collection result = EncryptionArtifactFactory.getSupportedProtocols(); // Verify results. - Assert.assertFalse( result.isEmpty() ); + assertFalse( result.isEmpty() ); } /** @@ -41,7 +57,7 @@ public void testHasDefaultProtocols() throws Exception final Collection result = EncryptionArtifactFactory.getDefaultProtocols(); // Verify results. - Assert.assertFalse( result.isEmpty() ); + assertFalse( result.isEmpty() ); } /** @@ -57,7 +73,7 @@ public void testHasSupportedCipherSuites() throws Exception final Collection result = EncryptionArtifactFactory.getSupportedCipherSuites(); // Verify results. - Assert.assertFalse( result.isEmpty() ); + assertFalse( result.isEmpty() ); } /** @@ -73,6 +89,6 @@ public void testHasDefaultCipherSuites() throws Exception final Collection result = EncryptionArtifactFactory.getDefaultCipherSuites(); // Verify results. - Assert.assertFalse( result.isEmpty() ); + assertFalse( result.isEmpty() ); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/stanzaid/StanzaIDUtilTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/stanzaid/StanzaIDUtilTest.java index bed49c3b34..df8182f6cd 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/stanzaid/StanzaIDUtilTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/stanzaid/StanzaIDUtilTest.java @@ -1,9 +1,23 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.openfire.stanzaid; import org.dom4j.Element; import org.dom4j.QName; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.JID; import org.xmpp.packet.Message; import org.xmpp.packet.Packet; @@ -11,10 +25,10 @@ import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** - * Unit tests that verify the functionality of {@link StanzaID}. + * Unit tests that verify the functionality of {@link StanzaIDUtil}. * * @author Guus der Kinderen, guus.der.kinderen@gmail.com */ @@ -36,16 +50,16 @@ public void testGeneratesStanzaIDElement() throws Exception final Packet result = StanzaIDUtil.ensureUniqueAndStableStanzaID( input, self ); // Verify results. - Assert.assertNotNull( result ); + assertNotNull( result ); final Element stanzaIDElement = result.getElement().element( QName.get( "stanza-id", "urn:xmpp:sid:0" ) ); - Assert.assertNotNull( stanzaIDElement ); + assertNotNull( stanzaIDElement ); try { UUID.fromString( stanzaIDElement.attributeValue( "id" ) ); } catch ( IllegalArgumentException ex ) { - Assert.fail(); + fail(); } assertEquals( self.toString(), stanzaIDElement.attributeValue( "by" ) ); } @@ -69,18 +83,18 @@ public void testOverwriteStanzaIDElement() throws Exception final Packet result = StanzaIDUtil.ensureUniqueAndStableStanzaID( input, self ); // Verify results. - Assert.assertNotNull( result ); + assertNotNull( result ); final Element stanzaIDElement = result.getElement().element( QName.get( "stanza-id", "urn:xmpp:sid:0" ) ); - Assert.assertNotNull( stanzaIDElement ); + assertNotNull( stanzaIDElement ); try { UUID.fromString( stanzaIDElement.attributeValue( "id" ) ); } catch ( IllegalArgumentException ex ) { - Assert.fail(); + fail(); } - Assert.assertNotEquals( notExpected, stanzaIDElement.attributeValue( "id" ) ); + assertNotEquals( notExpected, stanzaIDElement.attributeValue( "id" ) ); assertEquals( self.toString(), stanzaIDElement.attributeValue( "by" ) ); } @@ -103,7 +117,7 @@ public void testDontOverwriteStanzaIDElement() throws Exception final Packet result = StanzaIDUtil.ensureUniqueAndStableStanzaID( input, self ); // Verify results. - Assert.assertNotNull( result ); + assertNotNull( result ); final List elements = result.getElement().elements( QName.get( "stanza-id", "urn:xmpp:sid:0" ) ); assertEquals( 2, elements.size() ); } @@ -126,18 +140,18 @@ public void testUseOriginIdElement() throws Exception final Packet result = StanzaIDUtil.ensureUniqueAndStableStanzaID( input, self ); // Verify results. - Assert.assertNotNull( result ); + assertNotNull( result ); final Element stanzaIDElement = result.getElement().element( QName.get( "stanza-id", "urn:xmpp:sid:0" ) ); - Assert.assertNotNull( stanzaIDElement ); + assertNotNull( stanzaIDElement ); try { UUID.fromString( stanzaIDElement.attributeValue( "id" ) ); } catch ( IllegalArgumentException ex ) { - Assert.fail(); + fail(); } - Assert.assertNotEquals( expected, stanzaIDElement.attributeValue( "id" ) ); + assertNotEquals( expected, stanzaIDElement.attributeValue( "id" ) ); assertEquals( self.toString(), stanzaIDElement.attributeValue( "by" ) ); } diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/streammanagement/StreamManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/streammanagement/StreamManagerTest.java index b99324ee77..eb0db057d5 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/streammanagement/StreamManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/streammanagement/StreamManagerTest.java @@ -15,12 +15,12 @@ */ package org.jivesoftware.openfire.streammanagement; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigInteger; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Unit tests that verify the implementation of {@link StreamManager}. diff --git a/xmppserver/src/test/java/org/jivesoftware/openfire/user/UserManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/openfire/user/UserManagerTest.java index 98b965dc8c..29c08a5439 100644 --- a/xmppserver/src/test/java/org/jivesoftware/openfire/user/UserManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/openfire/user/UserManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2022-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,33 +16,34 @@ package org.jivesoftware.openfire.user; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.verify; - -import java.util.Collection; -import java.util.concurrent.atomic.AtomicReference; - import org.dom4j.Element; import org.jivesoftware.Fixtures; import org.jivesoftware.openfire.IQRouter; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.cache.CacheFactory; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.xmpp.component.IQResultListener; import org.xmpp.packet.IQ; import org.xmpp.packet.JID; import org.xmpp.packet.PacketError; -@RunWith(MockitoJUnitRunner.class) +import java.util.Collection; +import java.util.concurrent.atomic.AtomicReference; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.verify; + +@ExtendWith(MockitoExtension.class) public class UserManagerTest { private static final String REMOTE_XMPP_DOMAIN = "remote.xmpp.domain"; @@ -61,12 +62,12 @@ public class UserManagerTest { private UserManager userManager; private IQRouter iqRouter; - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { Fixtures.reconfigureOpenfireHome(); } - @Before + @BeforeEach public void setUp() throws Exception { Fixtures.clearExistingProperties(); @@ -105,16 +106,15 @@ public void getUserNamesWillGetAListOfUserNames() throws Exception{ assertThat(result.contains("not exists name"), is(false)); } - @Test(expected=IllegalArgumentException.class) + @Test public void deleteInvalidUserWillGetError() throws Exception{ User user = new User("!@#ED",null,null,null,null); - userManager.deleteUser(user); + assertThrows(IllegalArgumentException.class, () -> userManager.deleteUser(user)); } - @Test(expected=UserAlreadyExistsException.class) + @Test public void createExistingUserWillGetError() throws Exception{ - userManager.createUser(USER_ID, "change me", "Test User Name", "test-email@example.com"); - + assertThrows(UserAlreadyExistsException.class, () -> userManager.createUser(USER_ID, "change me", "Test User Name", "test-email@example.com")); } @Test diff --git a/xmppserver/src/test/java/org/jivesoftware/util/AdminConsoleTest.java b/xmppserver/src/test/java/org/jivesoftware/util/AdminConsoleTest.java index 6031c45469..ed9b6f5147 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/AdminConsoleTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/AdminConsoleTest.java @@ -1,27 +1,38 @@ /* - * Copyright (C) 2004-2008 Jive Software. All rights reserved. + * Copyright (C) 2004-2008 Jive Software. 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jivesoftware.util; +import org.dom4j.Element; +import org.jivesoftware.admin.AdminConsole; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + import java.io.InputStream; import java.lang.reflect.Method; import java.util.Collection; -import org.dom4j.Element; -import org.jivesoftware.admin.AdminConsole; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; - -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class AdminConsoleTest { /** * Resets the admin console internal data structures. */ - @After + @AfterEach public void tearDown() throws Exception { Class c = AdminConsole.class; Method init = c.getDeclaredMethod("load", (Class[])null); diff --git a/xmppserver/src/test/java/org/jivesoftware/util/AesEncryptorTest.java b/xmppserver/src/test/java/org/jivesoftware/util/AesEncryptorTest.java index c8cd70bc82..415958e658 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/AesEncryptorTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/AesEncryptorTest.java @@ -1,11 +1,28 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; +import org.junit.jupiter.api.Test; + import java.util.UUID; -import org.junit.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class AesEncryptorTest { @@ -16,7 +33,7 @@ public void testEncryptionUsingDefaultKey() { Encryptor encryptor = new AesEncryptor(); String b64Encrypted = encryptor.encrypt(test); - assertFalse(test.equals(b64Encrypted)); + assertNotEquals(test, b64Encrypted); assertEquals(test, encryptor.decrypt(b64Encrypted)); } @@ -29,7 +46,7 @@ public void testEncryptionUsingCustomKey() { Encryptor encryptor = new AesEncryptor(UUID.randomUUID().toString()); String b64Encrypted = encryptor.encrypt(test); - assertFalse(test.equals(b64Encrypted)); + assertNotEquals(test, b64Encrypted); assertEquals(test, encryptor.decrypt(b64Encrypted)); } @@ -42,7 +59,7 @@ public void testEncryptionForEmptyString() { Encryptor encryptor = new AesEncryptor(); String b64Encrypted = encryptor.encrypt(test); - assertFalse(test.equals(b64Encrypted)); + assertNotEquals(test, b64Encrypted); assertEquals(test, encryptor.decrypt(b64Encrypted)); } diff --git a/xmppserver/src/test/java/org/jivesoftware/util/BlowfishEncryptorTest.java b/xmppserver/src/test/java/org/jivesoftware/util/BlowfishEncryptorTest.java index bc174c2c4a..3a068f21f5 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/BlowfishEncryptorTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/BlowfishEncryptorTest.java @@ -1,12 +1,25 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import java.util.UUID; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class BlowfishEncryptorTest { @@ -17,7 +30,7 @@ public void testEncryptionUsingDefaultKey() { Encryptor encryptor = new Blowfish(); String b64Encrypted = encryptor.encrypt(test); - assertFalse(test.equals(b64Encrypted)); + assertNotEquals(test, b64Encrypted); assertEquals(test, encryptor.decrypt(b64Encrypted)); } @@ -30,7 +43,7 @@ public void testEncryptionUsingCustomKey() { Encryptor encryptor = new Blowfish(UUID.randomUUID().toString()); String b64Encrypted = encryptor.encrypt(test); - assertFalse(test.equals(b64Encrypted)); + assertNotEquals(test, b64Encrypted); assertEquals(test, encryptor.decrypt(b64Encrypted)); } @@ -43,7 +56,7 @@ public void testEncryptionForEmptyString() { Encryptor encryptor = new Blowfish(); String b64Encrypted = encryptor.encrypt(test); - assertFalse(test.equals(b64Encrypted)); + assertNotEquals(test, b64Encrypted); assertEquals(test, encryptor.decrypt(b64Encrypted)); } diff --git a/xmppserver/src/test/java/org/jivesoftware/util/CacheUtilTest.java b/xmppserver/src/test/java/org/jivesoftware/util/CacheUtilTest.java index d4b61529e9..c545f5ceed 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/CacheUtilTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/CacheUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,12 @@ import org.jivesoftware.util.cache.Cache; import org.jivesoftware.util.cache.CacheUtil; import org.jivesoftware.util.cache.DefaultLocalCacheStrategy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.Serializable; import java.util.ArrayList; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests that verify the functionality of {@link CacheUtil} diff --git a/xmppserver/src/test/java/org/jivesoftware/util/CacheableOptionalTest.java b/xmppserver/src/test/java/org/jivesoftware/util/CacheableOptionalTest.java index 4d3dd735f0..cc55bf8436 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/CacheableOptionalTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/CacheableOptionalTest.java @@ -1,7 +1,22 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -77,7 +92,7 @@ public void cacheSizeOfAbsentCacheableOptionalBooleanIsCorrect() throws Exceptio } // FIXME: I would expect the serialisation overhead to be constant, but that's not the case - @Ignore + @Disabled @Test public void cacheSizeOfPresentCacheableOptionalBooleanIsCorrect() throws Exception { diff --git a/xmppserver/src/test/java/org/jivesoftware/util/CertificateManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/util/CertificateManagerTest.java index 7dc9a0f3ed..bc2abc6c9c 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/CertificateManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/CertificateManagerTest.java @@ -1,6 +1,24 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import org.bouncycastle.asn1.*; +import org.bouncycastle.asn1.ASN1Encodable; +import org.bouncycastle.asn1.ASN1ObjectIdentifier; +import org.bouncycastle.asn1.DERSequence; +import org.bouncycastle.asn1.DERUTF8String; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.GeneralName; @@ -11,8 +29,8 @@ import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder; import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; @@ -29,8 +47,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; /** * Unit test to validate the functionality of @{link CertificateManager}. @@ -47,7 +66,7 @@ public class CertificateManagerTest private static KeyPair issuerKeyPair; private static ContentSigner contentSigner; - @BeforeClass + @BeforeAll public static void initialize() throws Exception { keyPairGenerator = KeyPairGenerator.getInstance( "RSA" ); diff --git a/xmppserver/src/test/java/org/jivesoftware/util/CertificateTest.java b/xmppserver/src/test/java/org/jivesoftware/util/CertificateTest.java index 9d2a9eb590..005eeec4b8 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/CertificateTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/CertificateTest.java @@ -1,13 +1,28 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; +import org.junit.jupiter.api.Test; + import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * Basic tests for code used by CertificateManager. @@ -28,8 +43,8 @@ public void testCN() { while (matcher.find()) { found.add(matcher.group(2)); } - assertEquals("Incorrect number of CNs were found", 2, found.size()); - assertEquals("Incorrect CN found", "scifi.com" , found.get(0)); - assertEquals("Incorrect CN found", "jabber.scifi.com" , found.get(1)); + assertEquals(2, found.size(), "Incorrect number of CNs were found"); + assertEquals("scifi.com" , found.get(0), "Incorrect CN found"); + assertEquals("jabber.scifi.com" , found.get(1), "Incorrect CN found"); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/util/CollectionUtilsTest.java b/xmppserver/src/test/java/org/jivesoftware/util/CollectionUtilsTest.java index 1bb57aaaac..417cd0253d 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/CollectionUtilsTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/CollectionUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2021-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,14 @@ */ package org.jivesoftware.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests that verify the functionality of {@link CollectionUtils} diff --git a/xmppserver/src/test/java/org/jivesoftware/util/EntityCapabilitiesManagerTest.java b/xmppserver/src/test/java/org/jivesoftware/util/EntityCapabilitiesManagerTest.java index 2b09d3390e..276082e122 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/EntityCapabilitiesManagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/EntityCapabilitiesManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2008 Jive Software. All rights reserved. + * Copyright (C) 2004-2008 Jive Software, 2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,16 @@ package org.jivesoftware.util; -import static org.junit.Assert.assertEquals; - import org.dom4j.Element; import org.dom4j.QName; import org.jivesoftware.openfire.entitycaps.EntityCapabilitiesManager; import org.jivesoftware.util.cache.CacheFactory; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.xmpp.packet.IQ; +import static org.junit.jupiter.api.Assertions.*; + /** * Test cases for the {@link EntityCapabilitiesManager} class. * @@ -35,7 +35,7 @@ */ public class EntityCapabilitiesManagerTest { - @BeforeClass + @BeforeAll public static void setUp() throws Exception { CacheFactory.initialize(); } diff --git a/xmppserver/src/test/java/org/jivesoftware/util/GraphicsUtilsTest.java b/xmppserver/src/test/java/org/jivesoftware/util/GraphicsUtilsTest.java index 3264906ce4..87dc812912 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/GraphicsUtilsTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/GraphicsUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,11 @@ */ package org.jivesoftware.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.InputStream; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests for {@link GraphicsUtils} diff --git a/xmppserver/src/test/java/org/jivesoftware/util/JIDTest.java b/xmppserver/src/test/java/org/jivesoftware/util/JIDTest.java index 20c0ba19e4..0a6133dcf9 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/JIDTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/JIDTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007 Jive Software. All rights reserved. + * Copyright (C) 2004-2007 Jive Software, 2023 Ignite Realtime Foundation. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. @@ -7,12 +7,10 @@ package org.jivesoftware.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xmpp.packet.JID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Test cases for the JID class. @@ -32,7 +30,7 @@ public void testDomain() { } catch (Exception e) { failed = true; } - assertTrue("A domain with spaces was accepted", failed); + assertTrue(failed, "A domain with spaces was accepted"); failed = false; try { @@ -40,7 +38,7 @@ public void testDomain() { } catch (Exception e) { failed = true; } - assertTrue("A domain with _ was accepted", failed); + assertTrue(failed, "A domain with _ was accepted"); } @Test @@ -54,30 +52,29 @@ public void testUsernames() { } catch (Exception e) { failed = true; } - assertTrue("A username with spaces was accepted", failed); + assertTrue(failed, "A username with spaces was accepted"); } @Test public void testCompare() { JID jid1 = new JID("john@mycomapny.com"); JID jid2 = new JID("john@mycomapny.com"); - assertEquals("Failed to compare 2 similar JIDs", 0 , jid1.compareTo(jid2)); - assertEquals("Failed to recognize equal JIDs", jid1 , jid2); + assertEquals(0 , jid1.compareTo(jid2), "Failed to compare 2 similar JIDs"); + assertEquals(jid1, jid2, "Failed to recognize equal JIDs"); jid1 = new JID("john@mycomapny.com"); jid2 = new JID("mycomapny.com"); - assertTrue("Failed to recognized bigger JID", jid1.compareTo(jid2) > 0); - assertFalse("Failed to recognize different JIDs", jid1.equals(jid2)); + assertTrue(jid1.compareTo(jid2) > 0, "Failed to recognized bigger JID"); + assertNotEquals(jid1, jid2, "Failed to recognize different JIDs"); jid1 = new JID("john@mycomapny.com"); jid2 = new JID("mycomapny.com/resource"); - assertTrue("Failed to recognized bigger JID", jid1.compareTo(jid2) > 0); - assertFalse("Failed to recognize different JIDs", jid1.equals(jid2)); + assertTrue(jid1.compareTo(jid2) > 0, "Failed to recognized bigger JID"); + assertNotEquals(jid1, jid2, "Failed to recognize different JIDs"); jid1 = new JID("john@mycomapny.com"); jid2 = new JID("john@mycomapny.com/resource"); - assertTrue("Failed to recognized bigger JID", jid1.compareTo(jid2) < 0); - assertFalse("Failed to recognize different JIDs", jid1.equals(jid2)); - + assertTrue(jid1.compareTo(jid2) < 0, "Failed to recognized bigger JID"); + assertNotEquals(jid1, jid2, "Failed to recognize different JIDs"); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/util/JavaSpecVersionTest.java b/xmppserver/src/test/java/org/jivesoftware/util/JavaSpecVersionTest.java index eb4c56c8d7..2a5228e965 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/JavaSpecVersionTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/JavaSpecVersionTest.java @@ -1,9 +1,23 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class JavaSpecVersionTest { @@ -46,7 +60,7 @@ public void test7notNewerThan8() throws Exception final boolean result = seven.isNewerThan( eight ); // Verify results. - assertFalse( false ); + assertFalse( result ); } @Test diff --git a/xmppserver/src/test/java/org/jivesoftware/util/LDAPTest.java b/xmppserver/src/test/java/org/jivesoftware/util/LDAPTest.java index 57e3e8b1f3..ebf96491ea 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/LDAPTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/LDAPTest.java @@ -1,30 +1,37 @@ /* - * Copyright (C) 2008 Daniel Henninger. All rights reserved. + * Copyright (C) 2008 Daniel Henninger, 2023 Ignite Realtime Foundation. All rights reserved. * - * This software is published under the terms of the GNU Public License (GPL), a copy of which is - * included in this distribution. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.jivesoftware.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.util.ArrayList; +import org.jivesoftware.Fixtures; +import org.jivesoftware.openfire.ldap.LdapManager; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import javax.naming.directory.BasicAttributes; import javax.naming.directory.SearchResult; -import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; -import org.jivesoftware.Fixtures; -import org.jivesoftware.openfire.ldap.LdapManager; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; /** * @author Daniel Henninger */ public class LDAPTest { - @BeforeClass + @BeforeAll public static void reconfigureOpenfireHome() throws Exception { Fixtures.reconfigureOpenfireHome(); } @@ -52,22 +59,22 @@ public void testRdnEscapeValue() { String before = "Jive Software, Inc"; String after = "Jive Software\\, Inc"; String converted = Rdn.escapeValue(before); - assertTrue("Conversion result "+before+" to "+converted, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted); before = "Test.User; (+1)"; after = "Test.User\\; (\\+1)"; converted = Rdn.escapeValue(before); - assertTrue("Conversion result "+before+" to "+converted, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted); before = "Wildcard *"; after = "Wildcard *"; converted = Rdn.escapeValue(before); - assertTrue("Conversion result "+before+" to "+converted, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted); before = "Group/Section"; after = "Group/Section"; converted = Rdn.escapeValue(before); - assertTrue("Conversion result "+before+" to "+converted, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted); } @Test @@ -80,27 +87,27 @@ public void testSanitizeSearchFilter() { before = "Wildcard *"; after = "Wildcard \\2a"; converted = LdapManager.sanitizeSearchFilter(before, false); - assertTrue("Conversion result "+before+" to "+converted+ " expected " + after, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted + " expected " + after); before = "Wildcard *"; after = "Wildcard *"; converted = LdapManager.sanitizeSearchFilter(before, true); - assertTrue("Conversion result "+before+" to "+converted+ " expected " + after, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted + " expected " + after); before = "Wild*card *"; after = "Wild\\2acard \\2a"; converted = LdapManager.sanitizeSearchFilter(before, false); - assertTrue("Conversion result "+before+" to "+converted+ " expected " + after, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted + " expected " + after); before = "Wild*card *"; after = "Wild*card *"; converted = LdapManager.sanitizeSearchFilter(before, true); - assertTrue("Conversion result "+before+" to "+converted+ " expected " + after, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted + " expected " + after); before = "~ Group|Section & Teams!"; after = "\\7e Group\\7cSection \\26 Teams\\21"; converted = LdapManager.sanitizeSearchFilter(before, false); - assertTrue("Conversion result "+before+" to "+converted+ " expected " + after, converted.equals(after)); + assertEquals(converted, after, "Conversion result " + before + " to " + converted + " expected " + after); } /** diff --git a/xmppserver/src/test/java/org/jivesoftware/util/ListPagerTest.java b/xmppserver/src/test/java/org/jivesoftware/util/ListPagerTest.java index 29a5626e00..d1518021a3 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/ListPagerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/ListPagerTest.java @@ -1,10 +1,25 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -14,11 +29,11 @@ import java.util.List; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ListPagerTest { private static final List LIST_OF_25 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25); @@ -30,14 +45,14 @@ public class ListPagerTest { @Mock private HttpSession session; - @Before + @BeforeEach public void setUp() { - doReturn("5").when(request).getParameter("listPagerPageSize"); doReturn(session).when(request).getSession(); } @Test public void aDefaultRequestWillHaveAPageSizeOf25() { + doReturn("5").when(request).getParameter("listPagerPageSize"); final ListPager listPager = new ListPager<>(request, response, LIST_OF_25); @@ -51,6 +66,7 @@ public void aDefaultRequestWillHaveAPageSizeOf25() { @Test public void anEmptyListWillStartOnPage1Of1() { + doReturn("5").when(request).getParameter("listPagerPageSize"); final ListPager listPager = new ListPager<>(request, response, Collections.emptyList()); @@ -64,6 +80,7 @@ public void anEmptyListWillStartOnPage1Of1() { @Test public void theLowerBoundCurrentPageIs1() { + doReturn("5").when(request).getParameter("listPagerPageSize"); doReturn("-1").when(request).getParameter("listPagerCurrentPage"); final ListPager listPager = new ListPager<>(request, response, LIST_OF_25); @@ -75,6 +92,7 @@ public void theLowerBoundCurrentPageIs1() { @Test public void theUpperBoundCurrentPageIsTotalPages() { + doReturn("5").when(request).getParameter("listPagerPageSize"); doReturn(String.valueOf(Integer.MAX_VALUE)).when(request).getParameter("listPagerCurrentPage"); final ListPager listPager = new ListPager<>(request, response, LIST_OF_25); @@ -86,6 +104,7 @@ public void theUpperBoundCurrentPageIsTotalPages() { @Test public void willFilterTheList() { + doReturn("5").when(request).getParameter("listPagerPageSize"); // Filter on even numbers only final ListPager listPager = new ListPager<>(request, response, LIST_OF_25, value -> value % 2 == 0); diff --git a/xmppserver/src/test/java/org/jivesoftware/util/LocaleUtilsTest.java b/xmppserver/src/test/java/org/jivesoftware/util/LocaleUtilsTest.java index 9ce63ee4e9..b24cb5bebb 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/LocaleUtilsTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/LocaleUtilsTest.java @@ -1,9 +1,24 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import org.hamcrest.MatcherAssert; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.hamcrest.Matchers.is; public class LocaleUtilsTest { @@ -12,6 +27,6 @@ public void getLocalizedStringWillReturnASensibleDefaultValue() { final String key = "if.this.key.exists.the.test.will.fail"; - assertThat(LocaleUtils.getLocalizedString(key), is("???" + key + "???")); + MatcherAssert.assertThat(LocaleUtils.getLocalizedString(key), is("???" + key + "???")); } } diff --git a/xmppserver/src/test/java/org/jivesoftware/util/SAXReaderUtilTest.java b/xmppserver/src/test/java/org/jivesoftware/util/SAXReaderUtilTest.java index c1a285953b..7737ab24e9 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/SAXReaderUtilTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/SAXReaderUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2021-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ import org.dom4j.Document; import org.dom4j.DocumentException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -26,7 +26,7 @@ import java.nio.charset.StandardCharsets; import java.util.concurrent.ExecutionException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Verifies the implementation of {@link SAXReaderUtil} diff --git a/xmppserver/src/test/java/org/jivesoftware/util/StringUtilsTest.java b/xmppserver/src/test/java/org/jivesoftware/util/StringUtilsTest.java index 1ce33a0c33..622313eadd 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/StringUtilsTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/StringUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,24 +12,23 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */package org.jivesoftware.util; + */ +package org.jivesoftware.util; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.time.Duration; import java.util.Arrays; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; public class StringUtilsTest { - @Before + @BeforeEach public void setUp() { JiveGlobals.setLocale(Locale.ENGLISH); } @@ -60,7 +59,7 @@ private void assertValidDomainName(String domain) { } private void assertValidDomainName(String domain, String expected) { - assertEquals("Domain should be valid: " + domain, expected, StringUtils.validateDomainName(domain)); + assertEquals(expected, StringUtils.validateDomainName(domain), "Domain should be valid: " + domain); } private void assertInvalidDomainName(String domain, String expectedCause) { diff --git a/xmppserver/src/test/java/org/jivesoftware/util/SystemPropertyTest.java b/xmppserver/src/test/java/org/jivesoftware/util/SystemPropertyTest.java index 7be15cf3e3..7729992578 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/SystemPropertyTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/SystemPropertyTest.java @@ -1,23 +1,20 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.doReturn; - -import java.time.Duration; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; - import org.jivesoftware.Fixtures; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.auth.AuthProvider; @@ -25,15 +22,28 @@ import org.jivesoftware.openfire.auth.HybridAuthProvider; import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.ldap.LdapAuthProvider; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.xmpp.packet.JID; -@RunWith(MockitoJUnitRunner.class) +import java.time.Duration; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.doReturn; + +@ExtendWith(MockitoExtension.class) public class SystemPropertyTest { @Mock @@ -41,16 +51,15 @@ public class SystemPropertyTest { @Mock private PluginManager pluginManager; - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { Fixtures.reconfigureOpenfireHome(); } @SuppressWarnings({"deprecation", "ResultOfMethodCallIgnored"}) - @Before + @BeforeEach public void setUp() { Fixtures.clearExistingProperties(); - doReturn(pluginManager).when(xmppServer).getPluginManager(); XMPPServer.setInstance(xmppServer); } @@ -136,48 +145,55 @@ public void willBuildABooleanProperty() { assertThat(booleanProperty.getValueAsSaved(), is("true")); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildAPropertyWithoutAKey() { - SystemProperty.Builder.ofType(String.class) - .build(); + assertThrows(IllegalArgumentException.class, () -> SystemProperty.Builder.ofType(String.class).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildAPropertyWithoutADefaultValue() { - SystemProperty.Builder.ofType(String.class) - .setKey("a-test-property-without-a-default-value") - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(String.class) + .setKey("a-test-property-without-a-default-value") + .build() + ); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildAPropertyWithoutADynamicIndicator() { - SystemProperty.Builder.ofType(String.class) - .setKey("a-test-property-without-dynamic-set") - .setDefaultValue("default value") - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(String.class) + .setKey("a-test-property-without-dynamic-set") + .setDefaultValue("default value") + .build() + ); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildAPropertyForAnUnsupportedClass() { - SystemProperty.Builder.ofType(JavaSpecVersion.class) - .setKey("a-property-for-an-unsupported-class") - .setDefaultValue(new JavaSpecVersion("1.8")) - .setDynamic(true) - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(JavaSpecVersion.class) + .setKey("a-property-for-an-unsupported-class") + .setDefaultValue(new JavaSpecVersion("1.8")) + .setDynamic(true) + .build() + ); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildTheSamePropertyTwice() { SystemProperty.Builder.ofType(String.class) .setKey("a-duplicate-property") .setDefaultValue("") .setDynamic(true) .build(); - SystemProperty.Builder.ofType(Boolean.class) - .setKey("a-duplicate-property") - .setDefaultValue(false) - .setDynamic(true) - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(Boolean.class) + .setKey("a-duplicate-property") + .setDefaultValue(false) + .setDynamic(true) + .build() + ); } @Test @@ -212,23 +228,27 @@ public void willPreventAValueBeingTooHigh() { assertThat(property.getValueAsSaved(), is("42")); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildADurationPropertyWithoutAChronoUnit() { - SystemProperty.Builder.ofType(Duration.class) - .setKey("this-will-not-work") - .setDefaultValue(Duration.ZERO) - .setDynamic(true) - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(Duration.class) + .setKey("this-will-not-work") + .setDefaultValue(Duration.ZERO) + .setDynamic(true) + .build() + ); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildADurationPropertyWithAnInvalidChronoUnit() { - SystemProperty.Builder.ofType(Duration.class) - .setKey("this-will-not-work") - .setDefaultValue(Duration.ZERO) - .setChronoUnit(ChronoUnit.CENTURIES) - .setDynamic(true) - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(Duration.class) + .setKey("this-will-not-work") + .setDefaultValue(Duration.ZERO) + .setChronoUnit(ChronoUnit.CENTURIES) + .setDynamic(true) + .build() + ); } @Test @@ -294,6 +314,8 @@ public void theDefaultPluginIsOpenfire() { @Test public void thePluginCanBeChanged() { + doReturn(pluginManager).when(xmppServer).getPluginManager(); + final SystemProperty longProperty = SystemProperty.Builder.ofType(Long.class) .setKey("a-plugin-property") .setDefaultValue(42L) @@ -304,15 +326,16 @@ public void thePluginCanBeChanged() { assertThat(longProperty.getPlugin(), is("TestPluginName")); } - @Test(expected = IllegalArgumentException.class) + @Test public void aPluginIsRequired() { - - SystemProperty.Builder.ofType(Long.class) - .setKey("a-null-plugin-property") - .setDefaultValue(42L) - .setPlugin(null) - .setDynamic(false) - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(Long.class) + .setKey("a-null-plugin-property") + .setDefaultValue(42L) + .setPlugin(null) + .setDynamic(false) + .build() + ); } @Test @@ -365,25 +388,27 @@ public void willNotReturnAMissingClass() { assertThat(classProperty.getValue(), is(equalTo(DefaultAuthProvider.class))); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildAClassPropertyWithoutABaseClass() { - - SystemProperty.Builder.ofType(Class.class) - .setKey("a-broken-class-property") - .setDefaultValue(DefaultAuthProvider.class) - .setDynamic(false) - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(Class.class) + .setKey("a-broken-class-property") + .setDefaultValue(DefaultAuthProvider.class) + .setDynamic(false) + .build() + ); } - @Test(expected = IllegalArgumentException.class) + @Test public void willNotBuildARegularPropertyWithABaseClass() { - - SystemProperty.Builder.ofType(Long.class) - .setKey("a-broken-long-property") - .setDefaultValue(42L) - .setBaseClass(java.lang.Long.class) - .setDynamic(false) - .build(); + assertThrows(IllegalArgumentException.class, () -> + SystemProperty.Builder.ofType(Long.class) + .setKey("a-broken-long-property") + .setDefaultValue(42L) + .setBaseClass(java.lang.Long.class) + .setDynamic(false) + .build() + ); } @Test @@ -426,6 +451,8 @@ public void willAllowNullDefaultsForAClassProperty() { @Test public void willRemovePluginSpecificProperties() { + doReturn(pluginManager).when(xmppServer).getPluginManager(); + final String key = "a-class-property-to-remove"; final SystemProperty property = SystemProperty.Builder.ofType(Class.class) .setKey(key) diff --git a/xmppserver/src/test/java/org/jivesoftware/util/VersionTest.java b/xmppserver/src/test/java/org/jivesoftware/util/VersionTest.java index dca7b88c4f..32a645b951 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/VersionTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/VersionTest.java @@ -1,13 +1,27 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; import org.jivesoftware.util.Version.ReleaseStatus; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; public class VersionTest { diff --git a/xmppserver/src/test/java/org/jivesoftware/util/WebXmlUtilsTest.java b/xmppserver/src/test/java/org/jivesoftware/util/WebXmlUtilsTest.java index ceb258d841..f7fce05f7a 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/WebXmlUtilsTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/WebXmlUtilsTest.java @@ -1,7 +1,22 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; import org.dom4j.Document; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.Iterator; @@ -9,7 +24,7 @@ import java.util.Map; import java.util.Set; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Unit tests for {@link WebXmlUtils} diff --git a/xmppserver/src/test/java/org/jivesoftware/util/XMLPropertiesTest.java b/xmppserver/src/test/java/org/jivesoftware/util/XMLPropertiesTest.java index 44bc8e3499..c415c3d1b4 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/XMLPropertiesTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/XMLPropertiesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2008 Jive Software, 2022 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2004-2008 Jive Software, 2022-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ package org.jivesoftware.util; -import java.io.ByteArrayInputStream; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import java.io.ByteArrayInputStream; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class XMLPropertiesTest { diff --git a/xmppserver/src/test/java/org/jivesoftware/util/XMPPDateTimeFormatTest.java b/xmppserver/src/test/java/org/jivesoftware/util/XMPPDateTimeFormatTest.java index a3ecc1a189..0ee46390bf 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/XMPPDateTimeFormatTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/XMPPDateTimeFormatTest.java @@ -1,6 +1,21 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; import java.text.DateFormat; import java.text.ParseException; @@ -8,7 +23,7 @@ import java.util.Date; import java.util.TimeZone; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; public class XMPPDateTimeFormatTest { private final String TEST_DATE = "2013-01-25T18:07:22.768Z"; diff --git a/xmppserver/src/test/java/org/jivesoftware/util/XPPWriterTest.java b/xmppserver/src/test/java/org/jivesoftware/util/XPPWriterTest.java index 28a467198b..813d038f93 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/XPPWriterTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/XPPWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2008 Jive Software. All rights reserved. + * Copyright (C) 2004-2008 Jive Software, 2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ package org.jivesoftware.util; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** *

Test the writing of dom4j documents using the XPP serializer.

@@ -29,7 +29,7 @@ public class XPPWriterTest { *

Run a standard config document through a round trip and compare.

*/ @Test - @Ignore + @Disabled public void testRoundtrip(){ // NOTE: disabling this test case until we get resources working again. /* diff --git a/xmppserver/src/test/java/org/jivesoftware/util/cache/DefaultExternalizableUtilTest.java b/xmppserver/src/test/java/org/jivesoftware/util/cache/DefaultExternalizableUtilTest.java index d2ca6f67b9..cb2da386d3 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/cache/DefaultExternalizableUtilTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/cache/DefaultExternalizableUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2020-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ */ package org.jivesoftware.util.cache; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.*; import java.util.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Verifies functionality as implemented by {@link DefaultExternalizableUtil} @@ -32,7 +32,7 @@ public class DefaultExternalizableUtilTest { private Bus bus; - @Before + @BeforeEach public void setupBus() { bus = new Bus(); } diff --git a/xmppserver/src/test/java/org/jivesoftware/util/cache/ReverseLookupComputingCacheEntryListenerTest.java b/xmppserver/src/test/java/org/jivesoftware/util/cache/ReverseLookupComputingCacheEntryListenerTest.java index 9d2294b572..57914bdfdf 100644 --- a/xmppserver/src/test/java/org/jivesoftware/util/cache/ReverseLookupComputingCacheEntryListenerTest.java +++ b/xmppserver/src/test/java/org/jivesoftware/util/cache/ReverseLookupComputingCacheEntryListenerTest.java @@ -1,12 +1,28 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jivesoftware.util.cache; import org.jivesoftware.openfire.cluster.NodeID; -import org.junit.Test; -import static org.junit.Assert.*; +import org.junit.jupiter.api.Test; import java.util.*; import java.util.function.Function; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class ReverseLookupComputingCacheEntryListenerTest { /**