本文整理汇总了Java中org.jmock.Mock.proxy方法的典型用法代码示例。如果您正苦于以下问题:Java Mock.proxy方法的具体用法?Java Mock.proxy怎么用?Java Mock.proxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jmock.Mock
的用法示例。
在下文中一共展示了Mock.proxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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]);
}
}
示例2: testGermanDate
import org.jmock.Mock; //导入方法依赖的package包/类
public void testGermanDate()
{
DateTimeConverter dtConv = new DateTimeConverter();
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
String inputValue = "30.06.09 12:11 Uhr ";
dtConv.setType("both");
dtConv.setTimeStyle("full");
dtConv.setLocale(Locale.GERMAN);
dtConv.setTimeZone(TimeZone.getTimeZone ("America/New_York"));
dtConv.setPattern("dd.MM.yy HH:mm' Uhr '");
Date dt = (Date) dtConv.getAsObject(facesContext, component, inputValue);
assertNotNull(dt);
mock.verify();
}
示例3: testSanitySuccess
import org.jmock.Mock; //导入方法依赖的package包/类
public void testSanitySuccess()
{
//some very basic sanity test
//
DoubleRangeValidator validator = new DoubleRangeValidator();
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
Double values[] = {200d,500d};
validator.setMinimum(2);
for (int i = 0; i < values.length ; i++)
{
doTestValidate(validator, facesContext, wrapper, values[i]);
}
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: testSettingFractDigitsAndSettingMinDigitsAreHononured
import org.jmock.Mock; //导入方法依赖的package包/类
public void testSettingFractDigitsAndSettingMinDigitsAreHononured()
{
Number[] inputValues = {new Long(1234), new Double(1234.5678), new Double(1234), new Double(10.00)};
String[] expectedValues = {"1,234", "34.57", "1,234", "10.00"};
int[] maxFractDigits = {0, 2, 2, 2};
int[] maxIntDigits = {4, 2, 4, 3};
int[] minIntDigits = {4, 1, 2, 1};
int[] minFractDigits = {0, 2, 0, 2};
NumberConverter converter = getNumberConverter();
Mock mock = mock(UIComponent.class);
UIComponent component = (UIComponent) mock.proxy();
//we do not care about getValueExpression() being called or not
mock.stubs().method("getValueExpression");
setFacesContext(facesContext);
try
{
converter.setLocale(Locale.US);
for (int i = 0; i < maxFractDigits.length; i++)
{
converter.setMaxFractionDigits(maxFractDigits[i]);
converter.setMaxIntegerDigits(maxIntDigits[i]);
converter.setMinFractionDigits(minFractDigits[i]);
converter.setMinIntegerDigits(minIntDigits[i]);
String out = converter.getAsString(facesContext, component, inputValues[i]);
assertEquals(expectedValues[i], out);
}
}
finally
{
setFacesContext(null);
}
mock.verify();
}
示例8: testNullContext
import org.jmock.Mock; //导入方法依赖的package包/类
/**
* Test when context is set to null
*/
public void testNullContext()
{
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
ByteLengthValidator validator = new ByteLengthValidator();
doTestNullContext(wrapper, validator);
}
示例9: testDefaultEncodingWorks
import org.jmock.Mock; //导入方法依赖的package包/类
public void testDefaultEncodingWorks()
{
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
ByteLengthValidator validator = new ByteLengthValidator();
String value = "four";
validator.setMaximum(4);
doTestValidate(validator, facesContext, wrapper, value);
}
示例10: 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);
ByteLengthValidator validator = new ByteLengthValidator();
int maxBytes[] = {3};
validator.setMessageDetailMaximum("\"{1}\"" + _IS_GREATER
+ maxBytes[0]);
//some very basic sanity test
String values[] = {"four"};
String encodings[] = {"ISO-8859-1"};
String expected = "\"" + values[0] + "\"" + _IS_GREATER + maxBytes[0];
try
{
validator.setMaximum(maxBytes[0]);
validator.setEncoding(encodings[0]);
validator.validate(facesContext, component, values[0]);
}
catch (ValidatorException ve)
{
String msg = ve.getFacesMessage().getDetail();
assertEquals(msg, expected);
}
}
示例11: testNullContext
import org.jmock.Mock; //导入方法依赖的package包/类
/**
* Test when context is set to null
*/
public void testNullContext()
{
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
DateTimeRangeValidator validator = new DateTimeRangeValidator();
doTestNullContext(wrapper, validator);
}
示例12: testGetAsString
import org.jmock.Mock; //导入方法依赖的package包/类
/**
* Test Color conveters getAsString(FacesContext, UIComponent, Object) method
* works fine
*/
public void testGetAsString()
{
ColorConverter converter = new ColorConverter();
Mock mock = mock(UIComponent.class);
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
Color[] colors = { new Color(255,2,4),
new Color(255,2,6),
new Color(255,255,255),
new Color(0,0,0),
new Color(105,105,105),
};
List<String[]> patternsHoloder = new ArrayList<String[]>();
patternsHoloder.add(new String[]{"#RRGGBB", "RRGGBB"});
patternsHoloder.add(new String[]{"RR.GG.BB", "#RRGGBB" });
patternsHoloder.add(new String[]{"RRGGBB", "r-g-b"});
patternsHoloder.add(new String[]{"RR GG BB", "rrr ggg bbb"});
patternsHoloder.add(new String[]{"rrr-ggg-bbb", "rrr ggg bbb" });
String matchValues[] = { "#FF0204",
"FF.02.06",
"FFFFFF",
"00 00 00",
"105-105-105",
};
for (int i = 0; i < patternsHoloder.size(); i++)
{
String[] patterns = patternsHoloder.get(i);
converter.setPatterns(patterns);
doTestGetAsString(converter, facesContext, wrapper,
colors[i], matchValues[i] );
}
mock.verify();
}
示例13: testNull
import org.jmock.Mock; //导入方法依赖的package包/类
/**
* Tests that null returns immediately.
*
* @throws ValidatorException when test fails
*/
public void testNull() throws ValidatorException
{
Mock mock = buildMockUIComponent();
UIComponent component = (UIComponent) mock.proxy();
MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
LongRangeValidator validator = new LongRangeValidator();
doTestNull(facesContext, wrapper, validator);
}
示例14: doTestProcessValidations
import org.jmock.Mock; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void doTestProcessValidations(
FacesContext context,
UIViewRoot root,
UIComponent component)
{
Mock mockUIComponent = createMockUIComponent();//mock(UIComponent.class);
UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
// JavaServer Faces 1.0 Specification, section 2.2.2
// During the apply-request-values phase,
// only the processDecodes lifecycle method may be called.
mockUIComponent.expects(once()).method("processValidators");
// These children will never get called
Mock mockBarChild = createMockUIComponent();
UIComponent barChild = (UIComponent) mockBarChild.proxy();
Mock mockOrdinaryChild = createMockUIComponent();
UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy();
// construct the UIComponent tree and
// execute the apply-request-values lifecycle phase
root.getChildren().add(component);
component.getFacets().put("foo", fooChild);
component.getFacets().put("bar", barChild);
component.getChildren().add(ordinaryChild);
root.processValidators(context);
mockUIComponent.verify();
mockBarChild.verify();
mockOrdinaryChild.verify();
}
示例15: doTestApplyRequestValues
import org.jmock.Mock; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void doTestApplyRequestValues(
FacesContext context,
UIViewRoot root,
UIComponent component)
{
Mock mockUIComponent = createMockUIComponent();
UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
// JavaServer Faces 1.0 Specification, section 2.2.2
// During the apply-request-values phase,
// only the processDecodes lifecycle method may be called.
if (component.isRendered()){
mockUIComponent.stubs().method("processDecodes").with(eq(facesContext));
}
// These children will never get called
Mock mockBarChild = createMockUIComponent();
UIComponent barChild = (UIComponent) mockBarChild.proxy();
Mock mockOrdinaryChild = createMockUIComponent();
UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy();
// construct the UIComponent tree and
// execute the apply-request-values lifecycle phase
root.getChildren().add(component);
component.getFacets().put("foo", fooChild);
component.getFacets().put("bar", barChild);
component.getChildren().add(ordinaryChild);
root.processDecodes(context);
mockUIComponent.verify();
mockBarChild.verify();
mockOrdinaryChild.verify();
}