Package lesson05

Examples of lesson05.Translator


    public static void main(String[] args) throws IOException {

        //initialization

        SourceLoader sourceLoader = new SourceLoader();
        Translator translator = new Translator(new URLSourceProvider());

        Scanner scanner = new Scanner(System.in);
        System.out.println("Type <exit> or enter the path to a file that need to be translated: ");
        String command = scanner.next();

        while (!"exit".equals(command)) {

            //      So, the only way to stop the application is to do that manually or type "exit"
            // paths:
            // /home/av/Downloads/1.txt
            // https://dl.dropboxusercontent.com/u/14434019/en.txt

            try {
                String source = sourceLoader.loadSource(command);
                String translation = translator.translate(source);

                System.out.println("Original: " + source);
                System.out.println("Translation: " + translation);
View Full Code Here


    public static void main(String[] args) throws IOException {

        //initialization

        SourceLoader sourceLoader = new SourceLoader();
        Translator translator = new Translator(new URLSourceProvider());

        Scanner scanner = new Scanner(System.in);
        System.out.println("Type <exit> or enter the path to a file that need to be translated: ");
        String command = scanner.next();
View Full Code Here

        return newMock(FieldTranslator.class);
    }

    protected final Translator mockTranslator(String name, Class type)
    {
        Translator translator = mockTranslator();

        train_getName(translator, name);
        train_getType(translator, type);

        return translator;
View Full Code Here


    @Test
    public void found_translator_by_name()
    {
        Translator translator = mockTranslator("mock", String.class);

        Collection<Translator> configuration = CollectionFactory.newList(translator);

        replay();
View Full Code Here

    }

    @Test
    public void unknown_translator_is_failure()
    {
        Translator fred = mockTranslator("fred", String.class);
        Translator barney = mockTranslator("barney", Long.class);

        Collection<Translator> configuration = CollectionFactory.newList(fred, barney);

        replay();
View Full Code Here

    }

    @Test(dataProvider = "to_client_data")
    public void to_client(Class type, Object value, String expected)
    {
        Translator t = source.getByType(type);

        String actual = t.toClient(value);

        assertEquals(actual, expected);
    }
View Full Code Here

    }

    @Test(dataProvider = "parse_client_success_data")
    public void parse_client(Class type, String input, Object expected) throws Exception
    {
        Translator t = source.getByType(type);

        Object actual = t.parseClient(null, input, null);

        assertEquals(actual, expected);
    }
View Full Code Here

    }

    @Test(dataProvider = "parse_client_failure_data")
    public void parse_client_failure(Class type, String input, String expectedMessage)
    {
        Translator t = source.getByType(type);
        Field field = mockField();

        replay();

        try
        {
            t.parseClient(field, input, expectedMessage);
            unreachable();
        }
        catch (ValidationException ex)
        {
            assertEquals(ex.getMessage(), expectedMessage);
View Full Code Here

    }

    @Test
    public void find_by_type()
    {
        Translator t = mockTranslator("string", String.class);
        Collection<Translator> configuration = CollectionFactory.newList(t);

        replay();

        TranslatorSource source = new TranslatorSourceImpl(configuration);
View Full Code Here

    }

    @Test
    public void get_by_type_not_found()
    {
        Translator string = mockTranslator("string", String.class);
        Translator bool = mockTranslator("bool", Boolean.class);

        Collection<Translator> configuration = CollectionFactory.newList(string, bool);

        replay();
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.