How to use MaxHistory class of org.junit.experimental.max package

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

Source:MaxHistory.java Github

copy

Full Screen

...10import org.junit.runner.Description;11import org.junit.runner.Result;12import org.junit.runner.notification.Failure;13import org.junit.runner.notification.RunListener;14public class MaxHistory15 implements Serializable16{17 private static final long serialVersionUID = 1L;18 private final Map<String, Long> fDurations = new HashMap();19 private final Map<String, Long> fFailureTimestamps = new HashMap();20 private final File fHistoryStore;21 22 private MaxHistory(File paramFile)23 {24 this.fHistoryStore = paramFile;25 }26 27 public static MaxHistory forFolder(File paramFile)28 {29 if (paramFile.exists()) {30 try31 {32 MaxHistory localMaxHistory = readHistory(paramFile);33 return localMaxHistory;34 }35 catch (CouldNotReadCoreException localCouldNotReadCoreException)36 {37 localCouldNotReadCoreException.printStackTrace();38 paramFile.delete();39 }40 }41 return new MaxHistory(paramFile);42 }43 44 /* Error */45 private static MaxHistory readHistory(File paramFile)46 throws CouldNotReadCoreException47 {48 // Byte code:49 // 0: new 72 java/io/FileInputStream50 // 3: dup51 // 4: aload_052 // 5: invokespecial 73 java/io/FileInputStream:<init> (Ljava/io/File;)V53 // 8: astore_054 // 9: new 75 java/io/ObjectInputStream55 // 12: dup56 // 13: aload_057 // 14: invokespecial 78 java/io/ObjectInputStream:<init> (Ljava/io/InputStream;)V58 // 17: astore_159 // 18: aload_160 // 19: invokevirtual 82 java/io/ObjectInputStream:readObject ()Ljava/lang/Object;61 // 22: checkcast 2 org/junit/experimental/max/MaxHistory62 // 25: astore_263 // 26: aload_164 // 27: invokevirtual 85 java/io/ObjectInputStream:close ()V65 // 30: aload_066 // 31: invokevirtual 86 java/io/FileInputStream:close ()V67 // 34: aload_268 // 35: areturn69 // 36: astore_270 // 37: aload_171 // 38: invokevirtual 85 java/io/ObjectInputStream:close ()V72 // 41: aload_273 // 42: athrow74 // 43: astore_175 // 44: aload_076 // 45: invokevirtual 86 java/io/FileInputStream:close ()V77 // 48: aload_178 // 49: athrow79 // 50: astore_080 // 51: new 51 org/junit/experimental/max/CouldNotReadCoreException81 // 54: dup82 // 55: aload_083 // 56: invokespecial 89 org/junit/experimental/max/CouldNotReadCoreException:<init> (Ljava/lang/Throwable;)V84 // 59: athrow85 // Local variable table:86 // start length slot name signature87 // 0 60 0 paramFile File88 // 17 21 1 localObjectInputStream java.io.ObjectInputStream89 // 43 6 1 localObject1 Object90 // 25 10 2 localMaxHistory MaxHistory91 // 36 6 2 localObject2 Object92 // Exception table:93 // from to target type94 // 18 26 36 finally95 // 9 18 43 finally96 // 26 30 43 finally97 // 37 43 43 finally98 // 0 9 50 java/lang/Exception99 // 30 34 50 java/lang/Exception100 // 44 50 50 java/lang/Exception101 }102 103 private void save()104 throws IOException105 {106 ObjectOutputStream localObjectOutputStream = new ObjectOutputStream(new FileOutputStream(this.fHistoryStore));107 localObjectOutputStream.writeObject(this);108 localObjectOutputStream.close();109 }110 111 Long getFailureTimestamp(Description paramDescription)112 {113 return (Long)this.fFailureTimestamps.get(paramDescription.toString());114 }115 116 Long getTestDuration(Description paramDescription)117 {118 return (Long)this.fDurations.get(paramDescription.toString());119 }120 121 boolean isNewTest(Description paramDescription)122 {123 return !this.fDurations.containsKey(paramDescription.toString());124 }125 126 public RunListener listener()127 {128 return new RememberingListener(null);129 }130 131 void putTestDuration(Description paramDescription, long paramLong)132 {133 this.fDurations.put(paramDescription.toString(), Long.valueOf(paramLong));134 }135 136 void putTestFailureTimestamp(Description paramDescription, long paramLong)137 {138 this.fFailureTimestamps.put(paramDescription.toString(), Long.valueOf(paramLong));139 }140 141 public Comparator<Description> testComparator()142 {143 return new TestComparator(null);144 }145 146 private final class RememberingListener147 extends RunListener148 {149 private long overallStart = System.currentTimeMillis();150 private Map<Description, Long> starts = new HashMap();151 152 private RememberingListener() {}153 154 public void testFailure(Failure paramFailure)155 throws Exception156 {157 MaxHistory.this.putTestFailureTimestamp(paramFailure.getDescription(), this.overallStart);158 }159 160 public void testFinished(Description paramDescription)161 throws Exception162 {163 long l1 = System.nanoTime();164 long l2 = ((Long)this.starts.get(paramDescription)).longValue();165 MaxHistory.this.putTestDuration(paramDescription, l1 - l2);166 }167 168 public void testRunFinished(Result paramResult)169 throws Exception170 {171 MaxHistory.this.save();172 }173 174 public void testStarted(Description paramDescription)175 throws Exception176 {177 this.starts.put(paramDescription, Long.valueOf(System.nanoTime()));178 }179 }180 181 private class TestComparator182 implements Comparator<Description>183 {184 private TestComparator() {}185 186 private Long getFailure(Description paramDescription)187 {188 Long localLong = MaxHistory.this.getFailureTimestamp(paramDescription);189 paramDescription = localLong;190 if (localLong == null) {191 paramDescription = Long.valueOf(0L);192 }193 return paramDescription;194 }195 196 public int compare(Description paramDescription1, Description paramDescription2)197 {198 int i;199 if (MaxHistory.this.isNewTest(paramDescription1)) {200 i = -1;201 }202 int j;203 do204 {205 return i;206 if (MaxHistory.this.isNewTest(paramDescription2)) {207 return 1;208 }209 j = getFailure(paramDescription2).compareTo(getFailure(paramDescription1));210 i = j;211 } while (j != 0);212 return MaxHistory.this.getTestDuration(paramDescription1).compareTo(MaxHistory.this.getTestDuration(paramDescription2));213 }214 }215}216/* Location: /home/dev/Downloads/apk/dex2jar-2.0/crumby-dex2jar.jar!/org/junit/experimental/max/MaxHistory.class217 * Java compiler version: 6 (50.0)218 * JD-Core Version: 0.7.1219 */...

Full Screen

Full Screen

Source:MaxCore.java Github

copy

Full Screen

...17import org.junit.runners.Suite;18import org.junit.runners.model.InitializationError;19public class MaxCore {20 private static final String MALFORMED_JUNIT_3_TEST_CLASS_PREFIX = "malformed JUnit 3 test class: ";21 private final MaxHistory history;22 @Deprecated23 public static MaxCore forFolder(String folderName) {24 return storedLocally(new File(folderName));25 }26 public static MaxCore storedLocally(File storedResults) {27 return new MaxCore(storedResults);28 }29 private MaxCore(File storedResults) {30 this.history = MaxHistory.forFolder(storedResults);31 }32 public Result run(Class<?> testClass) {33 return run(Request.aClass(testClass));34 }35 public Result run(Request request) {36 return run(request, new JUnitCore());37 }38 public Result run(Request request, JUnitCore core) {39 core.addListener(this.history.listener());40 return core.run(sortRequest(request).getRunner());41 }42 public Request sortRequest(Request request) {43 if (request instanceof SortingRequest) {44 return request;...

Full Screen

Full Screen

Source:MaxHistory$RememberingListener.java Github

copy

Full Screen

1final class org.junit.experimental.max.MaxHistory$RememberingListener extends org.junit.runner.notification.RunListener {2 final org.junit.experimental.max.MaxHistory this$0;3 public void testStarted(org.junit.runner.Description) throws java.lang.Exception;4 public void testFinished(org.junit.runner.Description) throws java.lang.Exception;5 public void testFailure(org.junit.runner.notification.Failure) throws java.lang.Exception;6 public void testRunFinished(org.junit.runner.Result) throws java.lang.Exception;7 org.junit.experimental.max.MaxHistory$RememberingListener(org.junit.experimental.max.MaxHistory, org.junit.experimental.max.MaxHistory$1);8}...

Full Screen

Full Screen

Source:MaxHistory$TestComparator.java Github

copy

Full Screen

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}...

Full Screen

Full Screen

MaxHistory

Using AI Code Generation

copy

Full Screen

1import org.junit.experimental.max.MaxHistory;2import org.junit.experimental.max.MaxCore;3import java.util.List;4import java.util.ArrayList;5import java.util.Collections;6import java.util.Comparator;7import java.util.concurrent.TimeUnit;8import java.io.File;9import java.io.IOException;10import java.io.FileWriter;11import java.io.BufferedWriter;12import java.io.PrintWriter;13import java.io.FileNotFoundException;14import java.io.FileReader;15import java.io.BufferedReader;16import java.io.InputStreamReader;17import java.io.FileInputStream;18import java.io.FileOutputStream;19import java.io.InputStream;20import java.io.OutputStream;21import java.io.PrintStream;22import java.nio.channels.FileChannel;23import java.nio.file.Files;24import java.nio.file.Path;25import java.nio.file.Paths;26import java.nio.file.StandardCopyOption;27import java.nio.file.StandardOpenOption;28import java.nio.charset.StandardCharsets;29import java.nio.file.attribute.BasicFileAttributes;30import java.nio.file.attribute.FileTime;31import java.util.Date;32import java.text.SimpleDateFormat;33import java.util.Map;34import java.util.HashMap;35import java.util.Set;36import java.util.HashSet;37import java.util.Iterator;38import java.util.concurrent.TimeUnit;39import java.util.regex.Pattern;40import java.util.regex.Matcher;41import java.lang.reflect.Method;42import java.lang.reflect.Field;43import java.lang.reflect.Modifier;44import java.lang.reflect.Type;45import java.lang.reflect.TypeVariable;46import java.lang.reflect.TypeVariable;47import java.lang.reflect.Type;48import java.lang.reflect.ParameterizedType;49import java.lang.reflect.InvocationTargetException;50import java.lang.reflect.Constructor;51import java.lang.annotation.Annotation;52import java.lang.annotation.ElementType;53import java.lang.annotation.Retention;54import java.lang.annotation.RetentionPolicy;55import java.lang.annotation.Target;56import java.lang.annotation.Inherited;57import java.lang.annotation.Documented;58import java.lang.annotation.Repeatable;59import java.lang.annotation.AnnotationFormatError;60import java.lang.annotation.AnnotationTypeMismatchException;61import java.lang.annotation.IncompleteAnnotationException;62import java.lang.annotation.AnnotationTypeMismatchException;63import java.lang.annotation.IncompleteAnnotationException;64import java.lang.annotation.AnnotationFormatError;65import java.lang.annotation.AnnotationTypeMismatchException;66import java.lang.annotation.IncompleteAnnotationException;67import java.lang.annotation.AnnotationFormatError;68import java.lang.annotation.AnnotationTypeMismatchException;69import java.lang.annotation.IncompleteAnnotationException;70import java.lang.annotation.AnnotationFormatError;

Full Screen

Full Screen
copy
1import javax.swing.*;2import java.awt.*;3import java.awt.event.*;45public class Test6{7 public static void main(String[] args)8 {9 final JFrame f = new JFrame("");10 JPanel panel = new JPanel();11 panel.setLayout(new GridLayout(2000,1));121314 for(int i = 0; i != 2000; i++)15 {16 JButton btn = new JButton("Button 2");17 panel.add(btn);18 }19 final JScrollPane sPane = new JScrollPane(panel);20 final int increment = 5000;21 sPane.getVerticalScrollBar().setUnitIncrement(increment);2223 KeyStroke kUp = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);24 KeyStroke kDown = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0);2526 sPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(kUp,"actionWhenKeyUp");27 sPane.getActionMap().put("actionWhenKeyUp",28 new AbstractAction("keyUpAction")29 {30 public void actionPerformed(ActionEvent e)31 {32 final JScrollBar bar = sPane.getVerticalScrollBar();33 int currentValue = bar.getValue();34 bar.setValue(currentValue - increment);35 }36 }37 );3839 sPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(kDown,"actionWhenKeyDown");40 sPane.getActionMap().put("actionWhenKeyDown",41 new AbstractAction("keyDownAction")42 {43 public void actionPerformed(ActionEvent e)44 {45 final JScrollBar bar = sPane.getVerticalScrollBar();46 int currentValue = bar.getValue();47 bar.setValue(currentValue + increment);48 }49 }50 );51 f.add(sPane);52 f.pack();53545556 SwingUtilities.invokeLater(57 new Runnable()58 {59 public void run()60 {61 f.setVisible(true);62 }63 }64 );65 }66}67
Full Screen
copy
1import java.awt.Color;2import java.awt.Dimension;3import java.awt.Point;4import java.awt.Rectangle;5import java.awt.event.MouseEvent;6import java.awt.event.MouseListener;7import java.util.Random;89import javax.swing.JFrame;10import javax.swing.JPanel;11import javax.swing.JScrollBar;12import javax.swing.JScrollPane;13import javax.swing.JViewport;14import javax.swing.event.MouseInputAdapter;1516public class testeSLider extends JFrame {17 private JPanel jp;18 private JScrollPane sc;1920 public testeSLider() {21 setVisible(true);22 setDefaultCloseOperation(EXIT_ON_CLOSE);23 setResizable(false);24 setLocationRelativeTo(null);25 setSize(new Dimension(820, 130));26 setBackground(Color.BLACK);27 jp = new JPanel();28 sc = new JScrollPane(jp);29 jp.setBackground(Color.GRAY);3031 sc.setBounds(0, 0, 100, 400);32 sc.setBackground(Color.DARK_GRAY);33 sc.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 0));34 sc.setBounds(50, 30, 300, 50);3536 getContentPane().add(sc);3738 int x = 0;39 for (int i = 0; i < 50; i++) {40 JPanel item = new JPanel();41 x = (87 * i) + (i * 10);4243 item.setBackground(Color.getHSBColor(new Random().nextInt(255),44 new Random().nextInt(255), new Random().nextInt(255)));45 item.setBounds(x, 5, 0, 0);46 item.setPreferredSize(new Dimension(90, 90));47 jp.add(item);48 addEfeito(item);49 }5051 }5253 private void addEfeito(JPanel item) {5455 MouseInputAdapter adapter = new MouseInputAdapter() {56 private JPanel panelTmp;57 private int deslocamento = 3;58 private int mouseStartX;59 private int mouseStartY;6061 @Override62 public void mouseDragged(MouseEvent e) {6364 final JScrollBar bar = sc.getHorizontalScrollBar();65 int currentValue = bar.getValue();66 bar.setValue(currentValue + (mouseStartX - e.getX()));67 }6869 @Override70 public void mouseEntered(MouseEvent e) {71 panelTmp = ((JPanel) e.getSource());72 panelTmp.setBounds(panelTmp.getX(), panelTmp.getY(),73 panelTmp.getWidth() + deslocamento,74 panelTmp.getHeight() + deslocamento);7576 }7778 @Override79 public void mouseExited(MouseEvent e) {80 panelTmp = ((JPanel) e.getSource());8182 panelTmp.setBounds(panelTmp.getX(), panelTmp.getY(),83 panelTmp.getWidth() - deslocamento,84 panelTmp.getHeight() - deslocamento);8586 }8788 @Override89 public void mouseClicked(MouseEvent e) {90 mouseStartX = e.getX();91 mouseStartY = e.getY();92 }9394 @Override95 public void mousePressed(MouseEvent e) {96 mouseStartX = e.getX();97 mouseStartY = e.getY();98 }99100 @Override101 public void mouseReleased(MouseEvent e) {102103 }104 };105 item.addMouseListener(adapter);106 item.addMouseMotionListener(adapter);107108 }109110 public static void main(String args[]) {111 new testeSLider();112 }113114}115
Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

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

Most used methods in MaxHistory

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful