1/*
2 * Copyright (C) 2013 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.mediaframeworktest.unit;
18
19import android.hardware.camera2.CameraAccessException;
20import android.hardware.camera2.utils.CameraRuntimeException;
21import android.hardware.camera2.utils.UncheckedThrow;
22import android.test.suitebuilder.annotation.SmallTest;
23
24import junit.framework.Assert;
25
26public class CameraUtilsRuntimeExceptionTest extends junit.framework.TestCase {
27
28    @SmallTest
29    public void testCameraRuntimeException1() {
30        try {
31            CameraRuntimeException runtimeExc = new CameraRuntimeException(12345);
32            throw runtimeExc.asChecked();
33        } catch (CameraAccessException e) {
34            assertEquals(12345, e.getReason());
35            assertNull(e.getMessage());
36            assertNull(e.getCause());
37        }
38    }
39
40    @SmallTest
41    public void testCameraRuntimeException2() {
42        try {
43            CameraRuntimeException runtimeExc = new CameraRuntimeException(12345, "Hello");
44            throw runtimeExc.asChecked();
45        } catch (CameraAccessException e) {
46            assertEquals(12345, e.getReason());
47            assertEquals("Hello", e.getMessage());
48            assertNull(e.getCause());
49        }
50    }
51
52    @SmallTest
53    public void testCameraRuntimeException3() {
54        Throwable cause = new IllegalStateException("For great justice");
55        try {
56            CameraRuntimeException runtimeExc = new CameraRuntimeException(12345, cause);
57            throw runtimeExc.asChecked();
58        } catch (CameraAccessException e) {
59            assertEquals(12345, e.getReason());
60            assertNull(e.getMessage());
61            assertEquals(cause, e.getCause());
62        }
63    }
64
65    @SmallTest
66    public void testCameraRuntimeException4() {
67        Throwable cause = new IllegalStateException("For great justice");
68        try {
69            CameraRuntimeException runtimeExc = new CameraRuntimeException(12345, "Hello", cause);
70            throw runtimeExc.asChecked();
71        } catch (CameraAccessException e) {
72            assertEquals(12345, e.getReason());
73            assertEquals("Hello", e.getMessage());
74            assertEquals(cause, e.getCause());
75        }
76    }
77}
78