package org.jboss.weld.tck;

import javax.enterprise.inject.UnproxyableResolutionException;
import javax.enterprise.inject.spi.BeanManager;
import javax.servlet.ServletContext;

import org.jboss.jsr299.tck.spi.Managers;
import org.jboss.testharness.impl.runner.servlet.ServletTestRunner;
import org.jboss.weld.DefinitionException;
import org.jboss.weld.DeploymentException;
import org.jboss.weld.mock.MockServletContext;
import org.jboss.weld.servlet.ServletHelper;

public class ManagersImpl implements Managers
{
   
   private static final ServletContext SERVLET_CONTEXT = new MockServletContext("");

   public BeanManager getManager()
   {
      if (ServletTestRunner.getCurrentServletContext() != null)
      {
         return ServletHelper.getModuleBeanManager(ServletTestRunner.getCurrentServletContext());
      }
      else
      {
         return ServletHelper.getModuleBeanManager(SERVLET_CONTEXT);
      }
   }

   public boolean isDefinitionError(org.jboss.testharness.api.DeploymentException deploymentException)
   {
      return isDefinitionException(deploymentException.getCause());
   }

   private boolean isDefinitionException(Throwable t)
   {
      if (t == null)
      {
         return false;
      }
      else if (DefinitionException.class.isAssignableFrom(t.getClass()))
      {
         return true;
      }
      else
      {
         return isDefinitionException(t.getCause());
      }
   }

   public boolean isDeploymentError(org.jboss.testharness.api.DeploymentException deploymentException)
   {
      return isDeploymentException(deploymentException.getCause());
   }

   public boolean isDeploymentException(Throwable t)
   {
      if (t == null)
      {
         return false;
      }
      else if (DeploymentException.class.isAssignableFrom(t.getClass()))
      {
         return true;
      }
      else if (UnproxyableResolutionException.class.isAssignableFrom(t.getClass()))
      {
         return true;
      }
      else
      {
         return isDeploymentException(t.getCause());
      }
   }
}

@@ -136,45 +136,8 @@
 ger;
-%0Aimport javax.servlet.ServletContext;
 %0A%0Aim
@@ -180,76 +180,8 @@
 rs;%0A
-import org.jboss.testharness.impl.runner.servlet.ServletTestRunner;%0A
 impo
@@ -288,530 +288,176 @@
 eld.
-mock.MockServletContext;%0Aimport org.jboss.weld.servlet.ServletHelper;%0A%0Apublic class ManagersImpl implements Managers%0A%7B%0A   %0A   private static final ServletContext SERVLET_CONTEXT = new MockServletContext(%22%22);%0A%0A   public BeanManager getManager()%0A   %7B%0A      if (ServletTestRunner.getCurrentServletContext() != null)%0A      %7B%0A         return ServletHelper.getModuleBeanManager(ServletTestRunner.getCurrentServletContext());%0A      %7D%0A      else%0A      %7B%0A         return ServletHelper.getModuleBeanManager(SERVLET_CONTEXT);%0A      %7D
+test.BeanManagerLocator;%0A%0Apublic class ManagersImpl implements Managers%0A%7B%0A   %0A   public BeanManager getManager()%0A   %7B%0A      return BeanManagerLocator.INSTANCE.locate();
 %0A   

Use BeanManagerLocator