• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Mock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jmock.Mock的典型用法代码示例。如果您正苦于以下问题:Java Mock类的具体用法?Java Mock怎么用?Java Mock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Mock类属于org.jmock包,在下文中一共展示了Mock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:21,代码来源:JrpipListenerTest.java


示例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);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:22,代码来源:FacesTestCase.java


示例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;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:23,代码来源:AbstractBaseTestCase.java


示例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.
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:17,代码来源:ValidatorTestCase.java


示例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]);
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:24,代码来源:ByteLengthValidatorTest.java


示例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);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:UIComponentTestCase.java


示例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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:28,代码来源:DateTimeRangeValidatorTest.java


示例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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:DateTimeRangeValidatorTest.java


示例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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:28,代码来源:DateTimeRangeValidatorTest.java


示例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);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:24,代码来源:DateTimeRangeValidatorTest.java


示例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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:28,代码来源:DateRestrictionValidatorTest.java


示例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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:RegExpValidatorTest.java


示例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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:27,代码来源:RegExpValidatorTest.java


示例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]);
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:24,代码来源:RegExpValidatorTest.java


示例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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:22,代码来源:TrinidadNumberConverterTest.java


示例16: testCustomMessageIsSet

import org.jmock.Mock; //导入依赖的package包/类
public void testCustomMessageIsSet()
{
  Mock mock = buildMockUIComponent();
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);
  RegExpValidator validator = new RegExpValidator();

  validator.setPattern("[0-9]*");
  validator.setMessageDetailNoMatch("\"{0}\" in \"{1}\" failed!! {4}");
  //some very basic sanity test

  try
  {
    validator.validate(facesContext, component, "9123456");
  }
  catch (ValidatorException ve)
  {
    String msg = ve.getFacesMessage().getDetail();
    assertEquals(msg, "\"four\" in \"label\" failed!! [0-9]*");
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:23,代码来源:RegExpValidatorTest.java


示例17: testTooLarge

import org.jmock.Mock; //导入依赖的package包/类
public void testTooLarge()
{
  // 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();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);

  try
  {
    LongRangeValidator validator = new LongRangeValidator();
    validator.setMaximum(100);
    validator.validate(facesContext, component, 1000);
    // test fails if it is here

    fail("Expected Null pointer exception");
  }
  catch (ValidatorException ve)
  {
    // suppress it - this is as expected
  }
  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:LongRangeValidatorTest.java


示例18: testExactFailure

import org.jmock.Mock; //导入依赖的package包/类
public void testExactFailure()
{
  // some very basic sanity test
  Mock mock = buildMockUIComponent();
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);

  try
  {
    LongRangeValidator validator = new LongRangeValidator();
    long value = 20;
    validator.setMinimum(2);
    validator.setMaximum(2);
    validator.validate(facesContext, component, value);
    fail("Expected ValidatorException for exact");
  }
  catch (ValidatorException ve)
  {
    // if exception then fine.
  }

  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:LongRangeValidatorTest.java


示例19: testSanitySuccess

import org.jmock.Mock; //导入依赖的package包/类
public void testSanitySuccess()
{
  //some very basic sanity test
  //
  LongRangeValidator validator = new LongRangeValidator();
  Mock mock = buildMockUIComponent();
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);

  Long values[]   = {200l,500l};
  validator.setMinimum(2);
  for (int i = 0; i < values.length ; i++)
  {
    doTestValidate(validator, facesContext, wrapper, values[i]);
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:17,代码来源:LongRangeValidatorTest.java


示例20: testTooLargeLength

import org.jmock.Mock; //导入依赖的package包/类
public void testTooLargeLength()
{
  // 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();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);

  try
  {
    LengthValidator validator = new LengthValidator();
    validator.setMaximum(2);
    validator.validate(facesContext, component, "someValue");
    // test fails if it is here

    fail("Expected Null pointer exception");
  }
  catch (ValidatorException ve)
  {
    // suppress it - this is as expected
  }
  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:LengthValidatorTest.java



注:本文中的org.jmock.Mock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Bean类代码示例发布时间:2022-05-20
下一篇:
Java PropertyAccessor类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap