Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
JUnit 4.13.2 Source Code Files
JUnit Source Code Files are provided in the source package file, junit-4.13.2-sources.jar.
You can browse JUnit Source Code files below:
✍: FYIcenter.com
⏎ org/junit/experimental/max/MaxHistory.java
package org.junit.experimental.max; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import org.junit.runner.Description; import org.junit.runner.Result; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; /** * Stores a subset of the history of each test: * <ul> * <li>Last failure timestamp * <li>Duration of last execution * </ul> */ public class MaxHistory implements Serializable { private static final long serialVersionUID = 1L; /** * Loads a {@link MaxHistory} from {@code file}, or generates a new one that * will be saved to {@code file}. */ public static MaxHistory forFolder(File file) { if (file.exists()) { try { return readHistory(file); } catch (CouldNotReadCoreException e) { e.printStackTrace(); file.delete(); } } return new MaxHistory(file); } private static MaxHistory readHistory(File storedResults) throws CouldNotReadCoreException { try { FileInputStream file = new FileInputStream(storedResults); try { ObjectInputStream stream = new ObjectInputStream(file); try { return (MaxHistory) stream.readObject(); } finally { stream.close(); } } finally { file.close(); } } catch (Exception e) { throw new CouldNotReadCoreException(e); } } /* * We have to use the f prefix until the next major release to ensure * serialization compatibility. * See https://github.com/junit-team/junit4/issues/976 */ private final Map<String, Long> fDurations = new HashMap<String, Long>(); private final Map<String, Long> fFailureTimestamps = new HashMap<String, Long>(); private final File fHistoryStore; private MaxHistory(File storedResults) { fHistoryStore = storedResults; } private void save() throws IOException { ObjectOutputStream stream = null; try { stream = new ObjectOutputStream(new FileOutputStream(fHistoryStore)); stream.writeObject(this); } finally { if (stream != null) { stream.close(); } } } Long getFailureTimestamp(Description key) { return fFailureTimestamps.get(key.toString()); } void putTestFailureTimestamp(Description key, long end) { fFailureTimestamps.put(key.toString(), end); } boolean isNewTest(Description key) { return !fDurations.containsKey(key.toString()); } Long getTestDuration(Description key) { return fDurations.get(key.toString()); } void putTestDuration(Description description, long duration) { fDurations.put(description.toString(), duration); } private final class RememberingListener extends RunListener { private long overallStart = System.currentTimeMillis(); private Map<Description, Long> starts = new HashMap<Description, Long>(); @Override public void testStarted(Description description) throws Exception { starts.put(description, System.nanoTime()); // Get most accurate // possible time } @Override public void testFinished(Description description) throws Exception { long end = System.nanoTime(); long start = starts.get(description); putTestDuration(description, end - start); } @Override public void testFailure(Failure failure) throws Exception { putTestFailureTimestamp(failure.getDescription(), overallStart); } @Override public void testRunFinished(Result result) throws Exception { save(); } } private class TestComparator implements Comparator<Description> { public int compare(Description o1, Description o2) { // Always prefer new tests if (isNewTest(o1)) { return -1; } if (isNewTest(o2)) { return 1; } // Then most recently failed first int result = getFailure(o2).compareTo(getFailure(o1)); return result != 0 ? result // Then shorter tests first : getTestDuration(o1).compareTo(getTestDuration(o2)); } private Long getFailure(Description key) { Long result = getFailureTimestamp(key); if (result == null) { return 0L; // 0 = "never failed (that I know about)" } return result; } } /** * @return a listener that will update this history based on the test * results reported. */ public RunListener listener() { return new RememberingListener(); } /** * @return a comparator that ranks tests based on the JUnit Max sorting * rules, as described in the {@link MaxCore} class comment. */ public Comparator<Description> testComparator() { return new TestComparator(); } }
⏎ org/junit/experimental/max/MaxHistory.java
Or download all of them as a single archive file:
File name: junit-4.13.2-sources.jar File size: 234540 bytes Release date: 2021-02-13 Download
⇒ Download and Install junit-4.12.jar
⇐ Download and Install junit-4.13.2.jar
2016-03-28, 11597👍, 0💬
Popular Posts:
How to download and install JDK (Java Development Kit) 1.4? If you want to write Java applications, ...
pache Derby is an open source relational database implemented entirely in Java and available under t...
JDK 17 jdk.compiler.jmod is the JMOD file for JDK 17 Compiler tool, which can be invoked by the "jav...
JDK 7 tools.jar is the JAR file for JDK 7 tools. It contains Java classes to support different JDK t...
What Is poi-3.5.jar - Part 2? poi-3.5.jar is one of the JAR files for Apache POI 3.5, which provides...