-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutLocale.java
More file actions
52 lines (43 loc) · 1.99 KB
/
AboutLocale.java
File metadata and controls
52 lines (43 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package intermediate;
import com.sandwich.koan.Koan;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import static com.sandwich.koan.constant.KoanConstants.__;
import static com.sandwich.util.Assert.assertEquals;
public class AboutLocale {
@Koan
public void localizedOutputOfDates() {
Calendar cal = Calendar.getInstance();
cal.set(2011, 3, 3);
Date date = cal.getTime();
Locale localeBR = new Locale("pt", "BR"); // portuguese, Brazil
DateFormat dateformatBR = DateFormat.getDateInstance(DateFormat.FULL, localeBR);
assertEquals(dateformatBR.format(date),"domingo, 3 de abril de 2011");
Locale localeJA = new Locale("ja"); // Japan
DateFormat dateformatJA = DateFormat.getDateInstance(DateFormat.FULL, localeJA);
// Well if you don't know how to type these characters, try "de", "it" or "us" ;-)
DateFormat dateformatJ = DateFormat.getDateInstance(DateFormat.FULL, localeJA);
assertEquals(dateformatJA.format(date), dateformatJ.format(date));
}
@Koan
public void getCountryInformation() {
Locale locBR = new Locale("pt", "BR");
assertEquals(locBR.getDisplayCountry(), "Brazil");
assertEquals(locBR.getDisplayCountry(locBR), "Brasil");
Locale locCH = new Locale("it", "CH");
assertEquals(locCH.getDisplayCountry(), "Switzerland");
assertEquals(locCH.getDisplayCountry(locCH), "Svizzera");
assertEquals(locCH.getDisplayCountry(new Locale("de", "CH")), "Schweiz");
}
@Koan
public void formatCurrency() {
float someAmount = 442.23f; // Don't use floats for money in real life. Really. It's a bad idea.
Locale locBR = new Locale("pt", "BR");
NumberFormat nf = NumberFormat.getCurrencyInstance(locBR);
NumberFormat nfq = NumberFormat.getCurrencyInstance(locBR);
assertEquals(nf.format(someAmount),nfq.format(someAmount));
}
}