Source Code Cross Referenced for MessageFormatterTest.java in  » Development » SLF4J » org » slf4j » helpers » 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 » Development » SLF4J » org.slf4j.helpers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (c) 2004-2005 SLF4J.ORG
003:         * Copyright (c) 2004-2005 QOS.CH
004:         * 
005:         * All rights reserved.
006:         * 
007:         * Permission is hereby granted, free of charge, to any person obtaining
008:         * a copy of this software and associated documentation files (the
009:         * "Software"), to  deal in  the Software without  restriction, including
010:         * without limitation  the rights to  use, copy, modify,  merge, publish,
011:         * distribute, and/or sell copies of  the Software, and to permit persons
012:         * to whom  the Software is furnished  to do so, provided  that the above
013:         * copyright notice(s) and this permission notice appear in all copies of
014:         * the  Software and  that both  the above  copyright notice(s)  and this
015:         * permission notice appear in supporting documentation.
016:         * 
017:         * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
018:         * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
019:         * MERCHANTABILITY, FITNESS FOR  A PARTICULAR PURPOSE AND NONINFRINGEMENT
020:         * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
021:         * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
022:         * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
023:         * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
024:         * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
025:         * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
026:         * 
027:         * Except as  contained in  this notice, the  name of a  copyright holder
028:         * shall not be used in advertising or otherwise to promote the sale, use
029:         * or other dealings in this Software without prior written authorization
030:         * of the copyright holder.
031:         *
032:         */
033:
034:        package org.slf4j.helpers;
035:
036:        import org.slf4j.helpers.MessageFormatter;
037:
038:        import junit.framework.TestCase;
039:
040:        /**
041:         * @author Ceki Gulcu
042:         *
043:         */
044:        public class MessageFormatterTest extends TestCase {
045:
046:            Integer i1 = new Integer(1);
047:            Integer i2 = new Integer(2);
048:            Integer i3 = new Integer(3);
049:
050:            public void testNull() {
051:                String result;
052:                result = MessageFormatter.format(null, i1);
053:                assertEquals(null, result);
054:            }
055:
056:            public void testNullParam() {
057:                String result;
058:
059:                result = MessageFormatter.format("Value is {}.", null);
060:                assertEquals("Value is null.", result);
061:
062:                result = MessageFormatter.format("Val1 is {}, val2 is {}.",
063:                        null, null);
064:                assertEquals("Val1 is null, val2 is null.", result);
065:
066:                result = MessageFormatter.format("Val1 is {}, val2 is {}.", i1,
067:                        null);
068:                assertEquals("Val1 is 1, val2 is null.", result);
069:
070:                result = MessageFormatter.format("Val1 is {}, val2 is {}.",
071:                        null, i2);
072:                assertEquals("Val1 is null, val2 is 2.", result);
073:
074:                result = MessageFormatter.arrayFormat(
075:                        "Val1 is {}, val2 is {}, val3 is {}", new Integer[] {
076:                                null, null, null });
077:                assertEquals("Val1 is null, val2 is null, val3 is null", result);
078:
079:                result = MessageFormatter.arrayFormat(
080:                        "Val1 is {}, val2 is {}, val3 is {}", new Integer[] {
081:                                null, i2, i3 });
082:                assertEquals("Val1 is null, val2 is 2, val3 is 3", result);
083:
084:                result = MessageFormatter.arrayFormat(
085:                        "Val1 is {}, val2 is {}, val3 is {}", new Integer[] {
086:                                null, null, i3 });
087:                assertEquals("Val1 is null, val2 is null, val3 is 3", result);
088:            }
089:
090:            public void testOneParameter() {
091:                String result;
092:
093:                result = MessageFormatter.format("Value is {}.", i3);
094:                assertEquals("Value is 3.", result);
095:
096:                result = MessageFormatter.format("Value is {", i3);
097:                assertEquals("Value is {", result);
098:
099:                result = MessageFormatter.format("{} is larger than 2.", i3);
100:                assertEquals("3 is larger than 2.", result);
101:
102:                result = MessageFormatter.format("No subst", i3);
103:                assertEquals("No subst", result);
104:
105:                result = MessageFormatter.format("Incorrect {subst", i3);
106:                assertEquals("Incorrect {subst", result);
107:
108:                result = MessageFormatter.format("Value is \\{bla} {}", i3);
109:                assertEquals("Value is {bla} 3", result);
110:
111:                result = MessageFormatter.format("Escaped \\{} subst", i3);
112:                assertEquals("Escaped {} subst", result);
113:
114:                result = MessageFormatter.format("\\{Escaped", i3);
115:                assertEquals("{Escaped", result);
116:
117:                result = MessageFormatter.format("\\{}Escaped", i3);
118:                assertEquals("{}Escaped", result);
119:
120:                result = MessageFormatter.format("File name is \\{{}}.",
121:                        "App folder.zip");
122:                assertEquals("File name is {App folder.zip}.", result);
123:
124:                // escaping the escape character
125:                result = MessageFormatter.format("File name is C:\\\\{}.",
126:                        "App folder.zip");
127:                assertEquals("File name is C:\\App folder.zip.", result);
128:            }
129:
130:            public void testTwoParameters() {
131:                String result;
132:
133:                result = MessageFormatter.format(
134:                        "Value {} is smaller than {}.", i1, i2);
135:                assertEquals("Value 1 is smaller than 2.", result);
136:
137:                result = MessageFormatter.format("Value {} is smaller than {}",
138:                        i1, i2);
139:                assertEquals("Value 1 is smaller than 2", result);
140:
141:                result = MessageFormatter.format("{}{}", i1, i2);
142:                assertEquals("12", result);
143:
144:                result = MessageFormatter.format("Val1={}, Val2={", i1, i2);
145:                assertEquals("Val1=1, Val2={", result);
146:
147:                result = MessageFormatter.format(
148:                        "Value {} is smaller than \\{}", i1, i2);
149:                assertEquals("Value 1 is smaller than {}", result);
150:
151:                result = MessageFormatter.format(
152:                        "Value {} is smaller than \\{} tail", i1, i2);
153:                assertEquals("Value 1 is smaller than {} tail", result);
154:
155:                result = MessageFormatter.format(
156:                        "Value {} is smaller than \\{", i1, i2);
157:                assertEquals("Value 1 is smaller than \\{", result);
158:
159:                result = MessageFormatter.format(
160:                        "Value {} is smaller than \\{tail", i1, i2);
161:                assertEquals("Value 1 is smaller than {tail", result);
162:
163:                result = MessageFormatter.format(
164:                        "Value \\{} is smaller than {}", i1, i2);
165:                assertEquals("Value {} is smaller than 1", result);
166:            }
167:
168:            public void testArray() {
169:                String result;
170:
171:                Integer[] ia = new Integer[] { i1, i2, i3 };
172:
173:                result = MessageFormatter.arrayFormat(
174:                        "Value {} is smaller than {} and {}.", ia);
175:                assertEquals("Value 1 is smaller than 2 and 3.", result);
176:
177:                result = MessageFormatter.arrayFormat("{}{}{}", ia);
178:                assertEquals("123", result);
179:
180:                result = MessageFormatter.arrayFormat(
181:                        "Value {} is smaller than {}.", ia);
182:                assertEquals("Value 1 is smaller than 2.", result);
183:
184:                result = MessageFormatter.arrayFormat(
185:                        "Value {} is smaller than {}", ia);
186:                assertEquals("Value 1 is smaller than 2", result);
187:
188:                result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia);
189:                assertEquals("Val=1, {, Val={}", result);
190:
191:                result = MessageFormatter
192:                        .arrayFormat("Val={}, \\{, Val={}", ia);
193:                assertEquals("Val=1, {, Val=2", result);
194:
195:                result = MessageFormatter.arrayFormat("Val1={}, Val2={", ia);
196:                assertEquals("Val1=1, Val2={", result);
197:
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.