當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。