How to use hashCode method of org.junit.runner.Description class

Best junit code snippet using org.junit.runner.Description.hashCode

Run junit automation tests on LambdaTest cloud grid

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

copy
1package org.junit.runner.notification;
2
3import org.junit.runner.Description;
4import org.junit.runner.Result;
5import org.junit.runner.notification.RunListener;
6
7/* access modifiers changed from: package-private */
8@RunListener.ThreadSafe
9public final class SynchronizedRunListener extends RunListener {
10    private final RunListener listener;
11    private final Object monitor;
12
13    SynchronizedRunListener(RunListener listener2, Object monitor2) {
14        this.listener = listener2;
15        this.monitor = monitor2;
16    }
17
18    @Override // org.junit.runner.notification.RunListener
19    public void testRunStarted(Description description) throws Exception {
20        synchronized (this.monitor) {
21            this.listener.testRunStarted(description);
22        }
23    }
24
25    @Override // org.junit.runner.notification.RunListener
26    public void testRunFinished(Result result) throws Exception {
27        synchronized (this.monitor) {
28            this.listener.testRunFinished(result);
29        }
30    }
31
32    @Override // org.junit.runner.notification.RunListener
33    public void testStarted(Description description) throws Exception {
34        synchronized (this.monitor) {
35            this.listener.testStarted(description);
36        }
37    }
38
39    @Override // org.junit.runner.notification.RunListener
40    public void testFinished(Description description) throws Exception {
41        synchronized (this.monitor) {
42            this.listener.testFinished(description);
43        }
44    }
45
46    @Override // org.junit.runner.notification.RunListener
47    public void testFailure(Failure failure) throws Exception {
48        synchronized (this.monitor) {
49            this.listener.testFailure(failure);
50        }
51    }
52
53    @Override // org.junit.runner.notification.RunListener
54    public void testAssumptionFailure(Failure failure) {
55        synchronized (this.monitor) {
56            this.listener.testAssumptionFailure(failure);
57        }
58    }
59
60    @Override // org.junit.runner.notification.RunListener
61    public void testIgnored(Description description) throws Exception {
62        synchronized (this.monitor) {
63            this.listener.testIgnored(description);
64        }
65    }
66
67    public int hashCode() {
68        return this.listener.hashCode();
69    }
70
71    public boolean equals(Object other) {
72        if (this == other) {
73            return true;
74        }
75        if (!(other instanceof SynchronizedRunListener)) {
76            return false;
77        }
78        return this.listener.equals(((SynchronizedRunListener) other).listener);
79    }
80
81    public String toString() {
82        return this.listener.toString() + " (with synchronization wrapper)";
83    }
84}
85
Full Screen
copy
1package it.geosolutions.urltesting;
2
3import java.io.ByteArrayOutputStream;
4import java.io.IOException;
5
6import org.apache.commons.httpclient.Header;
7import org.apache.commons.httpclient.HttpMethod;
8import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
9import org.apache.commons.httpclient.methods.RequestEntity;
10import org.junit.runner.Description;
11import org.junit.runner.Result;
12import org.junit.runner.notification.Failure;
13import org.junit.runner.notification.RunListener;
14import org.junit.runner.notification.RunNotifier;
15import org.junit.runner.notification.StoppedByUserException;
16import org.junit.runners.BlockJUnit4ClassRunner;
17import org.junit.runners.model.InitializationError;
18
19
20public class HttpReportRunner extends BlockJUnit4ClassRunner
21{
22
23    public static HttpMethod lastMethod;
24    public static String lastURL;
25
26    public HttpReportRunner(Class<?> klass) throws InitializationError
27    {
28        super(klass);
29    }
30
31    @Override
32    public void run(RunNotifier notifier)
33    {
34        // TODO Auto-generated method stub
35        super.run(new RunNotifierWrapper(notifier));
36    }
37
38    static class RunNotifierWrapper extends RunNotifier
39    {
40        RunNotifier delegate;
41
42        public RunNotifierWrapper(RunNotifier delegate)
43        {
44            this.delegate = delegate;
45        }
46
47        /**
48         * @param failure
49         * @see org.junit.runner.notification.RunNotifier#fireTestFailure(org.junit.runner.notification.Failure)
50         */
51        public void fireTestFailure(Failure failure)
52        {
53            if (lastURL != null)
54            {
55                AssertionError error = new AssertionError(failure.getException().getMessage() + "\n" + buildMethodReport());
56                error.initCause(failure.getException());
57                failure = new Failure(failure.getDescription(), error);
58            }
59
60            delegate.fireTestFailure(failure);
61        }
62
63        private String buildMethodReport()
64        {
65            StringBuilder sb = new StringBuilder();
66            sb.append("Last HTTP call: ");
67
68            String methodName = lastMethod.getClass().getSimpleName();
69            methodName = methodName.substring(0, methodName.indexOf("Method")).toUpperCase();
70            sb.append(methodName);
71
72            Header[] ctHeaders = lastMethod.getRequestHeaders("Content-type");
73            if ((ctHeaders != null) && (ctHeaders.length >= 1))
74            {
75                sb.append(" (").append(ctHeaders[0].getValue()).append(")");
76            }
77
78            sb.append(" ").append(lastURL);
79
80            if (lastMethod instanceof EntityEnclosingMethod)
81            {
82                try
83                {
84                    EntityEnclosingMethod eem = (EntityEnclosingMethod) lastMethod;
85                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
86                    RequestEntity re = eem.getRequestEntity();
87                    if (re != null)
88                    {
89                        re.writeRequest(bos);
90                        sb.append("\nWith body:").append(bos.toString());
91                    }
92                }
93                catch (IOException e)
94                {
95                    throw new RuntimeException("Failed to write out the last http method request body");
96                }
97            }
98
99            return sb.toString();
100        }
101
102        /** ----------------------------------------------------
103         *  PURE DELEGATE METHODS
104         *  ----------------------------------------------------
105         */
106
107        /**
108         * @param listener
109         * @see org.junit.runner.notification.RunNotifier#addFirstListener(org.junit.runner.notification.RunListener)
110         */
111        public void addFirstListener(RunListener listener)
112        {
113            delegate.addFirstListener(listener);
114        }
115
116        /**
117         * @param listener
118         * @see org.junit.runner.notification.RunNotifier#addListener(org.junit.runner.notification.RunListener)
119         */
120        public void addListener(RunListener listener)
121        {
122            delegate.addListener(listener);
123        }
124
125        /**
126         * @param obj
127         * @return
128         * @see java.lang.Object#equals(java.lang.Object)
129         */
130        public boolean equals(Object obj)
131        {
132            return delegate.equals(obj);
133        }
134
135        /**
136         * @param failure
137         * @see org.junit.runner.notification.RunNotifier#fireTestAssumptionFailed(org.junit.runner.notification.Failure)
138         */
139        public void fireTestAssumptionFailed(Failure failure)
140        {
141            delegate.fireTestAssumptionFailed(failure);
142        }
143
144        /**
145         * @param description
146         * @see org.junit.runner.notification.RunNotifier#fireTestFinished(org.junit.runner.Description)
147         */
148        public void fireTestFinished(Description description)
149        {
150            HttpReportRunner.lastMethod = null;
151            HttpReportRunner.lastURL = null;
152
153            delegate.fireTestFinished(description);
154        }
155
156        /**
157         * @param description
158         * @see org.junit.runner.notification.RunNotifier#fireTestIgnored(org.junit.runner.Description)
159         */
160        public void fireTestIgnored(Description description)
161        {
162            delegate.fireTestIgnored(description);
163        }
164
165        /**
166         * @param result
167         * @see org.junit.runner.notification.RunNotifier#fireTestRunFinished(org.junit.runner.Result)
168         */
169        public void fireTestRunFinished(Result result)
170        {
171            delegate.fireTestRunFinished(result);
172        }
173
174        /**
175         * @param description
176         * @see org.junit.runner.notification.RunNotifier#fireTestRunStarted(org.junit.runner.Description)
177         */
178        public void fireTestRunStarted(Description description)
179        {
180            delegate.fireTestRunStarted(description);
181        }
182
183        /**
184         * @param description
185         * @throws StoppedByUserException
186         * @see org.junit.runner.notification.RunNotifier#fireTestStarted(org.junit.runner.Description)
187         */
188        public void fireTestStarted(Description description) throws StoppedByUserException
189        {
190            delegate.fireTestStarted(description);
191        }
192
193        /**
194         * @return
195         * @see java.lang.Object#hashCode()
196         */
197        public int hashCode()
198        {
199            return delegate.hashCode();
200        }
201
202        /**
203         *
204         * @see org.junit.runner.notification.RunNotifier#pleaseStop()
205         */
206        public void pleaseStop()
207        {
208            delegate.pleaseStop();
209        }
210
211        /**
212         * @param listener
213         * @see org.junit.runner.notification.RunNotifier#removeListener(org.junit.runner.notification.RunListener)
214         */
215        public void removeListener(RunListener listener)
216        {
217            delegate.removeListener(listener);
218        }
219
220        /**
221         * @return
222         * @see java.lang.Object#toString()
223         */
224        public String toString()
225        {
226            return delegate.toString();
227        }
228
229
230    }
231
232}
233
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

Trigger hashCode code on LambdaTest Cloud Grid

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