use of org.apache.tapestry5.Translator in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_translator.
@Test
public void default_translator() {
ComponentResources resources = mockComponentResources();
FieldTranslator translator = mockFieldTranslator();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
train_createDefaultTranslator(source, resources, "object", translator);
replay();
ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
assertSame(provider.defaultTranslator("object", resources), translator);
verify();
}
use of org.apache.tapestry5.Translator in project tapestry-5 by apache.
the class TranslatorSourceImplTest method unknown_translator_is_failure.
@Test
public void unknown_translator_is_failure() {
Translator fred = mockTranslator("fred", String.class);
Translator barney = mockTranslator("barney", Long.class);
Map<Class, Translator> configuration = CollectionFactory.newMap();
configuration.put(String.class, fred);
configuration.put(Long.class, barney);
replay();
TranslatorSource source = new TranslatorSourceImpl(configuration);
try {
source.get("wilma");
unreachable();
} catch (UnknownValueException ex) {
assertMessageContains(ex, "Unknown translator type 'wilma'.");
}
}
use of org.apache.tapestry5.Translator in project tapestry-5 by apache.
the class TranslatorSourceImplTest method get_by_type_not_found.
@Test
public void get_by_type_not_found() {
Translator string = mockTranslator("string", String.class);
Translator bool = mockTranslator("bool", Boolean.class);
Map<Class, Translator> configuration = CollectionFactory.newMap();
configuration.put(String.class, string);
configuration.put(Boolean.class, bool);
replay();
TranslatorSource source = new TranslatorSourceImpl(configuration);
try {
source.getByType(Integer.class);
unreachable();
} catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "No translator is defined for type java.lang.Integer. Registered types: java.lang.Boolean, java.lang.String.");
}
verify();
}
use of org.apache.tapestry5.Translator in project tapestry-5 by apache.
the class TranslatorSourceImplTest method name_collision_with_standard_translators.
@Test
public void name_collision_with_standard_translators() {
Translator t1 = mockTranslator("fred", Integer.class);
Translator t2 = mockTranslator("fred", Long.class);
Map<Class, Translator> configuration = CollectionFactory.newMap();
configuration.put(Integer.class, t1);
configuration.put(Long.class, t2);
replay();
try {
new TranslatorSourceImpl(configuration);
unreachable();
} catch (RuntimeException ex) {
assertMessageContains(ex, "Two different Translators contributed to the TranslatorSource service use the same translator name: 'fred'.", "Translator names must be unique.");
}
verify();
}
use of org.apache.tapestry5.Translator in project tapestry-5 by apache.
the class TranslatorSourceImplTest method get_alternate_translator_by_name.
@Test
public void get_alternate_translator_by_name() {
Translator t1 = mockTranslator("fred", Integer.class);
Translator t2 = mockTranslator();
Map<Class, Translator> configuration = newConfiguration(Integer.class, t1);
Map<String, Translator> alternates = CollectionFactory.newMap();
alternates.put("barney", t2);
replay();
TranslatorSource source = new TranslatorSourceImpl(configuration, alternates);
assertSame(source.get("barney"), t2);
verify();
}
Aggregations