Package org.jbehave.core.steps.ParameterConverters

Examples of org.jbehave.core.steps.ParameterConverters.NumberConverter


        return configuration;
    }
   
    private ParameterConverter[] customConverters(Keywords keywords) {
        List<ParameterConverter> converters = new ArrayList<ParameterConverter>();
        converters.add(new NumberConverter(NumberFormat.getInstance(locale())));
        converters.add(new ExamplesTableConverter(new ExamplesTableFactory(keywords)));
        return converters.toArray(new ParameterConverter[converters.size()]);
    }
View Full Code Here


        }
    }

    @Test
    public void shouldConvertValuesToNumbersWithDefaultNumberFormat() {
        NumberConverter converter = new NumberConverter();
        assertThatAllNumberTypesAreAccepted(converter);
        assertThatAllNumbersAreConverted(converter, ParameterConverters.DEFAULT_NUMBER_FORMAT_LOCAL);
    }
View Full Code Here

    }

    @Test
    public void shouldConvertValuesToNumbersWithEnglishNumberFormat() {
        Locale locale = Locale.ENGLISH;
        ParameterConverter converter = new NumberConverter(NumberFormat.getInstance(locale));
        assertConverterForLocale(converter, locale);
    }
View Full Code Here

   
    @Test
    public void shouldConvertValuesToNumbersWithEnglishNumberFormatInMultipleThreads() {
        final Locale locale = Locale.ENGLISH;
        final int threads = 3;
        final ParameterConverter converter = new NumberConverter(NumberFormat.getInstance(locale));
        final BlockingQueue<String> queue = new ArrayBlockingQueue<String>(threads);
        Thread t1 = new Thread(){
            @Override
            public void run(){
                assertConverterForLocale(converter, locale);
View Full Code Here

    }
    @Test
    public void shouldConvertValuesToNumbersWithFrenchNumberFormat() {
        Locale locale = Locale.FRENCH;
        ParameterConverter converter = new NumberConverter(NumberFormat.getInstance(locale));
        assertThatAllNumberTypesAreAccepted(converter);
        assertThatAllNumbersAreConverted(converter, locale);
        assertThat((Float) converter.convertValue("100000,01", Float.class), equalTo(100000.01f));
        assertThat((Double) converter.convertValue("100000,01", Double.class), equalTo(100000.01d));
    }
View Full Code Here

    }

    @Test
    public void shouldConvertValuesToNumbersWithGermanNumberFormat() {
        Locale locale = Locale.GERMAN;
        ParameterConverter converter = new NumberConverter(NumberFormat.getInstance(locale));       
        assertThatAllNumberTypesAreAccepted(converter);
        assertThatAllNumbersAreConverted(converter, locale);
        assertThat((BigDecimal) converter.convertValue("1.000.000,01", BigDecimal.class), equalTo(new BigDecimal("1000000.01")));
    }
View Full Code Here

        assertThat((Number) converter.convertValue("3", Number.class), equalTo((Number)3L));
    }

    @Test
    public void shouldFailToConvertInvalidNumbersWithNumberFormat() {
        NumberConverter converter = new NumberConverter();
        try {
            converter.convertValue("abc", Long.class);
        } catch (ParameterConvertionFailed e) {
            assertThat(e.getCause(), is(instanceOf(ParseException.class)));
        }
    }
View Full Code Here

        }
    }

    @Test
    public void shouldFailToConvertInvalidNumbersWithNumberFormat2()  {
        NumberConverter converter = new NumberConverter();
        try {
            converter.convertValue("12.34.56", BigDecimal.class);
        } catch (ParameterConvertionFailed e) {
            assertThat(e.getCause(), is(instanceOf(NumberFormatException.class)));
        }
    }
View Full Code Here

        }
    }

    @Test
    public void shouldConvertNaNAndInfinityValuesToNumbers() {
        ParameterConverter converter = new NumberConverter();
        assertThat((Float) converter.convertValue(NAN, Float.class), equalTo(Float.NaN));
        assertThat((Float) converter.convertValue(INFINITY, Float.class), equalTo(Float.POSITIVE_INFINITY));
        assertThat((Float) converter.convertValue("-"+INFINITY, Float.class), equalTo(Float.NEGATIVE_INFINITY));
        assertThat((Double) converter.convertValue(NAN, Double.class), equalTo(Double.NaN));
        assertThat((Double) converter.convertValue(INFINITY, Double.class), equalTo(Double.POSITIVE_INFINITY));
        assertThat((Double) converter.convertValue("-"+INFINITY, Double.class), equalTo(Double.NEGATIVE_INFINITY));
    }
View Full Code Here

TOP

Related Classes of org.jbehave.core.steps.ParameterConverters.NumberConverter

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.