Package org.jbehave.core.steps.ParameterConverters

Examples of org.jbehave.core.steps.ParameterConverters.NumberConverter.convertValue()


    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));
    }

    @Test
    public void shouldConvertValuesToNumbersWithGermanNumberFormat() {
View Full Code Here


        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));
    }

    @Test
    public void shouldConvertValuesToNumbersWithGermanNumberFormat() {
        Locale locale = Locale.GERMAN;
View Full Code Here

    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")));
    }

    private void assertThatAllNumberTypesAreAccepted(ParameterConverter converter) {
        assertThat(converter.accept(Byte.class), equalTo(true));
        assertThat(converter.accept(byte.class), equalTo(true));
View Full Code Here

    @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

    @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

    @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

    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));
    }

    @SuppressWarnings("unchecked")
View Full Code Here

        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));
    }

    @SuppressWarnings("unchecked")
    @Test
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.