001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.print;
019:
020: import junit.framework.TestCase;
021:
022: public class DocFlavorTest extends TestCase {
023: public void testStatic() {
024: String encoding = System.getProperty("file.encoding");
025: assertEquals(encoding, DocFlavor.hostEncoding);
026: }
027:
028: public void testHashCode() {
029: DocFlavor f1 = new DocFlavor("text/plain; charset=us-ascii",
030: "[B");
031: DocFlavor f2 = new DocFlavor(
032: "text/plain; charset=us-ascii (comments)", "[B");
033: assertEquals(f1.hashCode(), f1.hashCode());
034: assertEquals(f1.hashCode(), f2.hashCode());
035: }
036:
037: public void testMyDocFlavor() {
038: tryNullPointer(null, "[B");
039: tryNullPointer("text/plain", null);
040: }
041:
042: public void testEqualsObject() {
043: DocFlavor f1 = new DocFlavor("text/plain; charset=us-ascii",
044: "[B");
045: DocFlavor f2 = new DocFlavor(
046: "text/plain; charset=us-ascii (comments)", "[B");
047: DocFlavor f3 = new DocFlavor("image/gif", "[B");
048: DocFlavor f4 = new DocFlavor("text/plain", "[B");
049: DocFlavor f5 = new DocFlavor("text/plain; charset=us-ascii",
050: "[C");
051: assertEquals(f1, f1);
052: assertEquals(f1, f2);
053: assertFalse(f1.equals(f3));
054: assertFalse(f1.equals(f4));
055: assertFalse(f1.equals(f5));
056: }
057:
058: public void testGetMediaSubtype() {
059: DocFlavor f = new DocFlavor("text/plain; charset=us-ascii",
060: "[B");
061: assertEquals("plain", f.getMediaSubtype());
062: }
063:
064: public void testGetMediaType() {
065: DocFlavor f = new DocFlavor("text/plain; charset=us-ascii",
066: "[B");
067: assertEquals("text", f.getMediaType());
068: }
069:
070: public void testGetMimeType() {
071: DocFlavor f = new DocFlavor(
072: "TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
073: assertEquals("text/plain; aaa=\"par2\"; bbb=\"par1\"", f
074: .getMimeType());
075: }
076:
077: public void testGetParameter() {
078: DocFlavor f = new DocFlavor(
079: "TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
080: assertEquals("par1", f.getParameter("bbb"));
081: assertNull(f.getParameter("absent"));
082: }
083:
084: public void testGetRepresentationClassName() {
085: DocFlavor f = new DocFlavor(
086: "TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
087: assertEquals("[B", f.getRepresentationClassName());
088: }
089:
090: public void testToString() {
091: DocFlavor f = new DocFlavor(
092: "TEXT/plain; BBB=par1; aaa=par2 (comments)", "[B");
093: assertEquals(
094: "text/plain; aaa=\"par2\"; bbb=\"par1\"; class=\"[B\"",
095: f.toString());
096: }
097:
098: void tryNullPointer(String s1, String s2) {
099: try {
100: new DocFlavor(s1, s2);
101: fail();
102: } catch (NullPointerException e) {
103: /* NullPointerException is expected here, so the test passes */
104: }
105: }
106: }
|