Search in sources :

Example 1 with Expectations

use of org.jmock.Expectations in project RoboBinding by RoboBinding.

the class SimpleOneWayPropertyInfoTest method givenPrimitivePropertyType_thenReturnBoxedType.

@Test
public void givenPrimitivePropertyType_thenReturnBoxedType() {
    final SetterElement setter = context.mock(SetterElement.class);
    final WrappedPrimitiveType primitiveType = context.mock(WrappedPrimitiveType.class);
    context.checking(new Expectations() {

        {
            oneOf(setter).parameterType();
            will(returnValue(primitiveType));
            oneOf(primitiveType).isPrimitive();
            will(returnValue(true));
            oneOf(primitiveType).boxedClassName();
            will(returnValue(Integer.class.getName()));
        }
    });
    SimpleOneWayPropertyInfo info = new SimpleOneWayPropertyInfo(setter);
    assertThat(info.propertyType(), equalTo(Integer.class.getName()));
}
Also used : Expectations(org.jmock.Expectations) SetterElement(org.robobinding.codegen.apt.element.SetterElement) WrappedPrimitiveType(org.robobinding.codegen.apt.type.WrappedPrimitiveType) Test(org.junit.Test)

Example 2 with Expectations

use of org.jmock.Expectations in project RoboBinding by RoboBinding.

the class ElementWrapperTest method whenWrapSupportedElements_thenReturnCoorespondingWrappedInstance.

@Theory
public void whenWrapSupportedElements_thenReturnCoorespondingWrappedInstance(@FromDataPoints("supportedElements") ElementToWrapped elementToWrapped) {
    Mockery context = new ClassMockery();
    final TypeMirrorWrapper typeWrapper = context.mock(TypeMirrorWrapper.class);
    context.checking(new Expectations() {

        {
            allowing(typeWrapper).wrap(with(any(TypeMirror.class)));
            will(returnValue(null));
        }
    });
    ElementWrapper wrapper = new ElementWrapper(typeWrapper, null, null, null);
    AbstractWrappedElement wrapped = wrapper.wrap(elementToWrapped.element);
    assertThat(wrapped, isA(elementToWrapped.wrappedType));
}
Also used : Expectations(org.jmock.Expectations) TypeMirror(javax.lang.model.type.TypeMirror) TypeMirrorWrapper(org.robobinding.codegen.apt.type.TypeMirrorWrapper) ClassMockery(org.robobinding.codegen.ClassMockery) ClassMockery(org.robobinding.codegen.ClassMockery) Mockery(org.jmock.Mockery) Theory(org.junit.experimental.theories.Theory)

Example 3 with Expectations

use of org.jmock.Expectations in project RoboBinding by RoboBinding.

the class WrappedPrimitiveTypeTest method shouldGetCorrectBoxedClassName.

@Theory
public void shouldGetCorrectBoxedClassName(@FromDataPoints("primitiveBoxedClassNames") PrimitiveTypeToClassName typeToBoxedClassName) {
    ClassMockery context = new ClassMockery();
    final TypeMirrorWrapper wrapper = context.mock(TypeMirrorWrapper.class);
    final WrappedDeclaredType integerDeclaredType = context.mock(WrappedDeclaredType.class);
    final WrappedDeclaredType booleanDeclaredType = context.mock(WrappedDeclaredType.class);
    context.checking(new Expectations() {

        {
            allowing(integerDeclaredType).className();
            will(returnValue(Integer.class.getName()));
            allowing(wrapper).wrap(declaredTypeOf(Integer.class));
            will(returnValue(integerDeclaredType));
            allowing(booleanDeclaredType).className();
            will(returnValue(Boolean.class.getName()));
            allowing(wrapper).wrap(declaredTypeOf(Boolean.class));
            will(returnValue(booleanDeclaredType));
        }
    });
    WrappedPrimitiveType type = new WrappedPrimitiveType(typeToBoxedClassName.type, compilation.getTypes(), wrapper);
    assertThat(type.boxedClassName(), equalTo(typeToBoxedClassName.className));
}
Also used : Expectations(org.jmock.Expectations) ClassMockery(org.robobinding.codegen.ClassMockery) Theory(org.junit.experimental.theories.Theory)

Example 4 with Expectations

use of org.jmock.Expectations in project nhin-d by DirectProject.

the class CertificateServiceTest method testListCertificates.

/**
     * Test the listCertificates method.
     */
public void testListCertificates() {
    final CertificateDao certificateDao = context.mock(CertificateDao.class);
    final Long certificateId = 7L;
    final int maxResults = 7;
    final CertificateGetOptions certificateOptions = CertificateGetOptions.DEFAULT;
    context.checking(new Expectations() {

        {
            oneOf(certificateDao).list((String) null);
            will(returnValue(Collections.<Certificate>emptyList()));
        }
    });
    CertificateServiceImpl service = new CertificateServiceImpl();
    service.setDao(certificateDao);
    try {
        Collection<Certificate> output = service.listCertificates(certificateId, maxResults, certificateOptions);
        assertNotNull("Output is null when using valid params", output);
        assertEquals("Output does not match mocked return value when using valid params", Collections.<Certificate>emptyList(), output);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateGetOptions(org.nhindirect.config.service.impl.CertificateGetOptions) CertificateDao(org.nhindirect.config.store.dao.CertificateDao) CertificateServiceImpl(org.nhindirect.config.service.impl.CertificateServiceImpl) Certificate(org.nhindirect.config.store.Certificate)

Example 5 with Expectations

use of org.jmock.Expectations in project nhin-d by DirectProject.

the class CertificateServiceTest method testAddCertificates.

/**
     * Test the addCertificates method.
     */
public void testAddCertificates() {
    final CertificateDao certificateDao = context.mock(CertificateDao.class);
    final Collection<Certificate> certificates = Arrays.asList(new Certificate());
    context.checking(new Expectations() {

        {
            oneOf(certificateDao).save(certificates.iterator().next());
        }
    });
    CertificateServiceImpl service = new CertificateServiceImpl();
    service.setDao(certificateDao);
    try {
        service.addCertificates(certificates);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) CertificateDao(org.nhindirect.config.store.dao.CertificateDao) CertificateServiceImpl(org.nhindirect.config.service.impl.CertificateServiceImpl) Certificate(org.nhindirect.config.store.Certificate)

Aggregations

Expectations (org.jmock.Expectations)1209 Test (org.junit.Test)864 Mockery (org.jmock.Mockery)120 UnitTest (org.apache.geode.test.junit.categories.UnitTest)109 File (java.io.File)66 ArrayList (java.util.ArrayList)59 Before (org.junit.Before)54 DocumentReference (org.xwiki.model.reference.DocumentReference)51 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)41 HashMap (java.util.HashMap)38 InternalCache (org.apache.geode.internal.cache.InternalCache)35 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)33 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)32 Test (org.testng.annotations.Test)32 Resource (org.apache.sling.api.resource.Resource)31 RewriterResponse (org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse)31 Sequence (org.jmock.Sequence)28 Invocation (org.jmock.api.Invocation)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)23 DiskStore (org.apache.geode.cache.DiskStore)23