Package lesson05

Examples of lesson05.Translator


    }

    @Test
    public void get_by_type_not_found()
    {
        Translator string = mockTranslator();
        Translator bool = mockTranslator();

        Map<String, Translator> configuration = CollectionFactory.newMap();

        configuration.put("string", string);
        configuration.put("boolean", bool);
View Full Code Here


    @Test
    public void default_translator()
    {
        TranslatorSource source = mockTranslatorSource();
        ComponentResources resources = mockComponentResources();
        Translator translator = mockTranslator();

        train_getBoundType(resources, "object", Integer.class);

        expect(source.findByType(Integer.class)).andReturn(translator);
View Full Code Here

    }

    public Translator get(String name)
    {

        Translator result = translators.get(name);

        if (result == null)
            throw new RuntimeException(ServicesMessages.unknownTranslatorType(name, InternalUtils
                    .sortedKeys(translators)));
View Full Code Here

        return result;
    }

    public Translator getByType(Class valueType)
    {
        Translator result = registry.get(valueType);

        if (result == null)
        {
            List<String> names = CollectionFactory.newList();
View Full Code Here

    @Test
    public void create_default_translator_with_annotation()
    {
        TranslatorSource ts = mockTranslatorSource();
        AnnotationProvider ap = mockAnnotationProvider("fred");
        Translator t = mockTranslator();

        expect(ts.get("fred")).andReturn(t);

        replay();
View Full Code Here

        Messages messages = mockMessages();
        Locale locale = Locale.ENGLISH;
        Class propertyType = Map.class;
        TranslatorSource ts = mockTranslatorSource();
        FormSupport fs = mockFormSupport();
        Translator translator = mockTranslator("maptrans", Map.class);
        Messages globalMessages = mockMessages();
        MessageFormatter formatter = mockMessageFormatter();
        MarkupWriter writer = mockMarkupWriter();
        String label = "Field Label";
        String message = "Woops, did it again.";
        AnnotationProvider ap = mockAnnotationProvider(null);

        train_findByType(ts, propertyType, translator);

        train_getFormValidationId(fs, "myform");

        train_contains(messages, "myform-myfield-maptrans-message", false);
        train_contains(messages, "myfield-maptrans-message", false);
        train_getMessageKey(translator, "mykey");
        train_getMessageFormatter(globalMessages, "mykey", formatter);
        train_getLabel(field, label);
        train_format(formatter, message, label);

        translator.render(field, message, writer, fs);

        replay();

        FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, globalMessages, fs);
View Full Code Here

        Messages messages = mockMessages();
        Locale locale = Locale.ENGLISH;
        Class propertyType = Map.class;
        TranslatorSource ts = mockTranslatorSource();
        FormSupport fs = mockFormSupport();
        Translator translator = mockTranslator("maptrans", Map.class);
        MessageFormatter formatter = mockMessageFormatter();
        MarkupWriter writer = mockMarkupWriter();
        String label = "My Label";
        String message = "Formatted Message";
        AnnotationProvider ap = mockAnnotationProvider(null);

        train_findByType(ts, propertyType, translator);

        train_getFormValidationId(fs, "myform");

        train_contains(messages, "myform-myfield-maptrans-message", false);
        train_contains(messages, "myfield-maptrans-message", true);
        train_getMessageFormatter(messages, "myfield-maptrans-message", formatter);

        train_getLabel(field, label);
        train_format(formatter, message, label);

        translator.render(field, message, writer, fs);

        replay();

        FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, null, fs);
View Full Code Here

        Messages messages = mockMessages();
        Locale locale = Locale.ENGLISH;
        Class propertyType = Map.class;
        TranslatorSource ts = mockTranslatorSource();
        FormSupport fs = mockFormSupport();
        Translator translator = mockTranslator("maptrans", Map.class);
        MessageFormatter formatter = mockMessageFormatter();
        MarkupWriter writer = mockMarkupWriter();
        String label = "My Label";
        String message = "Formatted Message";
        AnnotationProvider ap = mockAnnotationProvider(null);

        train_findByType(ts, propertyType, translator);

        train_getFormValidationId(fs, "myform");

        train_contains(messages, "myform-myfield-maptrans-message", true);
        train_getMessageFormatter(messages, "myform-myfield-maptrans-message", formatter);

        train_getLabel(field, label);
        train_format(formatter, message, label);

        translator.render(field, message, writer, fs);

        replay();

        FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, null, fs);
View Full Code Here

        ComponentResources resources = mockComponentResources();
        FieldComponent field = mockFieldComponent();
        Messages messages = mockMessages();
        TranslatorSource ts = mockTranslatorSource();
        FormSupport fs = mockFormSupport();
        Translator translator = mockTranslator("map", Map.class);
        Messages globalMessages = mockMessages();
        MessageFormatter formatter = mockMessageFormatter();
        MarkupWriter writer = mockMarkupWriter();
        String label = "My Label";
        String message = "Formatted Message";

        train_getComponent(resources, field);
        train_getId(resources, "myfield");
        train_getContainerMessages(resources, messages);

        train_get(ts, "map", translator);

        train_getFormValidationId(fs, "myform");

        train_contains(messages, "myform-myfield-map-message", false);
        train_contains(messages, "myfield-map-message", false);
        train_getMessageKey(translator, "mykey");
        train_getMessageFormatter(globalMessages, "mykey", formatter);

        train_getLabel(field, label);
        train_format(formatter, message, label);

        translator.render(field, message, writer, fs);

        replay();

        FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, globalMessages, fs);
View Full Code Here

        Defense.notNull(locale, "locale");


        if (propertyType == null) return null;

        Translator translator = translatorSource.findByType(propertyType);

        if (translator == null) return null;

        return createTranslator(field, overrideId, overrideMessages, locale, translator);
    }
View Full Code Here

TOP

Related Classes of lesson05.Translator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.