Package org.jmock

Examples of org.jmock.Mockery


    private String TEST_CLASSES_PATH = null;

    @Override
    public void setUp() throws Exception {
        super.setUp();
        Mockery mockery = new Mockery();
        final RuntimeContext context = mockery.mock(RuntimeContext.class);
        mockery.checking(new Expectations() {{
            allowing(context).getAttribute(WinkConfiguration.class); will(returnValue(null));
        }});
       
        RuntimeContextTLS.setRuntimeContext(context);
    }
View Full Code Here


    @Test
    public void testJdbcLockConfigOverride() throws Exception {

        JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter();
        Mockery context = new Mockery();
        final DataSource dataSource = context.mock(DataSource.class);
        final Connection connection = context.mock(Connection.class);
        final DatabaseMetaData metadata = context.mock(DatabaseMetaData.class);
        final ResultSet result = context.mock(ResultSet.class);
        adapter.setDataSource(dataSource);
        adapter.setCreateTablesOnStartup(false);

        context.checking(new Expectations() {{
            allowing(dataSource).getConnection();
            will(returnValue(connection));
            allowing(connection).getMetaData();
            will(returnValue(metadata));
            allowing(connection);
View Full Code Here

    }

    public void testJdbcLockConfigDefault() throws Exception {

        JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter();
        Mockery context = new Mockery();
        final DataSource dataSource = context.mock(DataSource.class);
        final Connection connection = context.mock(Connection.class);
        final DatabaseMetaData metadata = context.mock(DatabaseMetaData.class);
        final ResultSet result = context.mock(ResultSet.class);
        adapter.setDataSource(dataSource);
        adapter.setCreateTablesOnStartup(false);

        context.checking(new Expectations() {{
            allowing(dataSource).getConnection();
            will(returnValue(connection));
            allowing(connection).getMetaData();
            will(returnValue(metadata));
            allowing(connection);
View Full Code Here

   
    @Before
    public void setUp() throws Exception
    {
        super.setUp();
        context = new Mockery() {{
            setImposteriser(ClassImposteriser.INSTANCE);
        }};
       
        org.apache.activemq.ActiveMQConnectionFactory factory =
                new org.apache.activemq.ActiveMQConnectionFactory(BROKER_URL);
View Full Code Here

        Class.forName(OracleDataType.class.getName());
    }

    @Before
    public void setUp() throws Exception {
        context = new Mockery();
        statement = context.mock(PreparedStatement.class);
        create = new OracleFactory((Connection) null);
    }
View Full Code Here

   * Get a new {@link Mockery} instance.
   *
   * @return a new {@link Mockery} instance
   */
  public static Mockery getNewInstance() {
    return new Mockery() {
      {
        setImposteriser(ClassImposteriser.INSTANCE);
      }
    };
  }
View Full Code Here

    }

    @Override
    public void prepareTestInstance(TestContext context) {
        List<Field> mocks = context.introspector().selectFields(fieldsAnnotatedBy(Mock.class));
        Mockery mockery = findProvidedMockery(context);
        if (mockery == null) {
            mockery = new Mockery();
            for (Field mock : mocks) {
                if (!mock.getType().isInterface()) {
                    mockery.setImposteriser(ClassImposteriser.INSTANCE);
                    break;
                }
            }
        }
        context.attributes().set(MOCKERY, mockery);
        for (Field field : context.introspector().selectFields(and(fieldsAccepting(Mockery.class), fieldsAnnotatedBy(MockContext.class)))) {
            context.introspector().set(field, mockery);
        }
        for (Field field : mocks) {
            context.introspector().set(field, mockery.mock(field.getType(), field.getDeclaringClass().getName() + "." + field.getName()));
        }
    }
View Full Code Here

public class JMockFramework implements MockFramework {

  public Map<Field, Object> getValues(Field[] fields) throws Exception {
    final Map<Field,Object> jmockFields = new HashMap<Field,Object>();

    Mockery mockery = null;
    final Set<Object> ignored = new HashSet<Object>();

    for ( Field field : fields ) {
      if ( Mockery.class.isAssignableFrom(field.getType())) {
        if ( field.getAnnotation(Mock.class) != null )
          throw new IncompatibleAnnotationException(Mock.class, field.getType());

        if ( Mockery.class.equals(field.getType())) {
          mockery = new Mockery();
        } else {
          mockery = (Mockery)field.getType().newInstance();
        }
        jmockFields.put(field, mockery);
        break;
      }
    }

    for ( Field field : fields ) {
      boolean isMock = (field.getAnnotation(Mock.class) != null);
      boolean isStub = (field.getAnnotation(Stub.class) != null);
      if ( !isMock && !isStub ) continue;
      if ( isMock && (mockery == null) ) throw new NoMockeryException();
      if ( isStub && (mockery == null) ) mockery = new Mockery();

      Class<?> fieldType = field.getType();
      if ( fieldType.isArray() ) {
        Object[] array = (Object[])Array.newInstance(fieldType.getComponentType(), 3);
        for ( int i = 0; i < array.length; i++ ) {
          array[i] = mockery.mock(fieldType.getComponentType());
          if ( isStub ) {
            ignored.add(array[i]);
          }
        }
        jmockFields.put(field, array);

      } else {
        Object mock = mockery.mock(field.getType());
        if ( isStub ) {
          ignored.add(mock);
        }

        jmockFields.put(field, mock);
      }

    }

    if ( !ignored.isEmpty() && mockery != null) {
      Expectations expectations = new Expectations() {{
        for ( Object mock : ignored ) {
          ignoring(mock);
        }
      }};

            mockery.checking(expectations);
        }

    return jmockFields;
  }
View Full Code Here

        mockery.assertIsSatisfied();
    }

    @MockContextProvider
    Mockery buildMockery() {
        Mockery m = new Mockery();
        m.setImposteriser(ClassImposteriser.INSTANCE);
        m.setNamingScheme(LastWordNamingScheme.INSTANCE);
        m.setExpectationErrorTranslator(null);
        return m;
    }
View Full Code Here

    TestContext ctx;
    JMock2TestPlugin plugin = new JMock2TestPlugin();

    @BeforeMethod
    public void setup() {
        mockery = new Mockery();
        ctx = mockery.mock(TestContext.class);
    }
View Full Code Here

TOP

Related Classes of org.jmock.Mockery

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.