Package org.apache.isis.applib.value

Examples of org.apache.isis.applib.value.Money


    }

    @Test
    public void testDecoding() {
        final Object restored = adapter.fromEncodedString("23.77 FFR");
        final Money expected = new Money(23.77, "FFR");
        assertEquals(expected, restored);
    }
View Full Code Here


        assertEquals(expected, restored);
    }

    @Test
    public void testTitleOfWithPounds() {
        originalMoney = new Money(10.5, "gbp");
        assertEquals(POUND_SYMBOL + "10.50", adapter.displayTitleOf(originalMoney, (Localization) null));
    }
View Full Code Here

        assertEquals("10.50 UNK", adapter.displayTitleOf(createMoney(10.50, "UNK"), (Localization) null));
    }

    @Test
    public void testUserEntryWithCurrency() {
        final Money money = createMoney(10.5, "gbp");
        final Money parsed = adapter.parseTextEntry(money, "22.45 USD", null);
        assertEquals(new Money(22.45, "usd"), parsed);
    }
View Full Code Here

        assertEquals(new Money(22.45, "usd"), parsed);
    }

    @Test
    public void testNewUserEntryUsesPreviousCurrency() {
        originalMoney = new Money(10.5, "gbp");
        final Object parsed = adapter.parseTextEntry(originalMoney, "22.45", null);
        assertEquals(new Money(22.45, "gbp"), parsed);
    }
View Full Code Here

    @Test
    public void testReplacementEntryForDefaultCurrency() {
        // MoneyValueSemanticsProvider adapter = new
        // MoneyValueSemanticsProvider(new Money(10.3, "gbp"));
        final Object parsed = adapter.parseTextEntry(originalMoney, POUND_SYMBOL + "80.90", null);
        assertEquals(new Money(80.90, "gbp"), parsed);
    }
View Full Code Here

        }
    }

    @Test
    public void testNewValueDefaultsToLocalCurrency() throws Exception {
        final Money parsed = adapter.parseTextEntry(originalMoney, "3021.50", null);
        assertEquals(POUND_SYMBOL + "3,021.50", adapter.displayTitleOf(parsed, (Localization) null));
    }
View Full Code Here

        assertEquals(POUND_SYMBOL + "3,021.50", adapter.displayTitleOf(parsed, (Localization) null));
    }

    @Test
    public void testUnrelatedCurrencySymbolIsRejected() throws Exception {
        final Money money = createMoney(1, "eur");
        try {
            adapter.parseTextEntry(money, "$3021.50", null);
            fail("invalid code accepted " + adapter);
        } catch (final TextEntryParseException expected) {
        }
View Full Code Here

        final boolean isCurrencyCode = suffix.length() == 3 && Character.isLetter(suffix.charAt(0)) && Character.isLetter(suffix.charAt(1)) && Character.isLetter(suffix.charAt(2));
        return isCurrencyCode;
    }

    private Money parseDerivedValue(final Object original, final String entry) {
        Money money = (Money) original;
        if (money == null || money.getCurrency().equals(LOCAL_CURRENCY_CODE)) {
            try {
                final double value = DEFAULT_CURRENCY_FORMAT.parse(entry).doubleValue();
                money = new Money(value, LOCAL_CURRENCY_CODE);
                return money;
            } catch (final ParseException ignore) {
            }
        }

        try {
            final double value = DEFAULT_NUMBER_FORMAT.parse(entry).doubleValue();
            final String currencyCode = money == null ? defaultCurrencyCode : money.getCurrency();
            money = new Money(value, currencyCode);
            return money;
        } catch (final ParseException ex) {
            throw new TextEntryParseException("Not a distinguishable money value " + entry, ex);
        }
    }
View Full Code Here

            Currency.getInstance(currencyCode.toUpperCase());
        } catch (final IllegalArgumentException e) {
            throw new TextEntryParseException("Invalid currency code " + currencyCode, e);
        }
        try {
            final Money money = new Money(DEFAULT_NUMBER_FORMAT.parse(amount).doubleValue(), currencyCode);
            return money;
        } catch (final ParseException e) {
            throw new TextEntryParseException("Invalid money entry", e);
        }
    }
View Full Code Here

    @Override
    public String titleString(final Object object, final Localization localization) {
        if (object == null) {
            return "";
        }
        final Money money = (Money) object;
        final boolean localCurrency = LOCAL_CURRENCY_CODE.equals(money.getCurrency());
        if (localCurrency) {
            return DEFAULT_CURRENCY_FORMAT.format(money.doubleValue());
        } else {
            return DEFAULT_NUMBER_FORMAT.format(money.doubleValue()) + " " + money.getCurrency();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.applib.value.Money

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.