Gutyn
9 years ago
31 changed files with 765 additions and 388 deletions
@ -1,28 +1,129 @@ |
|||
package com.breadwallet.presenter.currencyformatting.tests; |
|||
|
|||
import android.test.AndroidTestCase; |
|||
|
|||
import java.util.Locale; |
|||
|
|||
|
|||
/** |
|||
* BreadWallet |
|||
* <p/> |
|||
* Created by Mihail on 8/18/15. |
|||
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com> |
|||
* <p/> |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to deal |
|||
* in the Software without restriction, including without limitation the rights |
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
* copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* <p/> |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* <p/> |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
* THE SOFTWARE. |
|||
* ISO 4217 currency codes can be found here: |
|||
* http://en.wikipedia.org/wiki/ISO_4217
|
|||
*/ |
|||
public class CurrencyFormatterFixedTests { |
|||
} |
|||
|
|||
|
|||
public class CurrencyFormatterFixedTests extends AndroidTestCase { |
|||
/** |
|||
* These tests differ between Android <= 4.0, and >= 4.1. |
|||
*/ |
|||
|
|||
public void testJPY() { |
|||
String expected = "¥15"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("ja", "JP"), "JPY", 15.00); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails. (¥15.00)
|
|||
// 4.1 and above - Fails (¥15)
|
|||
// Yes, that is a different yen symbol to what we get with ja_JP locale (note
|
|||
// we're forcing en_US in the CurrencyFormatter).
|
|||
} |
|||
|
|||
public void testNZDollarsInJapanLocale() { |
|||
// New Zealand currency, but the device locale is ja_JP
|
|||
String expected = "NZ$16"; // Yen has no decimal units
|
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("ja", "JP"), "NZD", 15.50); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails (NZ$15.50).
|
|||
} |
|||
|
|||
public void testCLP() { |
|||
String expected = "$15"; // Chilean Peso has no decimal units.
|
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("es", "CL"), "CLP", 15.00); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails. (CL$ 15,00)
|
|||
// 4.1 and above - Fails (CLP15).
|
|||
} |
|||
|
|||
public void testNZDollarsInChileLocale() { |
|||
// New Zealand currency, but the device locale is es_CL
|
|||
String expected = "NZ$16"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("es", "CL"), "NZD", 15.50); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails. (NZ$15,50)
|
|||
} |
|||
|
|||
public void testNZDollarsInAustralianLocale() { |
|||
String expected = "NZ$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "AU"), "NZD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testAustralianDollarsInNewZealandLocale() { |
|||
String expected = "AU$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "NZ"), "AUD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testGBP() { |
|||
String expected = "£15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "GB"), "GBP", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testNZD() { |
|||
String expected = "$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "NZ"), "NZD", 15.00); |
|||
assertEquals(expected, actual); |
|||
// Fails - NZ$15.00
|
|||
} |
|||
|
|||
public void testUSD() { |
|||
String expected = "$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "US"), "USD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testNZDInUSLocale() { |
|||
String expected = "NZ$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "US"), "NZD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testEURInFranceLocale() { |
|||
String expected = "15,00 €"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("fr", "FR"), "EUR", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testEURInRepublicOfIrelandLocale() { |
|||
String expected = "€15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "IE"), "EUR", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testUSDollarsInCanadianLocale() { |
|||
String expected = "US$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "CA"), "USD", 15.00); |
|||
assertEquals(expected, actual); |
|||
// Fails - $15.00
|
|||
} |
|||
|
|||
public void testCanadianDollarsInUSLocale() { |
|||
String expected = "CA$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "US"), "CAD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testEurosInUnitedKingdomLocale() { |
|||
String expected = "€15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("en", "GB"), "EUR", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testPoundsInFranceLocale() { |
|||
String expected = "15,00 £UK"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringFixed(new Locale("fr", "FR"), "GBP", 15.00); |
|||
assertEquals(expected, actual); |
|||
// Fails - 15,00 £
|
|||
} |
|||
|
|||
|
|||
} |
@ -1,28 +1,129 @@ |
|||
package com.breadwallet.presenter.currencyformatting.tests; |
|||
|
|||
/** |
|||
* BreadWallet |
|||
* <p/> |
|||
* Created by Mihail on 8/18/15. |
|||
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com> |
|||
* <p/> |
|||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
* of this software and associated documentation files (the "Software"), to deal |
|||
* in the Software without restriction, including without limitation the rights |
|||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
* copies of the Software, and to permit persons to whom the Software is |
|||
* furnished to do so, subject to the following conditions: |
|||
* <p/> |
|||
* The above copyright notice and this permission notice shall be included in |
|||
* all copies or substantial portions of the Software. |
|||
* <p/> |
|||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
* THE SOFTWARE. |
|||
*/ |
|||
public class CurrencyFormatterTests { |
|||
} |
|||
import android.test.AndroidTestCase; |
|||
|
|||
import java.util.Locale; |
|||
public class CurrencyFormatterTests extends AndroidTestCase { |
|||
/** |
|||
* These tests differ between Android <= 4.0, and >= 4.1. |
|||
*/ |
|||
|
|||
public void testJPY() { |
|||
String expected = "¥15"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("ja", "JP"), "JPY", 15.00); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails. (¥15.00)
|
|||
// 4.1 and above - Passes.
|
|||
} |
|||
|
|||
public void testNZDollarsInJapanLocale() { |
|||
// New Zealand currency, but the device locale is ja_JP
|
|||
String expected = "NZ$16"; // Yen has no decimal units
|
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("ja", "JP"), "NZD", 15.50); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails. NZ$15.50.
|
|||
// 4.1 and above - Passes.
|
|||
} |
|||
|
|||
public void testCLP() { |
|||
String expected = "$15"; // Chilean Peso has no decimal units.
|
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("es", "CL"), "CLP", 15.00); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails. (CL$ 15,00)
|
|||
// 4.1 and above - Passes.
|
|||
} |
|||
|
|||
public void testNZDollarsInChileLocale() { |
|||
// New Zealand currency, but the device locale is es_CL
|
|||
String expected = "NZ$16"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("es", "CL"), "NZD", 15.50); |
|||
assertEquals(expected, actual); |
|||
// 4.0 and below - Fails. NZD 15,50
|
|||
// 4.1 and above - Fails. NZD16
|
|||
} |
|||
|
|||
/** |
|||
* These tests fail, presumably because the formatting tables for the provided locales don't |
|||
* have a custom currency unit for the supplied ISO currency code. |
|||
*/ |
|||
|
|||
public void testNZDollarsInAustralianLocale() { |
|||
String expected = "NZ$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "AU"), "NZD", 15.00); |
|||
assertEquals(expected, actual); |
|||
// Fails. NZD15.00
|
|||
} |
|||
|
|||
public void testAustralianDollarsInNewZealandLocale() { |
|||
String expected = "AU$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "NZ"), "AUD", 15.00); |
|||
assertEquals(expected, actual); |
|||
// Fails. AUD15.00
|
|||
} |
|||
|
|||
/** |
|||
* These tests pass in all cases I've tested. (device version and locale variations) |
|||
*/ |
|||
|
|||
public void testGBP() { |
|||
String expected = "£15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "GB"), "GBP", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testNZD() { |
|||
String expected = "$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "NZ"), "NZD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testUSD() { |
|||
String expected = "$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "US"), "USD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testNZDInUSLocale() { |
|||
String expected = "NZ$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "US"), "NZD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testEURInFranceLocale() { |
|||
String expected = "15,00 €"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("fr", "FR"), "EUR", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testEURInRepublicOfIrelandLocale() { |
|||
String expected = "€15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "IE"), "EUR", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testUSDollarsInCanadianLocale() { |
|||
String expected = "US$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "CA"), "USD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testCanadianDollarsInUSLocale() { |
|||
String expected = "CA$15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "US"), "CAD", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testEurosInUnitedKingdomLocale() { |
|||
String expected = "€15.00"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("en", "GB"), "EUR", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
public void testPoundsInFranceLocale() { |
|||
String expected = "15,00 £UK"; |
|||
String actual = CurrencyFormatter.getFormattedCurrencyStringForLocale(new Locale("fr", "FR"), "GBP", 15.00); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
|
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue