本文整理匯總了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"));
}