Skip to content

Commit

Permalink
remove 'f' prefix from field names, add LEGACY_CODING_STYLE, change C…
Browse files Browse the repository at this point in the history
…ODING_STYLE
  • Loading branch information
Alex Yursha authored and stefanbirkner committed Jun 18, 2014
1 parent 63b1950 commit df00d5e
Show file tree
Hide file tree
Showing 58 changed files with 534 additions and 530 deletions.
3 changes: 3 additions & 0 deletions CODING_STYLE.txt
@@ -0,0 +1,3 @@
JUnit project uses the Google Java Style (http://google-styleguide.googlecode.com/svn/trunk/javaguide.html) for all new
code (under org.junit.*). Legacy code (under junit.*) used the legacy guide specified in LEGACY_CODING_STYLE.txt in the
project root.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/main/java/org/junit/experimental/ParallelComputer.java
Expand Up @@ -12,13 +12,13 @@
import org.junit.runners.model.RunnerScheduler;

public class ParallelComputer extends Computer {
private final boolean fClasses;
private final boolean classes;

private final boolean fMethods;
private final boolean methods;

public ParallelComputer(boolean classes, boolean methods) {
fClasses = classes;
fMethods = methods;
this.classes = classes;
this.methods = methods;
}

public static Computer classes() {
Expand Down Expand Up @@ -55,13 +55,13 @@ public void finished() {
public Runner getSuite(RunnerBuilder builder, java.lang.Class<?>[] classes)
throws InitializationError {
Runner suite = super.getSuite(builder, classes);
return fClasses ? parallelize(suite) : suite;
return this.classes ? parallelize(suite) : suite;
}

@Override
protected Runner getRunner(RunnerBuilder builder, Class<?> testClass)
throws Throwable {
Runner runner = super.getRunner(builder, testClass);
return fMethods ? parallelize(runner) : runner;
return methods ? parallelize(runner) : runner;
}
}
40 changes: 20 additions & 20 deletions src/main/java/org/junit/experimental/categories/Categories.java
Expand Up @@ -115,10 +115,10 @@ public class Categories extends Suite {
}

public static class CategoryFilter extends Filter {
private final Set<Class<?>> fIncluded;
private final Set<Class<?>> fExcluded;
private final boolean fIncludedAny;
private final boolean fExcludedAny;
private final Set<Class<?>> included;
private final Set<Class<?>> excluded;
private final boolean includedAny;
private final boolean excludedAny;

public static CategoryFilter include(boolean matchAny, Class<?>... categories) {
if (hasNull(categories)) {
Expand Down Expand Up @@ -157,10 +157,10 @@ public static CategoryFilter categoryFilter(boolean matchAnyInclusions, Set<Clas

protected CategoryFilter(boolean matchAnyIncludes, Set<Class<?>> includes,
boolean matchAnyExcludes, Set<Class<?>> excludes) {
fIncludedAny= matchAnyIncludes;
fExcludedAny= matchAnyExcludes;
fIncluded= copyAndRefine(includes);
fExcluded= copyAndRefine(excludes);
includedAny = matchAnyIncludes;
excludedAny = matchAnyExcludes;
included = copyAndRefine(includes);
excluded = copyAndRefine(excludes);
}

/**
Expand All @@ -186,9 +186,9 @@ public String describe() {
*/
@Override public String toString() {
StringBuilder description= new StringBuilder("categories ")
.append(fIncluded.isEmpty() ? "[all]" : fIncluded);
if (!fExcluded.isEmpty()) {
description.append(" - ").append(fExcluded);
.append(included.isEmpty() ? "[all]" : included);
if (!excluded.isEmpty()) {
description.append(" - ").append(excluded);
}
return description.toString();
}
Expand All @@ -213,29 +213,29 @@ private boolean hasCorrectCategoryAnnotation(Description description) {

// If a child has no categories, immediately return.
if (childCategories.isEmpty()) {
return fIncluded.isEmpty();
return included.isEmpty();
}

if (!fExcluded.isEmpty()) {
if (fExcludedAny) {
if (matchesAnyParentCategories(childCategories, fExcluded)) {
if (!excluded.isEmpty()) {
if (excludedAny) {
if (matchesAnyParentCategories(childCategories, excluded)) {
return false;
}
} else {
if (matchesAllParentCategories(childCategories, fExcluded)) {
if (matchesAllParentCategories(childCategories, excluded)) {
return false;
}
}
}

if (fIncluded.isEmpty()) {
if (included.isEmpty()) {
// Couldn't be excluded, and with no suite's included categories treated as should run.
return true;
} else {
if (fIncludedAny) {
return matchesAnyParentCategories(childCategories, fIncluded);
if (includedAny) {
return matchesAnyParentCategories(childCategories, included);
} else {
return matchesAllParentCategories(childCategories, fIncluded);
return matchesAllParentCategories(childCategories, included);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/junit/experimental/max/MaxCore.java
Expand Up @@ -49,10 +49,10 @@ public static MaxCore storedLocally(File storedResults) {
return new MaxCore(storedResults);
}

private final MaxHistory fHistory;
private final MaxHistory history;

private MaxCore(File storedResults) {
fHistory = MaxHistory.forFolder(storedResults);
history = MaxHistory.forFolder(storedResults);
}

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ public Result run(Request request) {
* @return a {@link Result} describing the details of the test run and the failed tests.
*/
public Result run(Request request, JUnitCore core) {
core.addListener(fHistory.listener());
core.addListener(history.listener());
return core.run(sortRequest(request).getRunner());
}

Expand All @@ -98,7 +98,7 @@ public Request sortRequest(Request request) {
return request;
}
List<Description> leaves = findLeaves(request);
Collections.sort(leaves, fHistory.testComparator());
Collections.sort(leaves, history.testComparator());
return constructLeafRequest(leaves);
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/junit/experimental/max/MaxHistory.java
Expand Up @@ -61,41 +61,41 @@ private static MaxHistory readHistory(File storedResults)
}
}

private final Map<String, Long> fDurations = new HashMap<String, Long>();
private final Map<String, Long> durations = new HashMap<String, Long>();

private final Map<String, Long> fFailureTimestamps = new HashMap<String, Long>();
private final Map<String, Long> failureTimestamps = new HashMap<String, Long>();

private final File fHistoryStore;
private final File historyStore;

private MaxHistory(File storedResults) {
fHistoryStore = storedResults;
historyStore = storedResults;
}

private void save() throws IOException {
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(
fHistoryStore));
historyStore));
stream.writeObject(this);
stream.close();
}

Long getFailureTimestamp(Description key) {
return fFailureTimestamps.get(key.toString());
return failureTimestamps.get(key.toString());
}

void putTestFailureTimestamp(Description key, long end) {
fFailureTimestamps.put(key.toString(), end);
failureTimestamps.put(key.toString(), end);
}

boolean isNewTest(Description key) {
return !fDurations.containsKey(key.toString());
return !durations.containsKey(key.toString());
}

Long getTestDuration(Description key) {
return fDurations.get(key.toString());
return durations.get(key.toString());
}

void putTestDuration(Description description, long duration) {
fDurations.put(description.toString(), duration);
durations.put(description.toString(), duration);
}

private final class RememberingListener extends RunListener {
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/junit/experimental/theories/Theories.java
Expand Up @@ -118,27 +118,27 @@ public Statement methodBlock(final FrameworkMethod method) {
public static class TheoryAnchor extends Statement {
private int successes = 0;

private FrameworkMethod fTestMethod;
private TestClass fTestClass;
private final FrameworkMethod testMethod;
private final TestClass testClass;

private List<AssumptionViolatedException> fInvalidParameters = new ArrayList<AssumptionViolatedException>();

public TheoryAnchor(FrameworkMethod method, TestClass testClass) {
fTestMethod = method;
fTestClass = testClass;
public TheoryAnchor(FrameworkMethod testMethod, TestClass testClass) {
this.testMethod = testMethod;
this.testClass = testClass;
}

private TestClass getTestClass() {
return fTestClass;
return testClass;
}

@Override
public void evaluate() throws Throwable {
runWithAssignment(Assignments.allUnassigned(
fTestMethod.getMethod(), getTestClass()));
testMethod.getMethod(), getTestClass()));

//if this test method is not annotated with Theory, then no successes is a valid case
boolean hasTheoryAnnotation = fTestMethod.getAnnotation(Theory.class) != null;
boolean hasTheoryAnnotation = testMethod.getAnnotation(Theory.class) != null;
if (successes == 0 && hasTheoryAnnotation) {
Assert
.fail("Never found parameters that satisfied method assumptions. Violated assumptions: "
Expand Down Expand Up @@ -207,7 +207,7 @@ public Object createTest() throws Exception {

return getTestClass().getOnlyConstructor().newInstance(params);
}
}.methodBlock(fTestMethod).evaluate();
}.methodBlock(testMethod).evaluate();
}

private Statement methodCompletesWithParameters(
Expand Down Expand Up @@ -235,12 +235,12 @@ protected void reportParameterizedError(Throwable e, Object... params)
if (params.length == 0) {
throw e;
}
throw new ParameterizedAssertionError(e, fTestMethod.getName(),
throw new ParameterizedAssertionError(e, testMethod.getName(),
params);
}

private boolean nullsOk() {
Theory annotation = fTestMethod.getMethod().getAnnotation(
Theory annotation = testMethod.getMethod().getAnnotation(
Theory.class);
if (annotation == null) {
return false;
Expand Down
Expand Up @@ -22,24 +22,24 @@
*/
public class AllMembersSupplier extends ParameterSupplier {
static class MethodParameterValue extends PotentialAssignment {
private final FrameworkMethod fMethod;
private final FrameworkMethod method;

private MethodParameterValue(FrameworkMethod dataPointMethod) {
fMethod = dataPointMethod;
method = dataPointMethod;
}

@Override
public Object getValue() throws CouldNotGenerateValueException {
try {
return fMethod.invokeExplosively(null);
return method.invokeExplosively(null);
} catch (IllegalArgumentException e) {
throw new RuntimeException(
"unexpected: argument length is checked");
} catch (IllegalAccessException e) {
throw new RuntimeException(
"unexpected: getMethods returned an inaccessible method");
} catch (Throwable throwable) {
DataPoint annotation = fMethod.getAnnotation(DataPoint.class);
DataPoint annotation = method.getAnnotation(DataPoint.class);
Assume.assumeTrue(annotation == null || !isAssignableToAnyOf(annotation.ignoredExceptions(), throwable));

throw new CouldNotGenerateValueException(throwable);
Expand All @@ -48,17 +48,17 @@ public Object getValue() throws CouldNotGenerateValueException {

@Override
public String getDescription() throws CouldNotGenerateValueException {
return fMethod.getName();
return method.getName();
}
}

private final TestClass fClass;
private final TestClass clazz;

/**
* Constructs a new supplier for {@code type}
*/
public AllMembersSupplier(TestClass type) {
fClass = type;
clazz = type;
}

@Override
Expand Down Expand Up @@ -172,11 +172,11 @@ private static boolean isAssignableToAnyOf(Class<?>[] typeArray, Object target)
}

protected Collection<FrameworkMethod> getDataPointsMethods(ParameterSignature sig) {
return fClass.getAnnotatedMethods(DataPoints.class);
return clazz.getAnnotatedMethods(DataPoints.class);
}

protected Collection<Field> getSingleDataPointFields(ParameterSignature sig) {
List<FrameworkField> fields = fClass.getAnnotatedFields(DataPoint.class);
List<FrameworkField> fields = clazz.getAnnotatedFields(DataPoint.class);
Collection<Field> validFields = new ArrayList<Field>();

for (FrameworkField frameworkField : fields) {
Expand All @@ -187,7 +187,7 @@ protected Collection<Field> getSingleDataPointFields(ParameterSignature sig) {
}

protected Collection<Field> getDataPointsFields(ParameterSignature sig) {
List<FrameworkField> fields = fClass.getAnnotatedFields(DataPoints.class);
List<FrameworkField> fields = clazz.getAnnotatedFields(DataPoints.class);
Collection<Field> validFields = new ArrayList<Field>();

for (FrameworkField frameworkField : fields) {
Expand All @@ -198,7 +198,7 @@ protected Collection<Field> getDataPointsFields(ParameterSignature sig) {
}

protected Collection<FrameworkMethod> getSingleDataPointMethods(ParameterSignature sig) {
return fClass.getAnnotatedMethods(DataPoint.class);
return clazz.getAnnotatedMethods(DataPoint.class);
}

}

3 comments on commit df00d5e

@nhuray
Copy link

@nhuray nhuray commented on df00d5e Jul 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Junit Team,

I tried to run a snapshot of the future version 4.12 on IntelliJ and I encountered an issue related to this commit :

Internal Error occured.
java.lang.NoSuchFieldException: fTestClass
    at java.lang.Class.getDeclaredField(Class.java:1938)
    at com.intellij.junit4.JUnit4IdeaTestRunner.getSuiteMethodDescription(JUnit4IdeaTestRunner.java:128)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:45)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)

It seems the IntelliJ junit plugin tried to load some fields of the class ClassRequest resolving them by name, as you can see here : http://grepcode.com/file/repository.grepcode.com/java/ext/com.jetbrains/intellij-idea/13.0.0/com/intellij/junit4/JUnit4IdeaTestRunner.java/

I think, it's the responsability of the IntelliJ team to change his implementation not using these private fields, but I'd like opening a discussion about that with the Junit team too.

I opened a bug on IntelliJ side : http://youtrack.jetbrains.com/issue/IDEA-127349

@marcphilipp
Copy link
Member

@marcphilipp marcphilipp commented on df00d5e Jul 15, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nhuray
Copy link

@nhuray nhuray commented on df00d5e Jul 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

Please sign in to comment.