How to use testComparator method of org.junit.experimental.max.MaxHistory class

Best junit code snippet using org.junit.experimental.max.MaxHistory.testComparator

Run junit automation tests on LambdaTest cloud grid

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

copy
1class org.junit.experimental.max.MaxHistory$TestComparator implements java.util.Comparator<org.junit.runner.Description> {
2  final org.junit.experimental.max.MaxHistory this$0;
3  public int compare(org.junit.runner.Description, org.junit.runner.Description);
4  public int compare(java.lang.Object, java.lang.Object);
5  org.junit.experimental.max.MaxHistory$TestComparator(org.junit.experimental.max.MaxHistory, org.junit.experimental.max.MaxHistory$1);
6}
7
Full Screen
copy
1package org.junit.experimental.max;
2
3import java.io.File;
4import java.io.FileOutputStream;
5import java.io.IOException;
6import java.io.ObjectOutputStream;
7import java.io.Serializable;
8import java.util.Comparator;
9import java.util.HashMap;
10import java.util.Map;
11import org.junit.runner.Description;
12import org.junit.runner.Result;
13import org.junit.runner.notification.Failure;
14import org.junit.runner.notification.RunListener;
15
16public class MaxHistory
17  implements Serializable
18{
19  private static final long serialVersionUID = 1L;
20  private final Map<String, Long> fDurations = new HashMap();
21  private final Map<String, Long> fFailureTimestamps = new HashMap();
22  private final File fHistoryStore;
23  
24  private MaxHistory(File paramFile)
25  {
26    this.fHistoryStore = paramFile;
27  }
28  
29  public static MaxHistory forFolder(File paramFile)
30  {
31    if (paramFile.exists()) {
32      try
33      {
34        MaxHistory localMaxHistory = readHistory(paramFile);
35        return localMaxHistory;
36      }
37      catch (CouldNotReadCoreException localCouldNotReadCoreException)
38      {
39        localCouldNotReadCoreException.printStackTrace();
40        paramFile.delete();
41      }
42    }
43    return new MaxHistory(paramFile);
44  }
45  
46  /* Error */
47  private static MaxHistory readHistory(File paramFile)
48    throws CouldNotReadCoreException
49  {
50    // Byte code:
51    //   0: new 72	java/io/FileInputStream
52    //   3: dup
53    //   4: aload_0
54    //   5: invokespecial 73	java/io/FileInputStream:<init>	(Ljava/io/File;)V
55    //   8: astore_0
56    //   9: new 75	java/io/ObjectInputStream
57    //   12: dup
58    //   13: aload_0
59    //   14: invokespecial 78	java/io/ObjectInputStream:<init>	(Ljava/io/InputStream;)V
60    //   17: astore_1
61    //   18: aload_1
62    //   19: invokevirtual 82	java/io/ObjectInputStream:readObject	()Ljava/lang/Object;
63    //   22: checkcast 2	org/junit/experimental/max/MaxHistory
64    //   25: astore_2
65    //   26: aload_1
66    //   27: invokevirtual 85	java/io/ObjectInputStream:close	()V
67    //   30: aload_0
68    //   31: invokevirtual 86	java/io/FileInputStream:close	()V
69    //   34: aload_2
70    //   35: areturn
71    //   36: astore_2
72    //   37: aload_1
73    //   38: invokevirtual 85	java/io/ObjectInputStream:close	()V
74    //   41: aload_2
75    //   42: athrow
76    //   43: astore_1
77    //   44: aload_0
78    //   45: invokevirtual 86	java/io/FileInputStream:close	()V
79    //   48: aload_1
80    //   49: athrow
81    //   50: astore_0
82    //   51: new 51	org/junit/experimental/max/CouldNotReadCoreException
83    //   54: dup
84    //   55: aload_0
85    //   56: invokespecial 89	org/junit/experimental/max/CouldNotReadCoreException:<init>	(Ljava/lang/Throwable;)V
86    //   59: athrow
87    // Local variable table:
88    //   start	length	slot	name	signature
89    //   0	60	0	paramFile	File
90    //   17	21	1	localObjectInputStream	java.io.ObjectInputStream
91    //   43	6	1	localObject1	Object
92    //   25	10	2	localMaxHistory	MaxHistory
93    //   36	6	2	localObject2	Object
94    // Exception table:
95    //   from	to	target	type
96    //   18	26	36	finally
97    //   9	18	43	finally
98    //   26	30	43	finally
99    //   37	43	43	finally
100    //   0	9	50	java/lang/Exception
101    //   30	34	50	java/lang/Exception
102    //   44	50	50	java/lang/Exception
103  }
104  
105  private void save()
106    throws IOException
107  {
108    ObjectOutputStream localObjectOutputStream = new ObjectOutputStream(new FileOutputStream(this.fHistoryStore));
109    localObjectOutputStream.writeObject(this);
110    localObjectOutputStream.close();
111  }
112  
113  Long getFailureTimestamp(Description paramDescription)
114  {
115    return (Long)this.fFailureTimestamps.get(paramDescription.toString());
116  }
117  
118  Long getTestDuration(Description paramDescription)
119  {
120    return (Long)this.fDurations.get(paramDescription.toString());
121  }
122  
123  boolean isNewTest(Description paramDescription)
124  {
125    return !this.fDurations.containsKey(paramDescription.toString());
126  }
127  
128  public RunListener listener()
129  {
130    return new RememberingListener(null);
131  }
132  
133  void putTestDuration(Description paramDescription, long paramLong)
134  {
135    this.fDurations.put(paramDescription.toString(), Long.valueOf(paramLong));
136  }
137  
138  void putTestFailureTimestamp(Description paramDescription, long paramLong)
139  {
140    this.fFailureTimestamps.put(paramDescription.toString(), Long.valueOf(paramLong));
141  }
142  
143  public Comparator<Description> testComparator()
144  {
145    return new TestComparator(null);
146  }
147  
148  final class RememberingListener
149    extends RunListener
150  {
151    private long overallStart = System.currentTimeMillis();
152    private Map<Description, Long> starts = new HashMap();
153    
154    private RememberingListener() {}
155    
156    public void testFailure(Failure paramFailure)
157      throws Exception
158    {
159      MaxHistory.this.putTestFailureTimestamp(paramFailure.getDescription(), this.overallStart);
160    }
161    
162    public void testFinished(Description paramDescription)
163      throws Exception
164    {
165      long l1 = System.nanoTime();
166      long l2 = ((Long)this.starts.get(paramDescription)).longValue();
167      MaxHistory.this.putTestDuration(paramDescription, l1 - l2);
168    }
169    
170    public void testRunFinished(Result paramResult)
171      throws Exception
172    {
173      MaxHistory.this.save();
174    }
175    
176    public void testStarted(Description paramDescription)
177      throws Exception
178    {
179      this.starts.put(paramDescription, Long.valueOf(System.nanoTime()));
180    }
181  }
182  
183  class TestComparator
184    implements Comparator<Description>
185  {
186    private TestComparator() {}
187    
188    private Long getFailure(Description paramDescription)
189    {
190      Long localLong = MaxHistory.this.getFailureTimestamp(paramDescription);
191      paramDescription = localLong;
192      if (localLong == null) {
193        paramDescription = Long.valueOf(0L);
194      }
195      return paramDescription;
196    }
197    
198    public int compare(Description paramDescription1, Description paramDescription2)
199    {
200      int i;
201      if (MaxHistory.this.isNewTest(paramDescription1)) {
202        i = -1;
203      }
204      int j;
205      do
206      {
207        return i;
208        if (MaxHistory.this.isNewTest(paramDescription2)) {
209          return 1;
210        }
211        j = getFailure(paramDescription2).compareTo(getFailure(paramDescription1));
212        i = j;
213      } while (j != 0);
214      return MaxHistory.this.getTestDuration(paramDescription1).compareTo(MaxHistory.this.getTestDuration(paramDescription2));
215    }
216  }
217}
218
219

220/* Location:           L:\local\mybackup\temp\qq_apk\com.tencent.tim\classes14.jar

221 * Qualified Name:     org.junit.experimental.max.MaxHistory

222 * JD-Core Version:    0.7.0.1

223 */
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 MaxHistory

Trigger testComparator code on LambdaTest Cloud Grid

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