本文整理汇总了Java中org.jmock.Mock类的典型用法代码示例。如果您正苦于以下问题:Java Mock类的具体用法?Java Mock怎么用?Java Mock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mock类属于org.jmock包,在下文中一共展示了Mock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExceptionalEvents
import org.jmock.Mock; //导入依赖的package包/类
public void testExceptionalEvents() throws MalformedURLException,
InterruptedException
{
Mock testListenerMock = this.buildMockForExceptionalCall();
FakeListener fakeListener = (FakeListener) this.servlet.getListeners().getListener(LISTENER_NAME);
fakeListener.setDelegate((JrpipEventListener) testListenerMock.proxy());
Echo echo = this.buildEchoProxy();
try
{
echo.throwUnexpectedException();
}
catch (RuntimeException e)
{
//caught test exception
}
testListenerMock.verify();
}
示例2: setUp
import org.jmock.Mock; //导入依赖的package包/类
@Override
protected void setUp() throws Exception
{
super.setUp();
FacesContext oldFacesContext = facesContext;
UIViewRoot oldViewRoot = oldFacesContext.getViewRoot();
oldFacesContext.release();
facesContext = new MockFacesContext12(externalContext,
lifecycle,
application);
facesContext.setViewRoot(oldViewRoot);
facesContext.setApplication(application);
facesContext.getViewRoot().setRenderKitId("org.apache.myfaces.trinidad.core");
RenderKitFactory renderKitFactory = (RenderKitFactory)
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
Mock mockRenderKitty = mock(RenderKit.class);
RenderKit renderKit = (RenderKit) mockRenderKitty.proxy();
_mockRenderKit = new MockRenderKitWrapper(mockRenderKitty, renderKit);
renderKitFactory.addRenderKit("org.apache.myfaces.trinidad.core", renderKit);
}
示例3: buildMockUIComponent
import org.jmock.Mock; //导入依赖的package包/类
/**
* Builds a MockUIComponent with attributes setup for the requested number of
* test iterations.
*/
protected Mock buildMockUIComponent(
int iterations,
String attributeNames[]
)
{
int i;
Mock c = mock(UIComponent.class);
Map<String, Object> attrs = new HashMap<String, Object>();
for (i = 0; i < attributeNames.length; i++)
attrs.put(attributeNames[i], attributeNames[i]);
for (i = 0; i < iterations; i++)
{
c.stubs().method("getAttributes").will(returnValue(attrs));
c.stubs().method("getId").will(returnValue("mockId"));
}
return c;
}
示例4: doTestIsNotString
import org.jmock.Mock; //导入依赖的package包/类
public void doTestIsNotString(Validator validator)
{
Mock mock = mock(UIComponent.class);
UIComponent component = (UIComponent) mock.proxy();
mock.stubs().method("getId").will(returnValue("test"));
try
{
validator.validate(facesContext, component, new Integer(1));
// if exception is not thrown - mark it as an failure
fail("Expected Validator Exception");
}
catch (IllegalArgumentException iae)
{
// if exception then fine.
}
}
示例5: testSanitySuccess
import org.jmock.Mock; //导入依赖的package包/类
/**
* Test that basic test passes
*/
public void testSanitySuccess()
{
ByteLengthValidator validator = new ByteLengthValidator();
//some very basic sanity test
String values[] = {"four"};
String encodings[] = {"ISO-8859-1"};
int maxBytes[] = {4};
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
for (int i = 0; i < values.length ; i++)
{
validator.setEncoding(encodings[i]);
validator.setMaximum(maxBytes[i]);
doTestValidate(validator, facesContext, wrapper, values[i]);
}
}
示例6: doTestValidateFailure
import org.jmock.Mock; //导入依赖的package包/类
protected void doTestValidateFailure(
UIViewRoot root)
{
// -= Simon =-
// All those variables do not seem to be used and do not seem
// to test anything either
/*Mock mockRenderkit = getMockRenderKitWrapper().getMock();
RenderKit renderkit = getMockRenderKitWrapper().getRenderKit();
*/
Mock mockRenderer = mock(Renderer.class);
/*Renderer renderer = (Renderer) mockRenderer.proxy();
Mock mockValidator = mock(Validator.class);
Validator validator = (Validator) mockValidator.proxy();
ViewHandler viewhandler = this.facesContext.getApplication().getViewHandler();*/
setCurrentContext(facesContext);
root.processValidators(facesContext);
mockRenderer.verify();
setCurrentContext(null);
}
示例7: testNonDate
import org.jmock.Mock; //导入依赖的package包/类
/**
* Tests that non Date objects throw a ValidationException.
*/
public void testNonDate()
{
DateTimeRangeValidator validator = new DateTimeRangeValidator();
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
mock.stubs().method("getId").will(returnValue("test"));
try
{
setFacesContext(facesContext);
validator.validate(facesContext, component, "not-a-date");
fail("ValidatorException not thrown");
}
catch (IllegalArgumentException iae)
{
// pass
}
finally
{
setFacesContext(null);
}
mock.verify();
}
示例8: testBeforeMaximumDate
import org.jmock.Mock; //导入依赖的package包/类
/**
* Tests that dates before the maximum date are valid.
*
* @throws ValidatorException when test fails
*/
public void testBeforeMaximumDate() throws ValidatorException
{
long millis = System.currentTimeMillis();
DateTimeRangeValidator validator = new DateTimeRangeValidator();
validator.setMaximum(new Date(millis));
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
try
{
setFacesContext(facesContext);
validator.validate(facesContext, component, new Date(millis - 1));
}
finally
{
setFacesContext(null);
}
mock.verify();
}
示例9: testWithinDateRange
import org.jmock.Mock; //导入依赖的package包/类
/**
* Tests that dates within the date range are valid.
*
* @throws ValidatorException when test fails
*/
public void testWithinDateRange() throws ValidatorException
{
long millis = System.currentTimeMillis();
DateTimeRangeValidator validator = new DateTimeRangeValidator();
validator.setMinimum(new Date(millis));
validator.setMaximum(new Date(millis + 2));
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
try
{
setFacesContext(facesContext);
validator.validate(facesContext, component, new Date(millis + 1));
}
finally
{
setFacesContext(null);
}
mock.verify();
}
示例10: testStateHolderSaveRestore
import org.jmock.Mock; //导入依赖的package包/类
/**
* Tests that dates after the date range cause a ValidationException.
*/
public void testStateHolderSaveRestore()
{
long millis = System.currentTimeMillis();
DateTimeRangeValidator originalValidator = new DateTimeRangeValidator();
originalValidator.setMinimum(new Date(millis));
originalValidator.setMaximum(new Date(millis + 10));
originalValidator.setMessageDetailMinimum("min");
originalValidator.setMessageDetailMaximum("max");
originalValidator.setMessageDetailNotInRange("not in range");
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
DateTimeRangeValidator restoredValidator = new DateTimeRangeValidator();
doTestStateHolderSaveRestore(originalValidator, restoredValidator,
facesContext, wrapper);
}
示例11: testNonDate
import org.jmock.Mock; //导入依赖的package包/类
/**
* Tests that non Date objects throw a ValidationException.
*/
public void testNonDate()
{
DateRestrictionValidator validator = new DateRestrictionValidator();
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
mock.stubs().method("getId").will(returnValue("test"));
try
{
setFacesContext(facesContext);
validator.validate(facesContext, component, "not-a-date");
fail("ValidatorException not thrown");
}
catch (IllegalArgumentException iae)
{
// pass
}
finally
{
setFacesContext(null);
}
mock.verify();
}
示例12: testPatternNotSet
import org.jmock.Mock; //导入依赖的package包/类
/**
* Test that pattern when not set throws null pointer exceptin
*/
public void testPatternNotSet()
{
// since the pattern has not been set it will be null
// let us push some arbitary value
Mock mock = mock(UIComponent.class);
UIComponent component = (UIComponent) mock.proxy();
try
{
RegExpValidator validator = new RegExpValidator();
validator.validate(facesContext, component, "someValue");
// test fails if it is here
fail("Expected Null pointer exception");
}
catch (NullPointerException npe)
{
// suppress it - this is as expected
}
mock.verify();
}
示例13: testBlankValueOnPattern
import org.jmock.Mock; //导入依赖的package包/类
/**
* Test that pattern when set to "" should fail validation
*/
public void testBlankValueOnPattern()
{
// some very basic sanity test
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
setMockLabelForComponent(wrapper);
try
{
RegExpValidator validator = new RegExpValidator();
String value = "999999";
validator.setPattern("");
validator.validate(facesContext, component, value);
fail("Expected ValidatorException");
}
catch (ValidatorException ve)
{
// if exception then fine.
}
mock.verify();
}
示例14: testSanitySuccess
import org.jmock.Mock; //导入依赖的package包/类
/**
* Simple test case which is expected to pass
* @todo need to add many test cases - add string to the values and
* patterns to patterns array.
*
*/
public void testSanitySuccess()
{
//some very basic sanity test
//
RegExpValidator validator = new RegExpValidator();
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
String values[] = {"9123456","9x"};
String patterns[] = {"[0-9]*","[9][x]"};
for (int i = 0; i < values.length ; i++)
{
validator.setPattern(patterns[i]);
doTestValidate(validator, facesContext, wrapper, values[i]);
}
}
示例15: testValueSetInRequestContextIsHonoured
import org.jmock.Mock; //导入依赖的package包/类
public void testValueSetInRequestContextIsHonoured()
{
//ugly ?
_mafct.release();
_mafct = null;
_mafct = new MockRequestContext();
_mafct.setDecimalSeparator('*');
_mafct.setNumberGroupingSeparator('!');
_mafct.setCurrencyCode(null);
Mock mock = mock(UIComponent.class);
UIComponent component = (UIComponent) mock.proxy();
NumberConverter conv = getNumberConverter();
conv.setLocale(Locale.US);
Number inputValue = new Double(8989.789);
String out = conv.getAsString(facesContext, component, inputValue);
assertEquals("8!989*789", out);
mock.verify();
}