How to use method of org.mockito.exceptions.base.TraceBuilder class

Best Mockito code snippet using org.mockito.exceptions.base.TraceBuilder.

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.exceptions.base;
7
8import java.util.Collections;
9import java.util.LinkedList;
10import java.util.List;
11
12public class TraceBuilder {
13
14    private String[] methods = {};
15    private String[] classes = {};
16
17    public Throwable toThrowable() {
18        RuntimeException exception = new RuntimeException();
19        exception.setStackTrace(toTraceArray());
20        return exception;
21    }
22
23    private List<StackTraceElement> toTraceList() {
24        assert methods.length == 0 || classes.length == 0;
25        
26        List<StackTraceElement> trace = new LinkedList<StackTraceElement>();
27        for (String method : methods) {
28            trace.add(new StackTraceElement("SomeClass", method, "SomeClass.java", 50));
29        }
30        for (String clazz : classes) {
31            trace.add(new StackTraceElement(clazz, "someMethod", clazz + ".java", 50));
32        }
33        
34        Collections.reverse(trace);
35        return trace;
36    }
37    
38    public StackTraceElement[] toTraceArray() {
39        return toTraceList().toArray(new StackTraceElement[0]);
40    }
41
42    public TraceBuilder classes(String ... classes) {
43        this.classes = classes;
44        return this;
45    }
46    
47    public TraceBuilder methods(String ... methods) {
48        this.methods = methods;
49        return this;
50    }
51}
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 TraceBuilder

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)