1/*
2 * Copyright (C) 2015 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.server.telecom.tests;
18
19import com.android.server.telecom.Log;
20
21import android.content.Context;
22
23/**
24 * Helper for Mockito-based test cases.
25 */
26public final class MockitoHelper {
27    private static final String DEXCACHE = "dexmaker.dexcache";
28
29    /**
30     * Creates a new helper, which in turn will set the context classloader so
31     * it can load Mockito resources.
32     *
33     * @param packageClass test case class
34     */
35    public void setUp(Context context, Class<?> packageClass) throws Exception {
36        String dexCache = context.getCacheDir().toString();
37        Log.v(this, "Setting property %s to %s", DEXCACHE, dexCache);
38        System.setProperty(DEXCACHE, dexCache);
39    }
40
41    /**
42     * Restores the context classloader to the previous value.
43     */
44    public void tearDown() throws Exception {
45        Log.v(this, "Restoring context classloaders");
46        Log.v(this, "Clearing property %s", DEXCACHE);
47        System.clearProperty(DEXCACHE);
48    }
49}