<commit_before>package org.jboss.resteasy.springmvc.test.spring;

import static org.jboss.resteasy.test.TestPortProvider.createClientRequest;

import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;

import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.springmvc.tjws.TJWSEmbeddedSpringMVCServer;
import org.jboss.resteasy.test.TestPortProvider;
import org.jboss.resteasy.util.FindAnnotation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Qualifier;

public class RequestScopedBeanTest {
	@Provider
	public static class QualifierInjectorFactoryImpl extends InjectorFactoryImpl implements BeanFactoryAware {
		BeanFactory beanFactory;

		public QualifierInjectorFactoryImpl(ResteasyProviderFactory factory) {
			super(factory);
		}

		@SuppressWarnings("unchecked")
		@Override
		public ValueInjector createParameterExtractor(Class injectTargetClass, AccessibleObject injectTarget, Class type, Type genericType, Annotation[] annotations) {
			final Qualifier qualifier = FindAnnotation.findAnnotation(annotations, Qualifier.class);
			if (qualifier == null) {
				return super.createParameterExtractor(injectTargetClass, injectTarget, type, genericType, annotations);
			} else {
				return new ValueInjector() {
					public Object inject(HttpRequest request, HttpResponse response) {
						return beanFactory.getBean(qualifier.value());
					}

					public Object inject() {
						// do nothing.
						return null;
					}
				};
			}
		}

		@Override
		public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
			this.beanFactory = beanFactory;
		}
	}
	
	public static class TestBean{
		String configured;
		
		public void setConfigured(String configured) {
			this.configured = configured;
		}
	}

	@Path("/")
	public static class TestBeanResource{
		@GET
		public String test(@Qualifier("testBean") TestBean bean){
			return bean.configured;
		}
	}
	
	private TJWSEmbeddedSpringMVCServer server;

	@Before
	public void startServer() {
		server = new TJWSEmbeddedSpringMVCServer("classpath:spring-request-scope-test-server.xml", TestPortProvider.getPort());
		server.start();
	}

	@After
	public void stopServer() {
		server.stop();
	}
	
	@Test
	public void testBean() throws Exception{
		String result = createClientRequest("/").accept(MediaType.TEXT_PLAIN_TYPE).get(String.class).getEntity();
		System.out.println(result);
	}
	
}<commit_msg>format fixing for RequesetScoedBeanTest and an additional "assertTrue"<commit_after>package org.jboss.resteasy.springmvc.test.spring;

import static org.jboss.resteasy.test.TestPortProvider.createClientRequest;

import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;

import junit.framework.Assert;

import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.springmvc.tjws.TJWSEmbeddedSpringMVCServer;
import org.jboss.resteasy.test.TestPortProvider;
import org.jboss.resteasy.util.FindAnnotation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Qualifier;

public class RequestScopedBeanTest
{
   @Provider
   public static class QualifierInjectorFactoryImpl extends InjectorFactoryImpl implements
         BeanFactoryAware
   {
      BeanFactory beanFactory;

      public QualifierInjectorFactoryImpl(ResteasyProviderFactory factory)
      {
         super(factory);
      }

      @SuppressWarnings("unchecked")
      @Override
      public ValueInjector createParameterExtractor(Class injectTargetClass,
            AccessibleObject injectTarget, Class type, Type genericType, Annotation[] annotations)
      {
         final Qualifier qualifier = FindAnnotation.findAnnotation(annotations, Qualifier.class);
         if (qualifier == null)
         {
            return super.createParameterExtractor(injectTargetClass, injectTarget, type,
                  genericType, annotations);
         }
         else
         {
            return new ValueInjector()
            {
               public Object inject(HttpRequest request, HttpResponse response)
               {
                  return beanFactory.getBean(qualifier.value());
               }

               public Object inject()
               {
                  // do nothing.
                  return null;
               }
            };
         }
      }

      @Override
      public void setBeanFactory(BeanFactory beanFactory) throws BeansException
      {
         this.beanFactory = beanFactory;
      }
   }

   public static class TestBean
   {
      String configured;

      public void setConfigured(String configured)
      {
         this.configured = configured;
      }
   }

   @Path("/")
   public static class TestBeanResource
   {
      @GET
      public String test(@Qualifier("testBean") TestBean bean)
      {
         return bean.configured;
      }
   }

   private TJWSEmbeddedSpringMVCServer server;

   @Before
   public void startServer()
   {
      server = new TJWSEmbeddedSpringMVCServer("classpath:spring-request-scope-test-server.xml",
            TestPortProvider.getPort());
      server.start();
   }

   @After
   public void stopServer()
   {
      server.stop();
   }

   @Test
   public void testBean() throws Exception
   {
      String result = createClientRequest("/").accept(MediaType.TEXT_PLAIN_TYPE).get(String.class)
            .getEntity();
     Assert.assertEquals("configuredValue", result);
   }

}
{'fraction_non_alphanumeric': 0.09068664933476067, 'fraction_numerical': 0.0, 'mean_word_length': 3.583041345480028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7156187', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1857, 'n_words': 361}