Search in sources :

Example 1 with SimpleScalar

use of freemarker.template.SimpleScalar in project ninja by ninjaframework.

the class TemplateEngineFreemarkerI18nMethodTest method testThatKeyWithPlaceholderReturnsDefaultKeyWhenKeyCannotBeFound.

@Test
public void testThatKeyWithPlaceholderReturnsDefaultKeyWhenKeyCannotBeFound() throws Exception {
    Optional<Result> resultOptional = Optional.of(result);
    List args = new ArrayList();
    args.add(new SimpleScalar("my.message.key"));
    args.add(new SimpleScalar("1000"));
    Mockito.when(messages.get(Matchers.eq("my.message.key"), Matchers.eq(context), Matchers.eq(resultOptional), Matchers.any(Object.class))).thenReturn(Optional.<String>empty());
    TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
    assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("my.message.key"));
    // There must have been logged something because we did not find
    // the value for the key...
    Mockito.verify(mockAppender).doAppend(Matchers.anyObject());
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TemplateModel(freemarker.template.TemplateModel) SimpleScalar(freemarker.template.SimpleScalar) Result(ninja.Result) Test(org.junit.Test)

Example 2 with SimpleScalar

use of freemarker.template.SimpleScalar in project ninja by ninjaframework.

the class TemplateEngineFreemarkerI18nMethodTest method testThatSingleKeyWithValueWorks.

@Test
public void testThatSingleKeyWithValueWorks() throws Exception {
    Optional<Result> resultOptional = Optional.of(result);
    Mockito.when(messages.get("my.message.key", context, resultOptional)).thenReturn(Optional.of("This simulates the translated message!"));
    List args = new ArrayList();
    args.add(new SimpleScalar("my.message.key"));
    TemplateModel returnValue = templateEngineFreemarkerI18nMethod.exec(args);
    assertThat(((SimpleScalar) returnValue).getAsString(), CoreMatchers.equalTo("This simulates the translated message!"));
    Mockito.verify(mockAppender, Mockito.never()).doAppend(Matchers.anyObject());
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TemplateModel(freemarker.template.TemplateModel) SimpleScalar(freemarker.template.SimpleScalar) Result(ninja.Result) Test(org.junit.Test)

Example 3 with SimpleScalar

use of freemarker.template.SimpleScalar in project ninja by ninjaframework.

the class TemplateEngineFreemarkerPrettyTimeMethod method exec.

@Override
public TemplateModel exec(List args) throws TemplateModelException {
    Date date = getFormattableObject(args.get(0));
    String result = prettyTime.format(date);
    return new SimpleScalar(result);
}
Also used : SimpleScalar(freemarker.template.SimpleScalar) SimpleDate(freemarker.template.SimpleDate) Date(java.util.Date)

Example 4 with SimpleScalar

use of freemarker.template.SimpleScalar in project android by JetBrains.

the class FmUnderscoreToCamelCaseMethodTest method check.

@SuppressWarnings("rawtypes")
private void check(String s, String expected) throws TemplateModelException {
    FmUnderscoreToCamelCaseMethod method = new FmUnderscoreToCamelCaseMethod();
    List list = Collections.singletonList(new SimpleScalar(s));
    assertEquals(expected, ((SimpleScalar) method.exec(list)).getAsString());
}
Also used : List(java.util.List) SimpleScalar(freemarker.template.SimpleScalar)

Example 5 with SimpleScalar

use of freemarker.template.SimpleScalar in project android by JetBrains.

the class FmClassNameToResourceMethodTest method check.

@SuppressWarnings("rawtypes")
private void check(String s, String expected) throws TemplateModelException {
    FmClassNameToResourceMethod method = new FmClassNameToResourceMethod();
    List list = Collections.singletonList(new SimpleScalar(s));
    assertEquals(expected, ((SimpleScalar) method.exec(list)).getAsString());
}
Also used : List(java.util.List) SimpleScalar(freemarker.template.SimpleScalar)

Aggregations

SimpleScalar (freemarker.template.SimpleScalar)21 List (java.util.List)17 ArrayList (java.util.ArrayList)5 SimpleNumber (freemarker.template.SimpleNumber)4 TemplateModel (freemarker.template.TemplateModel)4 Result (ninja.Result)4 Test (org.junit.Test)4 TemplateModelException (freemarker.template.TemplateModelException)2 ContainerUtil.newArrayList (com.intellij.util.containers.ContainerUtil.newArrayList)1 StringModel (freemarker.ext.beans.StringModel)1 SimpleDate (freemarker.template.SimpleDate)1 Date (java.util.Date)1 ConstraintViolation (ninja.validation.ConstraintViolation)1