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()));
}
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));
}
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));
}
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");
}
}
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");
}
}
Aggregations