EMMA Coverage Report (generated Mon Nov 01 16:48:29 PDT 2010)
[all classes][com.google.caja.lexer]

COVERAGE SUMMARY FOR SOURCE FILE [FetchedDataTest.java]

nameclass, %method, %block, %line, %
FetchedDataTest.java100% (2/2)100% (9/9)100% (118/118)100% (33/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FetchedDataTest100% (1/1)100% (5/5)100% (88/88)100% (23/23)
FetchedDataTest (): void 100% (1/1)100% (3/3)100% (2/2)
assertCharSet (String, String): void 100% (1/1)100% (27/27)100% (6/6)
setUp (): void 100% (1/1)100% (8/8)100% (3/3)
testCharSetParsing (): void 100% (1/1)100% (29/29)100% (8/8)
testSimpleContent (): void 100% (1/1)100% (21/21)100% (4/4)
     
class FetchedDataTest$TestURLConnection100% (1/1)100% (4/4)100% (30/30)100% (10/10)
FetchedDataTest$TestURLConnection (URL, String, String): void 100% (1/1)100% (10/10)100% (4/4)
connect (): void 100% (1/1)100% (7/7)100% (3/3)
getContentType (): String 100% (1/1)100% (3/3)100% (1/1)
getInputStream (): InputStream 100% (1/1)100% (10/10)100% (2/2)

1// Copyright (C) 2009 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package com.google.caja.lexer;
16 
17import com.google.caja.util.CajaTestCase;
18 
19import java.io.ByteArrayInputStream;
20import java.io.InputStream;
21import java.net.URI;
22import java.net.URL;
23import java.net.URLConnection;
24 
25/**
26 * @author ihab.awad@gmail.com (Ihab Awad)
27 */
28public class FetchedDataTest extends CajaTestCase {
29  private static class TestURLConnection extends URLConnection {
30    private String data;
31    private String contentType;
32    private boolean connected;
33 
34    public TestURLConnection(URL url, String data, String contentType) {
35      super(url);
36      this.data = data;
37      this.contentType = contentType;
38    }
39 
40    @Override
41    public void connect() {
42      assertFalse(connected);
43      connected = true;
44    }
45 
46    @Override
47    public String getContentType() {
48      return contentType;
49    }
50 
51    @Override
52    public InputStream getInputStream() {
53      assertTrue(connected);
54      return new ByteArrayInputStream(data.getBytes());
55    }
56  }
57 
58  private URL testUrl;
59 
60  @Override
61  public void setUp() throws Exception {
62    super.setUp();
63    testUrl = URI.create("http://www.example.com/").toURL();
64  }
65 
66  public final void testSimpleContent() throws Exception {
67    FetchedData fd = FetchedData.fromConnection(
68        new TestURLConnection(testUrl, "abcdef", "text/html"));
69    assertEquals("text/html", fd.getContentType());
70    assertEquals("abcdef", new String(fd.getByteContent()));
71  }
72 
73  private void assertCharSet(
74      String expectedCharSet, String urlConnectionContentType)
75      throws Exception {
76    String testContent = "abcdef";
77    FetchedData fd = FetchedData.fromConnection(
78        new TestURLConnection(testUrl, testContent, urlConnectionContentType));
79    assertEquals(testContent, new String(fd.getByteContent()));
80    assertEquals(urlConnectionContentType, fd.getContentType());
81    assertEquals(expectedCharSet, fd.getCharSet());
82  }
83 
84  public final void testCharSetParsing() throws Exception {
85    assertCharSet(
86        "iso-8859-1",
87        "text/html;charset=iso-8859-1");
88    assertCharSet(
89        "iso-8859-1",
90        "  text/html;  boo=baz;  charset=iso-8859-1  ");
91    assertCharSet(
92        "iso-8859-1",
93        "text/html;boo=\"baz\";charset=\"iso\\-8859\\-1\";bar=\"b\\\"ip\"");
94    assertCharSet(
95        "",
96        "text/html;boo=baz; charset = ;bar=bip");
97    assertCharSet(
98        "",
99        "text/html;boo=baz;charset;bar=bip");
100    assertCharSet(
101        "",
102        "");
103    assertCharSet(
104        "",
105        null);
106  }
107}

[all classes][com.google.caja.lexer]
EMMA 2.0.5312 (C) Vladimir Roubtsov