/*
 * JBoss, Home of Professional Open Source
 * Copyright 2010, Red Hat Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.msc.service;

import org.junit.Assert;
import org.junit.Test;

/**
 * @author Stuart Douglas
 */
public class InstallDoesNotClearContextClassLoaderTestCase extends AbstractServiceTest {

    @Test
    public void testServiceInstallationDoesNotClearTCCL() {
            serviceContainer.addListener(new AbstractServiceListener<Object>() {

            });
            final ClassLoader classLoader = new ClassLoader() {

            };
            Thread.currentThread().setContextClassLoader(classLoader);
            try {
                serviceContainer.addService(ServiceName.of("nothingService"), Service.NULL).install();
                Assert.assertEquals(classLoader, Thread.currentThread().getContextClassLoader());
            } finally {
                Thread.currentThread().setContextClassLoader(null);
            }
    }
}

@@ -1284,36 +1284,32 @@
 CCL() %7B%0A        
-    
 serviceContainer
@@ -1374,85 +1374,598 @@
     
-    %7D);%0A            final ClassLoader classLoader = new ClassLoader() %7B%0A%0A    
+%7D);%0A        final ClassLoader classLoader = new ClassLoader() %7B%0A%0A        %7D;%0A        Thread.currentThread().setContextClassLoader(classLoader);%0A        try %7B%0A            serviceContainer.addService(ServiceName.of(%22nothingService%22), Service.NULL).install();%0A            Assert.assertEquals(classLoader, Thread.currentThread().getContextClassLoader());%0A        %7D finally %7B%0A            Thread.currentThread().setContextClassLoader(null);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void setAddListenerDoesNotClearTCCL() %7B%0A        serviceContainer.addListener(new AbstractServiceListener%3CObject%3E() %7B%0A%0A
     
@@ -1965,30 +1965,99 @@
 %7B%0A%0A        %7D
+)
 ;%0A    
+    final ClassLoader classLoader = new ClassLoader() %7B%0A%0A        %7D;%0A
         Thre
@@ -2115,28 +2115,24 @@
 r);%0A        
-    
 try %7B%0A      
@@ -2129,35 +2129,68 @@
 y %7B%0A            
-   
+ServiceController%3CVoid%3E controller =
  serviceContaine
@@ -2210,39 +2210,40 @@
 ServiceName.of(%22
-nothing
+listener
 Service%22), Servi
@@ -2258,32 +2258,117 @@
 .install();%0A    
+        controller.addListener(new AbstractServiceListener%3CVoid%3E() %7B%0A            %7D);%0A
             Asse
@@ -2449,28 +2449,24 @@
 ));%0A        
-    
 %7D finally %7B%0A
@@ -2457,36 +2457,32 @@
     %7D finally %7B%0A
-    
             Thre
@@ -2525,28 +2525,24 @@
 ader(null);%0A
-    
         %7D%0A  

Test addListener does not clear the TCCL