How to use failed method of org.junit.rules.Stopwatch class

Best junit code snippet using org.junit.rules.Stopwatch.failed

Run junit automation tests on LambdaTest cloud grid

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

copy
1package org.junit.rules;
2
3import java.util.concurrent.TimeUnit;
4import org.junit.AssumptionViolatedException;
5import org.junit.runner.Description;
6import org.junit.runners.model.Statement;
7
8public abstract class Stopwatch implements TestRule {
9    private final Clock clock;
10    private volatile long endNanos;
11    private volatile long startNanos;
12
13    public Stopwatch() {
14        this(new Clock());
15    }
16
17    Stopwatch(Clock clock2) {
18        this.clock = clock2;
19    }
20
21    public long runtime(TimeUnit unit) {
22        return unit.convert(getNanos(), TimeUnit.NANOSECONDS);
23    }
24
25    /* access modifiers changed from: protected */
26    public void succeeded(long nanos, Description description) {
27    }
28
29    /* access modifiers changed from: protected */
30    public void failed(long nanos, Throwable e, Description description) {
31    }
32
33    /* access modifiers changed from: protected */
34    public void skipped(long nanos, AssumptionViolatedException e, Description description) {
35    }
36
37    /* access modifiers changed from: protected */
38    public void finished(long nanos, Description description) {
39    }
40
41    /* access modifiers changed from: private */
42    /* access modifiers changed from: public */
43    private long getNanos() {
44        if (this.startNanos != 0) {
45            long currentEndNanos = this.endNanos;
46            if (currentEndNanos == 0) {
47                currentEndNanos = this.clock.nanoTime();
48            }
49            return currentEndNanos - this.startNanos;
50        }
51        throw new IllegalStateException("Test has not started");
52    }
53
54    /* access modifiers changed from: private */
55    /* access modifiers changed from: public */
56    private void starting() {
57        this.startNanos = this.clock.nanoTime();
58        this.endNanos = 0;
59    }
60
61    /* access modifiers changed from: private */
62    /* access modifiers changed from: public */
63    private void stopping() {
64        this.endNanos = this.clock.nanoTime();
65    }
66
67    @Override // org.junit.rules.TestRule
68    public final Statement apply(Statement base, Description description) {
69        return new InternalWatcher().apply(base, description);
70    }
71
72    private class InternalWatcher extends TestWatcher {
73        private InternalWatcher() {
74        }
75
76        /* access modifiers changed from: protected */
77        @Override // org.junit.rules.TestWatcher
78        public void starting(Description description) {
79            Stopwatch.this.starting();
80        }
81
82        /* access modifiers changed from: protected */
83        @Override // org.junit.rules.TestWatcher
84        public void finished(Description description) {
85            Stopwatch stopwatch = Stopwatch.this;
86            stopwatch.finished(stopwatch.getNanos(), description);
87        }
88
89        /* access modifiers changed from: protected */
90        @Override // org.junit.rules.TestWatcher
91        public void succeeded(Description description) {
92            Stopwatch.this.stopping();
93            Stopwatch stopwatch = Stopwatch.this;
94            stopwatch.succeeded(stopwatch.getNanos(), description);
95        }
96
97        /* access modifiers changed from: protected */
98        @Override // org.junit.rules.TestWatcher
99        public void failed(Throwable e, Description description) {
100            Stopwatch.this.stopping();
101            Stopwatch stopwatch = Stopwatch.this;
102            stopwatch.failed(stopwatch.getNanos(), e, description);
103        }
104
105        /* access modifiers changed from: protected */
106        @Override // org.junit.rules.TestWatcher
107        public void skipped(AssumptionViolatedException e, Description description) {
108            Stopwatch.this.stopping();
109            Stopwatch stopwatch = Stopwatch.this;
110            stopwatch.skipped(stopwatch.getNanos(), e, description);
111        }
112    }
113
114    /* access modifiers changed from: package-private */
115    public static class Clock {
116        Clock() {
117        }
118
119        public long nanoTime() {
120            return System.nanoTime();
121        }
122    }
123}
124
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 Stopwatch

Trigger failed code on LambdaTest Cloud Grid

Execute automation tests with failed 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)