This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new 59bc6c2e3b [CXF-9023] Increase unit test coverage on 
org.apache.cxf.bus (#1901)
59bc6c2e3b is described below

commit 59bc6c2e3b7e16a0fa26a83c0d1240322c2f1321
Author: Jamie Goodyear <[email protected]>
AuthorDate: Wed Jun 19 09:40:41 2024 -0230

    [CXF-9023] Increase unit test coverage on org.apache.cxf.bus (#1901)
    
    * [CXF-9023] Increase unit test coverage on org.apache.cxf.bus
    
    * Remove the tests for classes that already have enough coverage
    
    ---------
    
    Co-authored-by: Andriy Redko <[email protected]>
---
 .../cxf/bus/managers/ServerRegistryImpTest.java    | 20 +++++-
 .../cxf/bus/resource/ResourceManagerImplTest.java  | 81 ++++++++++++++++++++++
 .../cxf/bus/spring/SpringBusFactoryTest.java       | 35 +++++++++-
 3 files changed, 133 insertions(+), 3 deletions(-)

diff --git 
a/core/src/test/java/org/apache/cxf/bus/managers/ServerRegistryImpTest.java 
b/core/src/test/java/org/apache/cxf/bus/managers/ServerRegistryImpTest.java
index 66a3bd3fdd..808d14f47b 100644
--- a/core/src/test/java/org/apache/cxf/bus/managers/ServerRegistryImpTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/managers/ServerRegistryImpTest.java
@@ -19,12 +19,15 @@
 
 package org.apache.cxf.bus.managers;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.DummyServer;
 import org.apache.cxf.endpoint.Server;
 
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
 public class ServerRegistryImpTest {
 
@@ -40,6 +43,19 @@ public class ServerRegistryImpTest {
         assertEquals("The serverList should be clear ", 
serverRegistryImpl.serversList.size(), 0);
     }
 
+    @Test
+    public void testServerRegistry() {
+        ServerRegistryImpl serverRegistryImpl = new ServerRegistryImpl();
+        assertEquals(0, serverRegistryImpl.getServers().size());
+    }
 
-
-}
\ No newline at end of file
+    @Test
+    public void testBus() {
+        ServerRegistryImpl serverRegistryImpl = new ServerRegistryImpl();
+        Bus bus = serverRegistryImpl.getBus();
+        Bus differentBus = BusFactory.getDefaultBus();
+        serverRegistryImpl.setBus(differentBus);
+        assertNotEquals(bus, differentBus);
+        assertEquals(differentBus, serverRegistryImpl.getBus());
+    }
+}
diff --git 
a/core/src/test/java/org/apache/cxf/bus/resource/ResourceManagerImplTest.java 
b/core/src/test/java/org/apache/cxf/bus/resource/ResourceManagerImplTest.java
new file mode 100644
index 0000000000..25efbfc189
--- /dev/null
+++ 
b/core/src/test/java/org/apache/cxf/bus/resource/ResourceManagerImplTest.java
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.cxf.bus.resource;
+
+import java.util.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.resource.ResourceManager;
+import org.apache.cxf.resource.ResourceResolver;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+public class ResourceManagerImplTest {
+
+    private Bus bus;
+
+    private ResourceManagerImpl resourceManager;
+
+
+    @Before
+    public void setup() {
+        BusFactory.setDefaultBus(null);
+        BusFactory.setThreadDefaultBus(null);
+        bus = BusFactory.newInstance().createBus();
+        resourceManager = new ResourceManagerImpl(bus);
+    }
+
+    @Test
+    public void testOnFirstResolve() {
+        List<ResourceResolver> beforeFirstResolve = 
resourceManager.getResourceResolvers();
+        resourceManager.onFirstResolve();
+        List<ResourceResolver> afterFirstResolve = 
resourceManager.getResourceResolvers();
+        assertEquals("No additional resolvers added.", 
beforeFirstResolve.size(),
+                afterFirstResolve.size());
+    }
+
+    @Test
+    public void testSetResolvers() {
+        List<ResourceResolver> initialResolvers = 
resourceManager.getResourceResolvers();
+        ResourceResolver mockResourceResolver = 
Mockito.mock(ResourceResolver.class);
+        List<ResourceResolver> mockResolvers = List.of(mockResourceResolver);
+        resourceManager.setResolvers(mockResolvers);
+
+        List<ResourceResolver> actual = resourceManager.getResourceResolvers();
+        assertEquals("Contains our Mock ResourceResolver", 1, actual.size());
+
+        resourceManager.setResolvers(initialResolvers);
+        actual = resourceManager.getResourceResolvers();
+        assertEquals("Initial resolvers should have been cleared by set call.",
+                0, actual.size());
+    }
+
+    @Test
+    public void testGetRegistrationType() {
+        ResourceManagerImpl impl = new ResourceManagerImpl();
+        assertEquals("ResourceManagerImpl is of type ResourceManager.class",
+                ResourceManager.class, impl.getRegistrationType());
+    }
+}
diff --git 
a/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java 
b/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
index 910938c01b..14df902178 100644
--- a/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
@@ -46,9 +46,12 @@ import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.transport.ConduitInitiatorManager;
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.apache.cxf.workqueue.WorkQueueManager;
+import org.springframework.beans.factory.xml.NamespaceHandlerResolver;
+import org.springframework.context.ApplicationContext;
 
 import org.junit.After;
 import org.junit.Test;
+import org.mockito.Mockito;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -58,6 +61,7 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
 
 public class SpringBusFactoryTest {
 
@@ -94,6 +98,26 @@ public class SpringBusFactoryTest {
 
     }
 
+    @Test
+    public void testNamespaceHandlerResolver() {
+        NamespaceHandlerResolver r = 
Mockito.mock(NamespaceHandlerResolver.class);
+        SpringBusFactory factory = new SpringBusFactory(r);
+        Bus bus = factory.createBus();
+        bus.shutdown(true);
+        verifyNoInteractions(r);
+
+        NamespaceHandlerResolver differentResolver = 
Mockito.mock(NamespaceHandlerResolver.class);
+        factory.setNamespaceHandlerResolver(differentResolver);
+        verifyNoInteractions(differentResolver);
+    }
+
+    @Test
+    public void testApplicationContext() {
+        ApplicationContext context = Mockito.mock(ApplicationContext.class);
+        SpringBusFactory factory = new SpringBusFactory(context);
+        assertEquals(context, factory.getApplicationContext());
+    }
+
     @Test
     public void testCustomFileName() {
         String cfgFile = 
"org/apache/cxf/bus/spring/resources/bus-overwrite.xml";
@@ -101,6 +125,15 @@ public class SpringBusFactoryTest {
         checkCustomerConfiguration(bus);
     }
 
+    @Test
+    public void testCustomFileNames() {
+        String cfgFile = 
"org/apache/cxf/bus/spring/resources/bus-overwrite.xml";
+        String[] cfgFiles = new String[1];
+        cfgFiles[0] = cfgFile;
+        Bus bus = new SpringBusFactory().createBus(cfgFiles);
+        checkCustomerConfiguration(bus);
+    }
+
     @Test
     public void testCustomerBusShutdown() {
         String cfgFile = "org/apache/cxf/bus/spring/customerBus.xml";
@@ -149,7 +182,7 @@ public class SpringBusFactoryTest {
         BusLifeCycleManager lifeCycleManager = 
bus.getExtension(BusLifeCycleManager.class);
         lifeCycleManager.registerLifeCycleListener(bl);
         bus.shutdown(true);
-        
+
         verify(bl).preShutdown();
         verify(bl).postShutdown();
     }

Reply via email to