Source Code Cross Referenced for NumberFormatRegistrationTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » format » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.icu.dev.test.format 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2003-2005, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.dev.test.format;
008:
009:        import com.ibm.icu.text.*;
010:        import com.ibm.icu.text.NumberFormat.*;
011:        import com.ibm.icu.util.ULocale;
012:
013:        import java.util.Arrays;
014:
015:        public class NumberFormatRegistrationTest extends
016:                com.ibm.icu.dev.test.TestFmwk {
017:
018:            public static void main(String[] args) {
019:                new NumberFormatRegistrationTest().run(args);
020:            }
021:
022:            public void TestRegistration() {
023:                final ULocale SRC_LOC = ULocale.FRANCE;
024:                final ULocale SWAP_LOC = ULocale.US;
025:
026:                class TestFactory extends SimpleNumberFormatFactory {
027:                    NumberFormat currencyStyle;
028:
029:                    TestFactory() {
030:                        this (SRC_LOC, SWAP_LOC);
031:                    }
032:
033:                    TestFactory(ULocale srcLoc, ULocale swapLoc) {
034:                        super (srcLoc);
035:                        currencyStyle = NumberFormat
036:                                .getIntegerInstance(swapLoc);
037:                    }
038:
039:                    public NumberFormat createFormat(ULocale loc, int formatType) {
040:                        if (formatType == FORMAT_CURRENCY) {
041:                            return currencyStyle;
042:                        }
043:                        return null;
044:                    }
045:                }
046:
047:                {
048:                    // coverage before registration
049:
050:                    try {
051:                        NumberFormat.unregister(null);
052:                        errln("did not throw exception on null unregister");
053:                    } catch (Exception e) {
054:                        logln("PASS: null unregister failed as expected");
055:                    }
056:
057:                    try {
058:                        NumberFormat.registerFactory(null);
059:                        errln("did not throw exception on null register");
060:                    } catch (Exception e) {
061:                        logln("PASS: null register failed as expected");
062:                    }
063:
064:                    try {
065:                        // if no NF has been registered yet, shim is null, so this silently
066:                        // returns false.  if, on the other hand, a NF has been registered,
067:                        // this will try to cast the argument to a Factory, and throw
068:                        // an exception.
069:                        if (NumberFormat.unregister("")) {
070:                            errln("unregister of empty string key succeeded");
071:                        }
072:                    } catch (Exception e) {
073:                    }
074:                }
075:
076:                ULocale fu_FU = new ULocale("fu_FU");
077:                NumberFormat f0 = NumberFormat.getIntegerInstance(SWAP_LOC);
078:                NumberFormat f1 = NumberFormat.getIntegerInstance(SRC_LOC);
079:                NumberFormat f2 = NumberFormat.getCurrencyInstance(SRC_LOC);
080:                Object key = NumberFormat.registerFactory(new TestFactory());
081:                Object key2 = NumberFormat.registerFactory(new TestFactory(
082:                        fu_FU, ULocale.GERMANY));
083:                if (!Arrays.asList(NumberFormat.getAvailableULocales())
084:                        .contains(fu_FU)) {
085:                    errln("did not list fu_FU");
086:                }
087:                NumberFormat f3 = NumberFormat.getCurrencyInstance(SRC_LOC);
088:                NumberFormat f4 = NumberFormat.getIntegerInstance(SRC_LOC);
089:                NumberFormat.unregister(key); // restore for other tests
090:                NumberFormat f5 = NumberFormat.getCurrencyInstance(SRC_LOC);
091:
092:                NumberFormat.unregister(key2);
093:
094:                float n = 1234.567f;
095:                logln("f0 swap int: " + f0.format(n));
096:                logln("f1 src int: " + f1.format(n));
097:                logln("f2 src cur: " + f2.format(n));
098:                logln("f3 reg cur: " + f3.format(n));
099:                logln("f4 reg int: " + f4.format(n));
100:                logln("f5 unreg cur: " + f5.format(n));
101:
102:                if (!f3.format(n).equals(f0.format(n))) {
103:                    errln("registered service did not match");
104:                }
105:                if (!f4.format(n).equals(f1.format(n))) {
106:                    errln("registered service did not inherit");
107:                }
108:                if (!f5.format(n).equals(f2.format(n))) {
109:                    errln("unregistered service did not match original");
110:                }
111:
112:                // coverage
113:                NumberFormat f6 = NumberFormat.getNumberInstance(fu_FU);
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.