How to use method of org.mockito.configuration.IMockitoConfiguration class

Best Mockito code snippet using org.mockito.configuration.IMockitoConfiguration.

Run Mockito automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package com.handsome.imock.configuration;
2
3import org.mockito.ReturnValues;
4import org.mockito.configuration.AnnotationEngine;
5import org.mockito.configuration.IMockitoConfiguration;
6import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;
7import org.mockito.stubbing.Answer;
8
9/**
10 * Created by jiayu.shenjy on 2016/4/11.
11 */
12public class IMockDefaultMockitoConfiguration implements IMockitoConfiguration {
13
14    /* (non-Javadoc)
15     * @see org.mockito.IMockitoConfiguration#getReturnValues()
16     */
17    @Deprecated
18    public ReturnValues getReturnValues() {
19        throw new RuntimeException("\n" + "This method should not be used by the framework because it was deprecated"
20                + "\n" + "Please report the failure to the Mockito mailing list");
21    }
22
23    public Answer<Object> getDefaultAnswer() {
24        return new ReturnsEmptyValues();
25    }
26
27    /* (non-Javadoc)
28     * @see org.mockito.IMockitoConfiguration#getAnnotationEngine()
29     */
30    public AnnotationEngine getAnnotationEngine() {
31        return new IMockInjectingAnnotationEngine();
32    }
33
34    /* (non-Javadoc)
35     * @see org.mockito.configuration.IMockitoConfiguration#cleansStackTrace()
36     */
37    public boolean cleansStackTrace() {
38        return true;
39    }
40
41    /* (non-Javadoc)
42     * @see org.mockito.configuration.IMockitoConfiguration#enableClassCache()
43     */
44    public boolean enableClassCache() {
45        return true;
46    }
47
48
49}
Full Screen
copy
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.configuration;
6
7import java.io.Serializable;
8import org.mockito.configuration.AnnotationEngine;
9import org.mockito.configuration.DefaultMockitoConfiguration;
10import org.mockito.configuration.IMockitoConfiguration;
11import org.mockito.internal.configuration.plugins.Plugins;
12import org.mockito.stubbing.Answer;
13
14/**
15 * Thread-safe wrapper on user-defined org.mockito.configuration.MockitoConfiguration implementation
16 */
17public class GlobalConfiguration implements IMockitoConfiguration, Serializable {
18    private static final long serialVersionUID = -2860353062105505938L;
19
20    private static final ThreadLocal<IMockitoConfiguration> GLOBAL_CONFIGURATION = new ThreadLocal<IMockitoConfiguration>();
21
22    //back door for testing
23    IMockitoConfiguration getIt() {
24        return GLOBAL_CONFIGURATION.get();
25    }
26
27    public GlobalConfiguration() {
28        //Configuration should be loaded only once but I cannot really test it
29        if (GLOBAL_CONFIGURATION.get() == null) {
30            GLOBAL_CONFIGURATION.set(createConfig());
31        }
32    }
33
34    private IMockitoConfiguration createConfig() {
35        IMockitoConfiguration defaultConfiguration = new DefaultMockitoConfiguration();
36        IMockitoConfiguration config = new ClassPathLoader().loadConfiguration();
37        if (config != null) {
38            return config;
39        } else {
40            return defaultConfiguration;
41        }
42    }
43
44    public static void validate() {
45        new GlobalConfiguration();
46    }
47
48    public AnnotationEngine getAnnotationEngine() {
49        return GLOBAL_CONFIGURATION.get().getAnnotationEngine();
50    }
51
52    public org.mockito.plugins.AnnotationEngine tryGetPluginAnnotationEngine() {
53        IMockitoConfiguration configuration = GLOBAL_CONFIGURATION.get();
54        if (configuration.getClass() == DefaultMockitoConfiguration.class) {
55            return Plugins.getAnnotationEngine();
56        }
57        return configuration.getAnnotationEngine();
58    }
59
60
61
62    public boolean cleansStackTrace() {
63        return GLOBAL_CONFIGURATION.get().cleansStackTrace();
64    }
65
66    public boolean enableClassCache() {
67        return GLOBAL_CONFIGURATION.get().enableClassCache();
68    }
69
70    public Answer<Object> getDefaultAnswer() {
71        return GLOBAL_CONFIGURATION.get().getDefaultAnswer();
72    }
73}
74
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in IMockitoConfiguration

Trigger code on LambdaTest Cloud Grid

Execute automation tests with on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)