Package org.mockito.stubbing

Examples of org.mockito.stubbing.Answer


    public XAConnection createXAConnection() throws JMSException {
        if (staticCreateXAConnectionException != null)
            throw staticCreateXAConnectionException;

      Answer xaSessionAnswer = new Answer<XASession>() {
        public XASession answer(InvocationOnMock invocation)throws Throwable {
          XASession mockXASession = mock(XASession.class);
          MessageProducer messageProducer = mock(MessageProducer.class);
            when(mockXASession.createProducer((Destination) anyObject())).thenReturn(messageProducer);
            MessageConsumer messageConsumer = mock(MessageConsumer.class);
View Full Code Here



        // Setup mock XAConnection
        final XAConnection mockXAConnection = mock(XAConnection.class);
        // Handle XAConnection.close(), first time we answer, after that we throw
        doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) throws Throwable {
        EventRecorder eventRecorder = EventRecorder.getEventRecorder(mockXAConnection);
        eventRecorder.addEvent(new XAConnectionCloseEvent(mockXAConnection));
        return null;
      }
View Full Code Here

        CallableStatement mockCallableStatement = mock(CallableStatement.class);
        when(mockConnection.prepareCall(anyString())).thenReturn(mockCallableStatement);
        when(mockConnection.prepareCall(anyString(), anyInt(), anyInt())).thenReturn(mockCallableStatement);
        when(mockConnection.prepareCall(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mockCallableStatement);
        // Handle Connection.close()
        doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) throws Throwable {
        EventRecorder eventRecorder = EventRecorder.getEventRecorder(mockConnection);
        eventRecorder.addEvent(new ConnectionCloseEvent(mockConnection));
        return null;
      }
        }).doThrow(new SQLException("Connection is already closed")).when(mockConnection).close();
        // Handle Connection.commit()
        doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) throws Throwable {
        EventRecorder eventRecorder = EventRecorder.getEventRecorder(mockConnection);
        eventRecorder.addEvent(new LocalCommitEvent(mockConnection, new Exception()));
        return null;
      }
        }).doThrow(new SQLException("Transaction already commited")).when(mockConnection).commit();
        // Handle Connection.rollback()
        doAnswer(new Answer() {
      public Object answer(InvocationOnMock invocation) throws Throwable {
        EventRecorder eventRecorder = EventRecorder.getEventRecorder(mockConnection);
        eventRecorder.addEvent(new LocalRollbackEvent(mockConnection, new Exception()));
        return null;
      }
View Full Code Here

     * @param returnType the Java type that the data should be converted to
     * @return a Mockito {@link org.mockito.stubbing.Answer} implementation that will load the data when requested
     */
    protected Answer withData(final String resource, final Class returnType)
    {
        return new Answer()
        {
            public Object answer(InvocationOnMock
                    invocation) throws Throwable
            {
                return loadData(resource, DataTypeFactory.create(returnType));
View Full Code Here

     * @param callback a callback can be used to manipulate the MuleMessage before it it gets returned
     * @return a Mockito {@link org.mockito.stubbing.Answer} implementation that will load the data when requested
     */
    protected Answer withData(final String resource, final MimeType mimeType, final MockMessageCallback callback, final Object ibean)
    {
        return new Answer()
        {
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                MimeType mime = mimeType;
                DataType ret = ((MockIBean)ibean).ibeanReturnType();
View Full Code Here

        ServletDispatcher dispatcher = new ServletDispatcher();
        Servlet servlet = mock(Servlet.class);
        HttpContext context = mock(HttpContext.class);
        ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);

        doAnswer(new Answer()
        {
            public Object answer(InvocationOnMock invocation)
            {
                HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
                resp.setStatus(HttpServletResponse.SC_OK);
View Full Code Here

        ServletDispatcher dispatcher = new ServletDispatcher();
        Servlet servlet = mock(Servlet.class);
        HttpContext context = mock(HttpContext.class);
        ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);

        when(context.handleSecurity(request, response)).thenAnswer(new Answer()
        {
            public Boolean answer(InvocationOnMock invocation)
            {
                HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
                resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
View Full Code Here

        ServletDispatcher dispatcher = new ServletDispatcher();
        Servlet servlet = mock(Servlet.class);
        HttpContext context = mock(HttpContext.class);
        ServletRegistration registration = new ServletRegistration("/", servlet, context);

        doAnswer(new Answer()
        {
            public Object answer(InvocationOnMock invocation)
            {
                HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
                resp.setStatus(HttpServletResponse.SC_OK);
View Full Code Here

        ServletDispatcher dispatcher = new ServletDispatcher();
        Servlet servlet = mock(Servlet.class);
        HttpContext context = mock(HttpContext.class);
        ServletRegistration registration = new ServletRegistration("/cad", servlet, context);

        doAnswer(new Answer()
        {
            public Object answer(InvocationOnMock invocation)
            {
                HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
                resp.setStatus(HttpServletResponse.SC_OK);
View Full Code Here

        ServletDispatcher dispatcher = new ServletDispatcher();
        Servlet servlet = mock(Servlet.class);
        HttpContext context = mock(HttpContext.class);
        ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);

        doAnswer(new Answer()
        {
            public Object answer(InvocationOnMock invocation)
            {
                HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
                resp.setStatus(HttpServletResponse.SC_OK);
View Full Code Here

TOP

Related Classes of org.mockito.stubbing.Answer

Copyright © 2018 www.massapicom. 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.