Home | History | Annotate | Download | only in inline
      1 /*
      2  * Copyright (C) 2017 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.dx.mockito.inline;
     18 
     19 import org.mockito.exceptions.stacktrace.StackTraceCleaner;
     20 import org.mockito.plugins.StackTraceCleanerProvider;
     21 
     22 /**
     23  * Cleans out mockito internal elements out of stack traces. This creates stack traces as if mockito
     24  * would have not intercepted any calls.
     25  */
     26 public final class DexmakerStackTraceCleaner implements StackTraceCleanerProvider {
     27     @Override
     28     public StackTraceCleaner getStackTraceCleaner(final StackTraceCleaner defaultCleaner) {
     29         return new StackTraceCleaner() {
     30             @Override
     31             public boolean isIn(StackTraceElement candidate) {
     32                 String className = candidate.getClassName();
     33 
     34                 return defaultCleaner.isIn(candidate)
     35                         // dexmaker class proxies
     36                         && !className.endsWith("_Proxy")
     37 
     38                         && !className.startsWith("java.lang.reflect.Method")
     39                         && !className.startsWith("java.lang.reflect.Proxy")
     40                         && !(className.startsWith("com.android.dx.mockito.")
     41                              // Do not clean unit tests
     42                              && !className.startsWith("com.android.dx.mockito.tests")
     43                              && !className.startsWith("com.android.dx.mockito.inline.tests"))
     44 
     45                         // dalvik interface proxies
     46                         && !className.startsWith("$Proxy")
     47                         && !className.matches(".*\\.\\$Proxy[\\d]+");
     48             }
     49         };
     50     }
     51 
     52 }
     53