Home | History | Annotate | Download | only in configuration
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 package org.mockito.configuration;
      6 
      7 import org.mockito.stubbing.Answer;
      8 import org.mockitousage.configuration.CustomizedAnnotationForSmartMockTest;
      9 
     10 public class MockitoConfiguration extends DefaultMockitoConfiguration implements IMockitoConfiguration {
     11 
     12     private Answer<Object> overriddenDefaultAnswer = null;
     13 
     14     private boolean cleansStackTrace;
     15 
     16     private AnnotationEngine overriddenEngine;
     17 
     18     private boolean enableClassCache = true;
     19 
     20     //for testing purposes, allow to override the configuration
     21     public void overrideDefaultAnswer(Answer<Object> defaultAnswer) {
     22         this.overriddenDefaultAnswer = defaultAnswer;
     23     }
     24 
     25     //for testing purposes, allow to override the configuration
     26     public void overrideCleansStackTrace(boolean cleansStackTrace) {
     27         this.cleansStackTrace = cleansStackTrace;
     28     }
     29 
     30     //for testing purposes, allow to override the annotation engine
     31     public void overrideAnnotationEngine(AnnotationEngine engine) {
     32         this.overriddenEngine = engine;
     33     }
     34 
     35     //for testing purposes, allow to override the annotation engine
     36     public void overrideEnableClassCache(boolean enableClassCache) {
     37         this.enableClassCache = enableClassCache;
     38     }
     39 
     40     @Override
     41     public Answer<Object> getDefaultAnswer() {
     42         if (overriddenDefaultAnswer == null) {
     43             return super.getDefaultAnswer();
     44         } else {
     45             return overriddenDefaultAnswer;
     46         }
     47     }
     48 
     49     @Override
     50     public AnnotationEngine getAnnotationEngine() {
     51         if (this.overriddenEngine != null) {
     52             return this.overriddenEngine;
     53         }
     54         return new CustomizedAnnotationForSmartMockTest.CustomInjectingAnnotationEngine();
     55     }
     56 
     57     @Override
     58     public boolean cleansStackTrace() {
     59         return cleansStackTrace;
     60     }
     61 
     62     @Override
     63     public boolean enableClassCache() {
     64         return enableClassCache;
     65     }
     66 
     67 }
     68