Package org.jboss.arquillian.impl.execution

Source Code of org.jboss.arquillian.impl.execution.LocalTestExecuterTestCase

/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.arquillian.impl.execution;

import java.lang.reflect.Method;

import junit.framework.Assert;

import org.jboss.arquillian.impl.AbstractManagerTestBase;
import org.jboss.arquillian.impl.core.ManagerBuilder;
import org.jboss.arquillian.impl.execution.LocalTestExecuter;
import org.jboss.arquillian.impl.execution.event.LocalExecutionEvent;
import org.jboss.arquillian.spi.ServiceLoader;
import org.jboss.arquillian.spi.TestMethodExecutor;
import org.jboss.arquillian.spi.TestResult;
import org.jboss.arquillian.spi.core.annotation.ApplicationScoped;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;


/**
* InContainerExecuterTestCase
*
* @author <a href="mailto:aknutsen@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
@RunWith(MockitoJUnitRunner.class)
public class LocalTestExecuterTestCase extends AbstractManagerTestBase
{
   @Override
   protected void addExtensions(ManagerBuilder builder)
   {
      builder.extension(LocalTestExecuter.class);
   }
  
   @Mock
   private TestMethodExecutor testExecutor;

   @Mock
   private ServiceLoader serviceLoader;
  
   @Test
   public void shouldReturnPassed() throws Throwable
   {
      bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
     
      Mockito.when(testExecutor.getInstance()).thenReturn(this);
      Mockito.when(testExecutor.getMethod()).thenReturn(
            getTestMethod("shouldReturnPassed"));
     
      fire(new LocalExecutionEvent(testExecutor));
     
      TestResult result = getManager().resolve(TestResult.class);
      Assert.assertNotNull(
            "Should have set result",
            result);

      Assert.assertEquals(
            "Should have passed test",
            TestResult.Status.PASSED,
            result.getStatus());

      Assert.assertNull(
            "Should not have set cause",
            result.getThrowable());
   }

   @Test
   public void shouldReturnFailedOnException() throws Throwable
   {
      bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
     
      Exception exception = new Exception();
     
      Mockito.when(testExecutor.getInstance()).thenReturn(this);
      Mockito.when(testExecutor.getMethod()).thenReturn(
            getTestMethod("shouldReturnFailedOnException"));
      Mockito.doThrow(exception).when(testExecutor).invoke();
     
     
      fire(new LocalExecutionEvent(testExecutor));

      TestResult result = getManager().resolve(TestResult.class);
      Assert.assertNotNull(
            "Should have set result",
            result);

      Assert.assertEquals(
            "Should have failed test",
            TestResult.Status.FAILED,
            result.getStatus());

      Assert.assertEquals(
            "Should have set failed cause",
            exception,
            result.getThrowable());
   }

   private Method getTestMethod(String name) throws Exception
   {
      return this.getClass().getMethod(name);
   }
}
TOP

Related Classes of org.jboss.arquillian.impl.execution.LocalTestExecuterTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.