Source Code Cross Referenced for WriterTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » io » 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 » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  You may obtain a copy of the License at
007:         * 
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.harmony.luni.tests.java.io;
017:
018:        import java.io.IOException;
019:        import java.io.Writer;
020:
021:        import junit.framework.TestCase;
022:
023:        public class WriterTest extends TestCase {
024:
025:            /**
026:             * @tests java.io.Writer#append(char)
027:             */
028:            public void test_appendChar() throws IOException {
029:                char testChar = ' ';
030:                MockWriter writer = new MockWriter(20);
031:                writer.append(testChar);
032:                assertEquals(String.valueOf(testChar), String.valueOf(writer
033:                        .getContents()));
034:                writer.close();
035:            }
036:
037:            /**
038:             * @tests java.io.Writer#append(CharSequence)
039:             */
040:            public void test_appendCharSequence() throws IOException {
041:                String testString = "My Test String";
042:                MockWriter writer = new MockWriter(20);
043:                writer.append(testString);
044:                assertEquals(testString, String.valueOf(writer.getContents()));
045:                writer.close();
046:
047:            }
048:
049:            /**
050:             * @tests java.io.Writer#append(CharSequence, int, int)
051:             */
052:            public void test_appendCharSequenceIntInt() throws IOException {
053:                String testString = "My Test String";
054:                MockWriter writer = new MockWriter(20);
055:                writer.append(testString, 1, 3);
056:                assertEquals(testString.substring(1, 3), String.valueOf(writer
057:                        .getContents()));
058:                writer.close();
059:
060:            }
061:
062:            /**
063:             * @tests java.io.Writer#write(String)
064:             */
065:            public void test_writeLjava_lang_String() throws IOException {
066:                // Regression for HARMONY-51
067:                Object lock = new Object();
068:                Writer wr = new MockLockWriter(lock);
069:                // FIXME This test should be added to the exclusion list until
070:                // Thread.holdsLock works on IBM VME
071:                //      wr.write("Some string");
072:                wr.close();
073:            }
074:
075:            class MockLockWriter extends Writer {
076:                final Object myLock;
077:
078:                MockLockWriter(Object lock) {
079:                    super (lock);
080:                    myLock = lock;
081:                }
082:
083:                @Override
084:                public synchronized void close() throws IOException {
085:                    // do nothing
086:                }
087:
088:                @Override
089:                public synchronized void flush() throws IOException {
090:                    // do nothing
091:                }
092:
093:                @Override
094:                public void write(char[] arg0, int arg1, int arg2)
095:                        throws IOException {
096:                    assertTrue(Thread.holdsLock(myLock));
097:                }
098:            }
099:
100:            class MockWriter extends Writer {
101:                private char[] contents;
102:
103:                private int length;
104:
105:                private int offset;
106:
107:                MockWriter(int capacity) {
108:                    contents = new char[capacity];
109:                    length = capacity;
110:                    offset = 0;
111:                }
112:
113:                public synchronized void close() throws IOException {
114:                    flush();
115:                    contents = null;
116:                }
117:
118:                public synchronized void flush() throws IOException {
119:                    // do nothing
120:                }
121:
122:                public void write(char[] buffer, int offset, int count)
123:                        throws IOException {
124:                    if (null == contents) {
125:                        throw new IOException();
126:                    }
127:                    if (offset < 0 || count < 0 || offset >= buffer.length) {
128:                        throw new IndexOutOfBoundsException();
129:                    }
130:                    count = Math.min(count, buffer.length - offset);
131:                    count = Math.min(count, this .length - this .offset);
132:                    for (int i = 0; i < count; i++) {
133:                        contents[this .offset + i] = buffer[offset + i];
134:                    }
135:                    this .offset += count;
136:
137:                }
138:
139:                public char[] getContents() {
140:                    char[] result = new char[offset];
141:                    for (int i = 0; i < offset; i++) {
142:                        result[i] = contents[i];
143:                    }
144:                    return result;
145:                }
146:            }
147:
148:        }
w___w___w__.___j_a_va__2___s._co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.