Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
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 (322)
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/internal/runners/MethodValidator.java
package org.junit.internal.runners;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runners.BlockJUnit4ClassRunner;
/**
* @deprecated Included for backwards compatibility with JUnit 4.4. Will be
* removed in the next major release. Please use
* {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}.
*/
@Deprecated
public class MethodValidator {
private final List<Throwable> errors = new ArrayList<Throwable>();
private TestClass testClass;
public MethodValidator(TestClass testClass) {
this.testClass = testClass;
}
public void validateInstanceMethods() {
validateTestMethods(After.class, false);
validateTestMethods(Before.class, false);
validateTestMethods(Test.class, false);
List<Method> methods = testClass.getAnnotatedMethods(Test.class);
if (methods.size() == 0) {
errors.add(new Exception("No runnable methods"));
}
}
public void validateStaticMethods() {
validateTestMethods(BeforeClass.class, true);
validateTestMethods(AfterClass.class, true);
}
public List<Throwable> validateMethodsForDefaultRunner() {
validateNoArgConstructor();
validateStaticMethods();
validateInstanceMethods();
return errors;
}
public void assertValid() throws InitializationError {
if (!errors.isEmpty()) {
throw new InitializationError(errors);
}
}
public void validateNoArgConstructor() {
try {
testClass.getConstructor();
} catch (Exception e) {
errors.add(new Exception("Test class should have public zero-argument constructor", e));
}
}
private void validateTestMethods(Class<? extends Annotation> annotation,
boolean isStatic) {
List<Method> methods = testClass.getAnnotatedMethods(annotation);
for (Method each : methods) {
if (Modifier.isStatic(each.getModifiers()) != isStatic) {
String state = isStatic ? "should" : "should not";
errors.add(new Exception("Method " + each.getName() + "() "
+ state + " be static"));
}
if (!Modifier.isPublic(each.getDeclaringClass().getModifiers())) {
errors.add(new Exception("Class " + each.getDeclaringClass().getName()
+ " should be public"));
}
if (!Modifier.isPublic(each.getModifiers())) {
errors.add(new Exception("Method " + each.getName()
+ " should be public"));
}
if (each.getReturnType() != Void.TYPE) {
errors.add(new Exception("Method " + each.getName()
+ "should have a return type of void"));
}
if (each.getParameterTypes().length != 0) {
errors.add(new Exception("Method " + each.getName()
+ " should have no parameters"));
}
}
}
}
⏎ org/junit/internal/runners/MethodValidator.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, ≈93🔥, 0💬
Popular Posts:
What Is poi-ooxml-5.2.3.jar? poi-ooxml-5.2.3.jar is one of the JAR files for Apache POI 5.2.3, which...
jlGui is a music player for the Java platform. It is based on Java Sound 1.0 (i.e. JDK 1.3+). It sup...
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
How to download and install javamail-1_2.zip? The JavaMail API is a set of abstract APIs that model ...
maven-embedder-3.8.6.jar is the JAR file for Apache Maven 3.8.6 Embedder module. Apache Maven is a s...