本文整理汇总了Java中javax.validation.MessageInterpolator.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于javax.validation.MessageInterpolator包,在下文中一共展示了Context类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDefaultConstructor
import javax.validation.MessageInterpolator.Context; //导入依赖的package包/类
/**
* JAVADOC Method Level Comments
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testDefaultConstructor() {
Context context = mock(Context.class);
ConstraintDescriptor cd = mock(ConstraintDescriptor.class);
Map<String, Object> atts = new HashMap<String, Object>();
String[] properties = { "name", "value" };
atts.put("properties", properties);
when(cd.getAttributes()).thenReturn(atts);
when(context.getConstraintDescriptor()).thenReturn(cd);
Foo foo = new Foo();
foo.setName("Name");
foo.setValue(200);
when(context.getValidatedValue()).thenReturn(foo);
BeanMessageInterpolator interpolator = new BeanMessageInterpolator();
assertEquals("message Name and 200",
interpolator.interpolate("message {0} and {1}", context));
}
示例2: testInterpolateStringContext
import javax.validation.MessageInterpolator.Context; //导入依赖的package包/类
/**
* JAVADOC Method Level Comments
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testInterpolateStringContext() {
Context context = mock(Context.class);
ConstraintDescriptor cd = mock(ConstraintDescriptor.class);
Map<String, Object> atts = new HashMap<String, Object>();
when(cd.getAttributes()).thenReturn(atts);
when(context.getConstraintDescriptor()).thenReturn(cd);
Foo foo = new Foo();
when(context.getValidatedValue()).thenReturn(foo);
MessageInterpolator delegate = mock(MessageInterpolator.class);
when(delegate.interpolate("message", context)).thenReturn("MEssAGE");
BeanMessageInterpolator interpolator = new BeanMessageInterpolator(delegate);
interpolator.interpolate("message", context);
assertEquals(foo, atts.get("0"));
}
示例3: testInterpolateStringContextLocale
import javax.validation.MessageInterpolator.Context; //导入依赖的package包/类
/**
* JAVADOC Method Level Comments
*/
@SuppressWarnings("unchecked")
@Test
public void testInterpolateStringContextLocale() {
Context context = mock(Context.class);
@SuppressWarnings("rawtypes")
ConstraintDescriptor cd = mock(ConstraintDescriptor.class);
Map<String, Object> atts = new HashMap<String, Object>();
String[] properties = { "name", "value" };
atts.put("properties", properties);
when(cd.getAttributes()).thenReturn(atts);
when(context.getConstraintDescriptor()).thenReturn(cd);
Foo foo = new Foo();
foo.setName("Name");
foo.setValue(200);
when(context.getValidatedValue()).thenReturn(foo);
MessageInterpolator delegate = mock(MessageInterpolator.class);
when(delegate.interpolate("message", context, Locale.getDefault())).thenReturn("MEssAGE");
BeanMessageInterpolator interpolator = new BeanMessageInterpolator(delegate);
interpolator.interpolate("message", context, Locale.getDefault());
assertEquals("Name", atts.get("0"));
assertEquals("200", atts.get("1"));
}