1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ahat;
18 
19 import java.io.IOException;
20 import java.io.OutputStream;
21 import java.io.PrintStream;
22 
23 /**
24  * Provide common utilities for basic handler tests.
25  */
26 public class TestHandler {
27   private static class NullOutputStream extends OutputStream {
write(int b)28     public void write(int b) throws IOException {
29     }
30   }
31 
32   /**
33    * Test that the given handler doesn't crash on the given query.
34    */
testNoCrash(AhatHandler handler, String uri)35   public static void testNoCrash(AhatHandler handler, String uri) throws IOException {
36     PrintStream ps = new PrintStream(new NullOutputStream());
37     HtmlDoc doc = new HtmlDoc(ps, DocString.text("noCrash test"), DocString.uri("style.css"));
38     Query query = new Query(DocString.uri(uri));
39     handler.handle(doc, query);
40   }
41 }
42