Example usage for java.util Currency getInstance

List of usage examples for java.util Currency getInstance

Introduction

In this page you can find the example usage for java.util Currency getInstance.

Prototype

public static Currency getInstance(Locale locale) 

Source Link

Document

Returns the Currency instance for the country of the given locale.

Usage

From source file:org.gnucash.android.test.ui.TransactionsActivityTest.java

public void testBulkMoveTransactions() {
    String targetAccountName = "Target";
    Account account = new Account(targetAccountName);
    account.setCurrency(Currency.getInstance(Locale.getDefault()));
    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(getActivity());
    accountsDbAdapter.addAccount(account);

    int beforeOriginCount = accountsDbAdapter.getAccount(DUMMY_ACCOUNT_UID).getTransactionCount();

    mSolo.waitForText(DUMMY_ACCOUNT_NAME);

    validateTransactionListDisplayed();// w  ww  . j av a2  s  .co m

    mSolo.clickOnCheckBox(0);
    mSolo.waitForText(getActivity().getString(R.string.title_selected, 1));
    //initiate bulk move
    clickSherlockActionBarItem(R.id.context_menu_move_transactions);

    mSolo.waitForDialogToClose(2000);

    Spinner spinner = mSolo.getCurrentViews(Spinner.class).get(0);
    mSolo.clickOnView(spinner);
    mSolo.sleep(500);
    mSolo.clickOnText(targetAccountName);
    mSolo.clickOnButton(1);
    //      mSolo.clickOnText(getActivity().getString(R.string.btn_move));

    mSolo.waitForDialogToClose(2000);

    int targetCount = accountsDbAdapter.getAccount(account.getUID()).getTransactionCount();
    assertEquals(1, targetCount);

    int afterOriginCount = accountsDbAdapter.getAccount(DUMMY_ACCOUNT_UID).getTransactionCount();
    assertEquals(beforeOriginCount - 1, afterOriginCount);

    accountsDbAdapter.close();

}

From source file:com.mitre.fulfilmentprocess.test.PaymentIntegrationTest.java

protected OrderModel placeTestOrder(final boolean valid) throws InvalidCartException, CalculationException {
    final CartModel cart = cartService.getSessionCart();
    final UserModel user = userService.getCurrentUser();
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct1"), 1, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct2"), 2, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct3"), 3, null);

    final AddressModel deliveryAddress = new AddressModel();
    deliveryAddress.setOwner(user);/*from  www . j a  v a  2s . c om*/
    deliveryAddress.setFirstname("Der");
    deliveryAddress.setLastname("Buck");
    deliveryAddress.setTown("Muenchen");
    deliveryAddress.setCountry(commonI18NService.getCountry("DE"));
    modelService.save(deliveryAddress);

    final DebitPaymentInfoModel paymentInfo = new DebitPaymentInfoModel();
    paymentInfo.setOwner(cart);
    paymentInfo.setBank("MeineBank");
    paymentInfo.setUser(user);
    paymentInfo.setAccountNumber("34434");
    paymentInfo.setBankIDNumber("1111112");
    paymentInfo.setBaOwner("Ich");
    paymentInfo.setCode("testPaymentInfo1");
    modelService.save(paymentInfo);

    cart.setDeliveryMode(deliveryService.getDeliveryModeForCode("free"));
    cart.setDeliveryAddress(deliveryAddress);
    cart.setPaymentInfo(paymentInfo);

    final CardInfo card = new CardInfo();
    card.setCardType(CreditCardType.VISA);
    card.setCardNumber("4111111111111111");
    card.setExpirationMonth(Integer.valueOf(12));
    if (valid) {
        card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 2));
    } else {
        card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) - 2));
    }

    final PaymentTransactionModel paymentTransaction = paymentService.authorize("code4" + codeNo++,
            BigDecimal.ONE, Currency.getInstance("EUR"), deliveryAddress, deliveryAddress, card)
            .getPaymentTransaction();

    cart.setPaymentTransactions(Collections.singletonList(paymentTransaction));
    modelService.save(cart);
    calculationService.calculate(cart);

    final CommerceCheckoutParameter parameter = new CommerceCheckoutParameter();
    parameter.setEnableHooks(true);
    parameter.setCart(cart);
    parameter.setSalesApplication(SalesApplication.WEB);

    return commerceCheckoutService.placeOrder(parameter).getOrder();
}

From source file:biz.wolschon.fileformats.gnucash.baseclasses.SimpleAccount.java

/**
 * @return null if we are no currency but e.g. a fund
 */// w w w.j  a  v a 2 s. c om
public Currency getCurrency() {

    if (!getCurrencyNameSpace().equals(GnucashAccount.CURRENCYNAMESPACE_CURRENCY)) {
        return null;
    }

    String gnucashCurrencyID = getCurrencyID();
    return Currency.getInstance(gnucashCurrencyID);
}

From source file:fragment.web.TenantsControllerTest.java

@Test
public void testValidTrialCode() throws Exception {
    String validateResponse = controller.validatePromotionCodeforTenant("INVALID", "", "");
    Assert.assertEquals("false", validateResponse);

    PromotionSignup promotionSignup = new PromotionSignup("test" + random.nextInt(), "Citrix",
            "PromotionSignUp@citrix.com");
    promotionSignup.setCreateBy(getRootUser());
    promotionSignup.setCurrency(Currency.getInstance("USD"));
    promotionSignup.setPhone("9999999999");

    CampaignPromotion campaignPromotion = new CampaignPromotion();
    campaignPromotion.setCode("USD" + random.nextInt());
    campaignPromotion.setCreateBy(getRootUser());
    campaignPromotion.setUpdateBy(getRootUser());
    campaignPromotion.setTrial(true);/*www . j a v  a  2 s. c  o  m*/
    campaignPromotion.setCampaignPromotionsInChannels(new HashSet<CampaignPromotionsInChannels>());
    campaignPromotion = cmpdao.save(campaignPromotion);

    PromotionToken promotionToken = new PromotionToken(campaignPromotion, "TESTPROMOCODE");
    promotionToken.setCreateBy(getRootUser());
    tokendao.save(promotionToken);

    promotionSignup.setPromotionToken(promotionToken);

    String[] currencyValueList = { "USD", "EUR" };
    Channel newChannel = channelController.createChannel(
            WebTestUtils.createChannelForm("ChannelForTrialAccount", "ToTestValidPromoCode", "PROMOCODE", null,
                    "en_US", "Asia/Kolkata", currencyValueList, map, new MockHttpServletResponse()),
            null, map, new MockHttpServletResponse());
    Set<CampaignPromotionsInChannels> campPromoChannelSet = new HashSet<CampaignPromotionsInChannels>();
    campPromoChannelSet.add(new CampaignPromotionsInChannels(campaignPromotion, newChannel));
    campaignPromotion.setCampaignPromotionsInChannels(campPromoChannelSet);
    cmpdao.save(campaignPromotion);
    validateResponse = controller.validatePromotionCodeforTenant("TESTPROMOCODE", newChannel.getParam(), "");
    Assert.assertEquals("true", validateResponse);

}

From source file:org.totschnig.myexpenses.util.Utils.java

public static Currency getSaveInstance(String strCurrency) {
    Currency c;/*from   w ww .j a  va 2  s  .c  om*/
    try {
        c = Currency.getInstance(strCurrency);
    } catch (IllegalArgumentException e) {
        Log.e("MyExpenses", strCurrency + " is not defined in ISO 4217");
        c = Currency.getInstance(Locale.getDefault());
    }
    return getSaveInstance(c);
}

From source file:org.gnucash.android.ui.transaction.TransactionFormFragment.java

/**
* Initialize views with default data for new transactions
*///  w w  w  . j a va  2 s .c  o  m
private void initalizeViews() {
    Date time = new Date(System.currentTimeMillis());
    mDateTextView.setText(DATE_FORMATTER.format(time));
    mTimeTextView.setText(TIME_FORMATTER.format(time));
    mTime = mDate = Calendar.getInstance();

    String typePref = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getString(getString(R.string.key_default_transaction_type), "DEBIT");
    if (typePref.equals("CREDIT")) {
        if (mAccountType.hasDebitNormalBalance())
            mTransactionTypeButton.setChecked(false);
        else
            mTransactionTypeButton.setChecked(true);
    } else { //DEBIT
        if (mAccountType.hasDebitNormalBalance())
            mTransactionTypeButton.setChecked(true);
        else
            mTransactionTypeButton.setChecked(false);
    }

    final long accountId = getArguments().getLong(UxArgument.SELECTED_ACCOUNT_ID);
    String code = Money.DEFAULT_CURRENCY_CODE;
    if (accountId != 0) {
        code = mTransactionsDbAdapter.getCurrencyCode(accountId);
    }
    Currency accountCurrency = Currency.getInstance(code);
    mCurrencyTextView.setText(accountCurrency.getSymbol(Locale.getDefault()));

    if (mUseDoubleEntry) {
        long defaultTransferAccountID = mAccountsDbAdapter.getDefaultTransferAccountID(accountId);
        if (defaultTransferAccountID > 0) {
            setSelectedTransferAccount(defaultTransferAccountID);
        }
    }
}

From source file:org.totschnig.myexpenses.model.Account.java

public void setCurrency(String currency) throws IllegalArgumentException {
    this.currency = Currency.getInstance(currency);
    openingBalance.setCurrency(this.currency);
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static Currency getSaveInstance(Currency currency) {
    try {/*  w ww  .ja va  2 s.c  o m*/
        CurrencyEnum.valueOf(currency.getCurrencyCode());
        return currency;
    } catch (IllegalArgumentException e) {
        return Currency.getInstance("EUR");
    }
}

From source file:com.acc.fulfilmentprocess.test.FraudCheckIntegrationTest.java

protected void placeTestOrder() throws InvalidCartException, CalculationException {
    final CartModel cart = cartService.getSessionCart();
    final UserModel user = userService.getCurrentUser();
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct1"), 1, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct2"), 2, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct3"), 3, null);

    final AddressModel deliveryAddress = new AddressModel();
    deliveryAddress.setOwner(user);/*from   w w  w.ja v a 2  s. c o m*/
    deliveryAddress.setFirstname("Der");
    deliveryAddress.setLastname("Buck");
    deliveryAddress.setTown("Muenchen");
    deliveryAddress.setCountry(commonI18NService.getCountry("DE"));
    modelService.save(deliveryAddress);

    final DebitPaymentInfoModel paymentInfo = new DebitPaymentInfoModel();
    paymentInfo.setOwner(cart);
    paymentInfo.setBank("MeineBank");
    paymentInfo.setUser(user);
    paymentInfo.setAccountNumber("34434");
    paymentInfo.setBankIDNumber("1111112");
    paymentInfo.setBaOwner("Ich");
    paymentInfo.setCode("testPaymentInfo1");
    modelService.save(paymentInfo);

    final ZoneDeliveryModeModel zoneDeliveryModeModel = new ZoneDeliveryModeModel();
    zoneDeliveryModeModel.setCode("free");
    zoneDeliveryModeModel.setNet(Boolean.TRUE);
    final ZoneDeliveryModeValueModel zoneDeliveryModeValueModel = new ZoneDeliveryModeValueModel();
    zoneDeliveryModeValueModel.setDeliveryMode(zoneDeliveryModeModel);
    zoneDeliveryModeValueModel.setValue(Double.valueOf(0.00));
    zoneDeliveryModeValueModel.setCurrency(commonI18NService.getCurrency("EUR"));
    zoneDeliveryModeValueModel.setMinimum(Double.valueOf(0.00));
    final ZoneModel zoneModel = new ZoneModel();
    zoneModel.setCode("de");
    zoneModel.setCountries(Collections.singleton(commonI18NService.getCountry("DE")));
    modelService.save(zoneModel);
    zoneDeliveryModeValueModel.setZone(zoneModel);
    modelService.save(zoneDeliveryModeModel);
    zoneDeliveryModeModel.setValues(Collections.singleton(zoneDeliveryModeValueModel));
    modelService.save(zoneDeliveryModeValueModel);
    modelService.save(zoneDeliveryModeModel);

    cart.setDeliveryMode(zoneDeliveryModeModel);
    cart.setDeliveryAddress(deliveryAddress);
    cart.setPaymentInfo(paymentInfo);

    final CardInfo card = new CardInfo();
    card.setCardType(CreditCardType.VISA);
    card.setCardNumber("4111111111111111");
    card.setExpirationMonth(Integer.valueOf(12));
    card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 2));
    card.setCv2Number("123");
    final PaymentTransactionModel paymentTransaction = paymentService.authorize("code3" + codeNo++,
            BigDecimal.ONE, Currency.getInstance("EUR"), deliveryAddress, deliveryAddress, card)
            .getPaymentTransaction();

    cart.setPaymentTransactions(Collections.singletonList(paymentTransaction));
    modelService.save(cart);
    calculationService.calculate(cart);

    order = commerceCheckoutService.placeOrder(cart);
}

From source file:com.mitre.fulfilmentprocess.test.FraudCheckIntegrationTest.java

protected void placeTestOrder() throws InvalidCartException, CalculationException {
    final CartModel cart = cartService.getSessionCart();
    final UserModel user = userService.getCurrentUser();
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct1"), 1, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct2"), 2, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct3"), 3, null);

    final AddressModel deliveryAddress = new AddressModel();
    deliveryAddress.setOwner(user);//from   w w w.  ja va2  s.c  o m
    deliveryAddress.setFirstname("Der");
    deliveryAddress.setLastname("Buck");
    deliveryAddress.setTown("Muenchen");
    deliveryAddress.setCountry(commonI18NService.getCountry("DE"));
    modelService.save(deliveryAddress);

    final DebitPaymentInfoModel paymentInfo = new DebitPaymentInfoModel();
    paymentInfo.setOwner(cart);
    paymentInfo.setBank("MeineBank");
    paymentInfo.setUser(user);
    paymentInfo.setAccountNumber("34434");
    paymentInfo.setBankIDNumber("1111112");
    paymentInfo.setBaOwner("Ich");
    paymentInfo.setCode("testPaymentInfo1");
    modelService.save(paymentInfo);

    final ZoneDeliveryModeModel zoneDeliveryModeModel = new ZoneDeliveryModeModel();
    zoneDeliveryModeModel.setCode("free");
    zoneDeliveryModeModel.setNet(Boolean.TRUE);
    final ZoneDeliveryModeValueModel zoneDeliveryModeValueModel = new ZoneDeliveryModeValueModel();
    zoneDeliveryModeValueModel.setDeliveryMode(zoneDeliveryModeModel);
    zoneDeliveryModeValueModel.setValue(Double.valueOf(0.00));
    zoneDeliveryModeValueModel.setCurrency(commonI18NService.getCurrency("EUR"));
    zoneDeliveryModeValueModel.setMinimum(Double.valueOf(0.00));
    final ZoneModel zoneModel = new ZoneModel();
    zoneModel.setCode("de");
    zoneModel.setCountries(Collections.singleton(commonI18NService.getCountry("DE")));
    modelService.save(zoneModel);
    zoneDeliveryModeValueModel.setZone(zoneModel);
    modelService.save(zoneDeliveryModeModel);
    zoneDeliveryModeModel.setValues(Collections.singleton(zoneDeliveryModeValueModel));
    modelService.save(zoneDeliveryModeValueModel);
    modelService.save(zoneDeliveryModeModel);

    cart.setDeliveryMode(zoneDeliveryModeModel);
    cart.setDeliveryAddress(deliveryAddress);
    cart.setPaymentInfo(paymentInfo);

    final CardInfo card = new CardInfo();
    card.setCardType(CreditCardType.VISA);
    card.setCardNumber("4111111111111111");
    card.setExpirationMonth(Integer.valueOf(12));
    card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 2));
    card.setCv2Number("123");
    final PaymentTransactionModel paymentTransaction = paymentService.authorize("code3" + codeNo++,
            BigDecimal.ONE, Currency.getInstance("EUR"), deliveryAddress, deliveryAddress, card)
            .getPaymentTransaction();

    cart.setPaymentTransactions(Collections.singletonList(paymentTransaction));
    modelService.save(cart);
    calculationService.calculate(cart);

    final CommerceCheckoutParameter parameter = new CommerceCheckoutParameter();
    parameter.setEnableHooks(true);
    parameter.setCart(cart);
    parameter.setSalesApplication(SalesApplication.WEB);

    order = commerceCheckoutService.placeOrder(parameter).getOrder();
}