1/*
2 * Copyright (C) 2008 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
17package com.android.tools.layoutlib.create;
18
19import static org.junit.Assert.*;
20
21import org.junit.After;
22import org.junit.Before;
23import org.junit.Test;
24
25public class LogTest {
26
27    private MockLog mLog;
28
29    @Before
30    public void setUp() throws Exception {
31        mLog = new MockLog();
32    }
33
34    @After
35    public void tearDown() throws Exception {
36        // pass
37    }
38
39    @Test
40    public void testDebug() {
41        assertEquals("", mLog.getOut());
42        assertEquals("", mLog.getErr());
43
44        mLog.setVerbose(false);
45        mLog.debug("Test %d", 42);
46        assertEquals("", mLog.getOut());
47
48        mLog.setVerbose(true);
49        mLog.debug("Test %d", 42);
50
51        assertEquals("Test 42\n", mLog.getOut());
52        assertEquals("", mLog.getErr());
53    }
54
55    @Test
56    public void testInfo() {
57        assertEquals("", mLog.getOut());
58        assertEquals("", mLog.getErr());
59
60        mLog.info("Test %d", 43);
61
62        assertEquals("Test 43\n", mLog.getOut());
63        assertEquals("", mLog.getErr());
64    }
65
66    @Test
67    public void testError() {
68        assertEquals("", mLog.getOut());
69        assertEquals("", mLog.getErr());
70
71        mLog.error("Test %d", 44);
72
73        assertEquals("", mLog.getOut());
74        assertEquals("Test 44\n", mLog.getErr());
75    }
76
77    @Test
78    public void testException() {
79        assertEquals("", mLog.getOut());
80        assertEquals("", mLog.getErr());
81
82        Exception e = new Exception("My Exception");
83        mLog.exception(e, "Test %d", 44);
84
85        assertEquals("", mLog.getOut());
86        assertTrue(mLog.getErr().startsWith("Test 44\njava.lang.Exception: My Exception"));
87    }
88}
89