当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了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));
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:28,代码来源:BeanMessageInterpolatorTest.java

示例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"));
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:27,代码来源:BeanMessageInterpolatorTest.java

示例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"));
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:34,代码来源:BeanMessageInterpolatorTest.java


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