0 Replies Latest reply on Jan 22, 2016 9:06 AM by Sanket Patel

    Problem

    Sanket Patel Newbie

      Hello,

       

      I was tring to use mockito with arquillian.

      I used with simple JUnit and it runs fine although i am trying to figure out the deployment for arquillian which is where i think the problem is !!!

      Can anyone help me to figure out ?

       

      Thank you.

       

      package mockito_test;

       

       

      import static org.junit.Assert.assertEquals;

      import static org.mockito.Mockito.verify;

      import static org.mockito.Mockito.when;

       

       

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.spec.WebArchive;

      import org.jboss.shrinkwrap.resolver.api.maven.Maven;

      import org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem;

      import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;

      import org.junit.Before;

      import org.junit.Test;

      import org.junit.runner.RunWith;

      import org.mockito.Mock;

      import org.mockito.MockitoAnnotations;

       

       

      @RunWith(Arquillian.class)

       

       

      public class BookDALTest {

       

       

        @Deployment

        public static WebArchive deploy() {

       

       

       

        return ShrinkWrap.create(WebArchive.class).addAsLibraries("resolver");

        }

       

       

        @Mock

        Book book;

       

       

        @Before

        public void setUp() {

        MockitoAnnotations.initMocks(this);

        }

       

       

        @Test

        public void addBookTest() {

        BookDAL bo = new BookDAL();

       

       

        when(book.getIsbn()).thenReturn(new String("8131721019"));

        assertEquals("8131721019", bo.addBook(book));

        verify(book).getIsbn(); // To verify that the geISBN method was called

       

       

        }

       

       

      }

       

       

       

       

      pom.xml

       

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        <modelVersion>4.0.0</modelVersion>

        <groupId>org.router.test-cases</groupId>

        <artifactId>test-cases</artifactId>

        <version>1.0-SNAPSHOT</version>

        <packaging>jar</packaging>

       

       

        <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        </properties>

       

       

       

       

       

       

        <build>

        <defaultGoal>test</defaultGoal>

        <plugins>

        <!-- The compiler plugin enforces Java 1.6 compatibility and controls

        execution of annotation processors -->

        <plugin>

        <artifactId>maven-compiler-plugin</artifactId>

        <version>2.3.2</version>

        <configuration>

        <source>1.8</source>

        <target>1.8</target>

        </configuration>

        </plugin>

        <plugin>

        <artifactId>maven-surefire-plugin</artifactId>

        <version>2.12</version>

        </plugin>

        </plugins>

        </build>

        <dependencyManagement>

        <dependencies>

        <dependency>

        <groupId>org.jboss.arquillian</groupId>

        <artifactId>arquillian-bom</artifactId>

        <version>1.1.9.Final</version>

        <scope>import</scope>

        <type>pom</type>

        </dependency>

        </dependencies>

        </dependencyManagement>

        <dependencies>

       

       

        <!-- Dependency for Mockito -->

       

       

        <dependency>

        <groupId>org.mockito</groupId>

        <artifactId>mockito-core</artifactId>

        <version>2.0.39-beta</version>

        </dependency>

       

       

        <dependency>

        <groupId>org.apache.maven</groupId>

        <artifactId>maven-aether-provider</artifactId>

        <version>3.0.5</version>

        <scope>test</scope>

        </dependency>

        <dependency>

        <groupId>junit</groupId>

        <artifactId>junit</artifactId>

        <version>4.12</version>

        <scope>test</scope>

        </dependency>

        <dependency>

        <groupId>org.jboss.arquillian.junit</groupId>

        <artifactId>arquillian-junit-container</artifactId>

        <scope>test</scope>

        </dependency>

       

       

       

       

        <dependency>

        <groupId>org.wildfly.arquillian</groupId>

        <artifactId>wildfly-arquillian-container-managed</artifactId>

        <version>1.0.2.Final</version>

        <scope>test</scope>

        </dependency>

       

       

       

       

        <dependency>

        <groupId>org.jboss.shrinkwrap.resolver</groupId>

        <artifactId>shrinkwrap-resolver-api</artifactId>

        <scope>test</scope>

        </dependency>

        <dependency>

        <groupId>org.jboss.shrinkwrap.resolver</groupId>

        <artifactId>shrinkwrap-resolver-api-maven</artifactId>

        <scope>test</scope>

        </dependency>

        <dependency>

        <groupId>org.jboss.shrinkwrap.resolver</groupId>

        <artifactId>

        shrinkwrap-resolver-api-maven-archive

        </artifactId>

        <scope>test</scope>

        </dependency>

        </dependencies>

       

       

      </project>