Skip to content

Commit

Permalink
Run code cleanup for consistency
Browse files Browse the repository at this point in the history
Eclipse settings saved to config/spectrum.cleanup.xml
  • Loading branch information
greghaskins committed Jul 21, 2016
1 parent 22566f3 commit b343b6b
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 46 deletions.
61 changes: 61 additions & 0 deletions config/spectrum.cleanup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="2">
<profile kind="CleanUpProfile" name="spectrum clean-up" version="2">
<setting id="cleanup.qualify_static_method_accesses_with_declaring_class" value="false"/>
<setting id="cleanup.always_use_this_for_non_static_method_access" value="false"/>
<setting id="cleanup.organize_imports" value="true"/>
<setting id="cleanup.remove_trailing_whitespaces_ignore_empty" value="false"/>
<setting id="cleanup.format_source_code_changes_only" value="false"/>
<setting id="cleanup.qualify_static_field_accesses_with_declaring_class" value="false"/>
<setting id="cleanup.add_generated_serial_version_id" value="false"/>
<setting id="cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class" value="true"/>
<setting id="cleanup.remove_redundant_type_arguments" value="false"/>
<setting id="cleanup.remove_unused_imports" value="true"/>
<setting id="cleanup.insert_inferred_type_arguments" value="false"/>
<setting id="cleanup.make_private_fields_final" value="true"/>
<setting id="cleanup.use_lambda" value="true"/>
<setting id="cleanup.always_use_blocks" value="true"/>
<setting id="cleanup.use_this_for_non_static_field_access_only_if_necessary" value="false"/>
<setting id="cleanup.sort_members_all" value="false"/>
<setting id="cleanup.remove_trailing_whitespaces_all" value="true"/>
<setting id="cleanup.add_missing_annotations" value="true"/>
<setting id="cleanup.always_use_this_for_non_static_field_access" value="true"/>
<setting id="cleanup.make_parameters_final" value="true"/>
<setting id="cleanup.sort_members" value="false"/>
<setting id="cleanup.remove_private_constructors" value="true"/>
<setting id="cleanup.always_use_parentheses_in_expressions" value="false"/>
<setting id="cleanup.remove_unused_local_variables" value="false"/>
<setting id="cleanup.convert_to_enhanced_for_loop" value="false"/>
<setting id="cleanup.remove_unused_private_fields" value="true"/>
<setting id="cleanup.never_use_blocks" value="false"/>
<setting id="cleanup.add_missing_deprecated_annotations" value="true"/>
<setting id="cleanup.use_this_for_non_static_field_access" value="true"/>
<setting id="cleanup.remove_unnecessary_nls_tags" value="true"/>
<setting id="cleanup.qualify_static_member_accesses_through_instances_with_declaring_class" value="true"/>
<setting id="cleanup.add_missing_nls_tags" value="false"/>
<setting id="cleanup.remove_unnecessary_casts" value="true"/>
<setting id="cleanup.use_blocks_only_for_return_and_throw" value="false"/>
<setting id="cleanup.format_source_code" value="true"/>
<setting id="cleanup.convert_functional_interfaces" value="false"/>
<setting id="cleanup.add_default_serial_version_id" value="true"/>
<setting id="cleanup.remove_unused_private_methods" value="true"/>
<setting id="cleanup.remove_trailing_whitespaces" value="true"/>
<setting id="cleanup.make_type_abstract_if_missing_method" value="false"/>
<setting id="cleanup.add_serial_version_id" value="false"/>
<setting id="cleanup.use_this_for_non_static_method_access" value="true"/>
<setting id="cleanup.use_this_for_non_static_method_access_only_if_necessary" value="true"/>
<setting id="cleanup.use_anonymous_class_creation" value="false"/>
<setting id="cleanup.add_missing_override_annotations_interface_methods" value="true"/>
<setting id="cleanup.remove_unused_private_members" value="false"/>
<setting id="cleanup.make_local_variable_final" value="true"/>
<setting id="cleanup.add_missing_methods" value="false"/>
<setting id="cleanup.never_use_parentheses_in_expressions" value="true"/>
<setting id="cleanup.qualify_static_member_accesses_with_declaring_class" value="true"/>
<setting id="cleanup.use_parentheses_in_expressions" value="false"/>
<setting id="cleanup.add_missing_override_annotations" value="true"/>
<setting id="cleanup.use_blocks" value="true"/>
<setting id="cleanup.make_variable_declarations_final" value="true"/>
<setting id="cleanup.correct_indentation" value="true"/>
<setting id="cleanup.remove_unused_private_types" value="true"/>
</profile>
</profiles>
2 changes: 1 addition & 1 deletion src/main/java/com/greghaskins/spectrum/Parent.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Parent {

Parent NONE = new Parent() {
@Override
public void focus(Child child) {}
public void focus(final Child child) {}

@Override
public boolean isIgnored() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/greghaskins/spectrum/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public void focus() {

@Override
public void ignore() {
ignored = true;
this.ignored = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class WhenDescribingTheSpec {

@Before
public void before() throws Exception {
description = new Spectrum(Fixture.getSpecThatRequiresAConstructorParameter()).getDescription();
this.description =
new Spectrum(Fixture.getSpecThatRequiresAConstructorParameter()).getDescription();
}

@Test
Expand All @@ -40,7 +41,7 @@ private Description getDescriptionForError() {
}

private Description getDescriptionForExplodingContext() {
return description;
return this.description;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ public class WhenRunningTheSpec {

@Before
public void before() throws Exception {
result = SpectrumRunner.run(Fixture.getSpecThatRequiresAConstructorParameter());
this.result = SpectrumRunner.run(Fixture.getSpecThatRequiresAConstructorParameter());
}

@Test
public void thereIsOneFailure() throws Exception {
assertThat(result.getFailureCount(), is(1));
assertThat(this.result.getFailureCount(), is(1));
}

@Test
public void theFailureExplainsWhatHappened() throws Exception {
assertThat(result.getFailures().get(0),
assertThat(this.result.getFailures().get(0),
is(failure("encountered an error", UnableToConstructSpecException.class,
Fixture.getSpecThatRequiresAConstructorParameter().getName())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class WhenDescribingTheSpec {

@Before
public void before() throws Exception {
description =
this.description =
new Spectrum(Fixture.getSpecThatThrowsAnExceptionInConstructor()).getDescription();
}

Expand All @@ -41,7 +41,7 @@ private Description getDescriptionForError() {
}

private Description getDescriptionForExplodingContext() {
return description;
return this.description;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public class WhenRunningTheSpec {

@Before
public void before() throws Exception {
result = SpectrumRunner.run(Fixture.getSpecThatThrowsAnExceptionInConstructor());
this.result = SpectrumRunner.run(Fixture.getSpecThatThrowsAnExceptionInConstructor());
}

@Test
public void thereIsOneFailure() throws Exception {
assertThat(result.getFailureCount(), is(1));
assertThat(this.result.getFailureCount(), is(1));
}

@Test
public void theFailureExplainsWhatHappened() throws Exception {
assertThat(result.getFailures().get(0),
assertThat(this.result.getFailures().get(0),
is(failure("encountered an error", Fixture.SomeException.class, "kaboom")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class WhenDescribingTheSpec {

@Before
public void before() throws Exception {
description =
this.description =
new Spectrum(Fixture.getSpecThatThrowsAnExceptionInDescribeBlock()).getDescription();
}

Expand All @@ -40,7 +40,7 @@ private Description getDescriptionForError() {
}

private Description getDescriptionForExplodingContext() {
return description.getChildren().get(0);
return this.description.getChildren().get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public class WhenRunningTheSpec {

@Before
public void before() throws Exception {
result = SpectrumRunner.run(Fixture.getSpecThatThrowsAnExceptionInDescribeBlock());
this.result = SpectrumRunner.run(Fixture.getSpecThatThrowsAnExceptionInDescribeBlock());
}

@Test
public void thereIsOneFailure() throws Exception {
assertThat(result.getFailureCount(), is(1));
assertThat(this.result.getFailureCount(), is(1));
}

@Test
public void theFailureExplainsWhatHappened() throws Exception {
assertThat(result.getFailures().get(0),
assertThat(this.result.getFailures().get(0),
is(failure("encountered an error", Fixture.SomeException.class, "kaboom")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ public class WhenDescribingTheSpec {
public void before() throws Exception {
final Description rootDescription =
new Spectrum(getSpecWithNestedDescribeBlocks()).getDescription();
mainDescription = rootDescription.getChildren().get(0);
this.mainDescription = rootDescription.getChildren().get(0);
}

@Test
public void theMainDescriptionHasTwoContextsAsChildren() throws Exception {
assertThat(mainDescription.getChildren(),
assertThat(this.mainDescription.getChildren(),
contains(Description.createSuiteDescription("with a first child context"),
Description.createSuiteDescription("with a second child context")));
}

@Test
public void theFirstSubContextHasThreeTests() throws Exception {
assertThat(mainDescription.getChildren().get(0).getChildren(), hasSize(3));
assertThat(this.mainDescription.getChildren().get(0).getChildren(), hasSize(3));
}

@Test
public void theSecondSubContextHasOneTest() throws Exception {
assertThat(mainDescription.getChildren().get(1).getChildren(), hasSize(1));
assertThat(this.mainDescription.getChildren().get(1).getChildren(), hasSize(1));
}

private static Class<?> getSpecWithNestedDescribeBlocks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ public class WhenDescribingTheSpec {

@Before
public void before() throws Exception {
description = new Spectrum(Fixture.getSpecWithOnePassingTest()).getDescription();
this.description = new Spectrum(Fixture.getSpecWithOnePassingTest()).getDescription();
}

@Test
public void theRootSuiteIsTheTestClass() throws Exception {
assertThat(description.getDisplayName(), is(Fixture.getSpecWithOnePassingTest().getName()));
assertThat(this.description.getDisplayName(),
is(Fixture.getSpecWithOnePassingTest().getName()));
}

@Test
public void thereIsOneChildSuite() throws Exception {
assertThat(description.getChildren(), hasSize(1));
assertThat(this.description.getChildren(), hasSize(1));
}

@Test
Expand All @@ -45,7 +46,7 @@ public void theTestNameIsCorrect() throws Exception {
}

private Description getFirstChildSuite() {
return description.getChildren().get(0);
return this.description.getChildren().get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public class WhenRunningTheSpec {

@Before
public void before() throws Exception {
result = SpectrumRunner.run(Fixture.getSpecWithOnePassingTest());
this.result = SpectrumRunner.run(Fixture.getSpecWithOnePassingTest());
}

@Test
public void theRunCountIsOne() throws Exception {
assertThat(result.getRunCount(), is(1));
assertThat(this.result.getRunCount(), is(1));
}

@Test
public void theRunIsSuccessful() throws Exception {
assertThat(result.wasSuccessful(), is(true));
assertThat(this.result.wasSuccessful(), is(true));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WhenDescribingTheSpec {

@Before
public void before() throws Exception {
description = new Spectrum(Fixture.getSpecWithPassingAndFailingTests()).getDescription();
this.description = new Spectrum(Fixture.getSpecWithPassingAndFailingTests()).getDescription();
}

@Test
Expand All @@ -45,7 +45,7 @@ public void theTestsAreInDeclarationOrder() throws Exception {
}

private Description getFirstContext() {
return description.getChildren().get(0);
return this.description.getChildren().get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public class WhenRunningTheSpec {

@Before
public void before() throws Exception {
result = SpectrumRunner.run(Fixture.getSpecWithPassingAndFailingTests());
this.result = SpectrumRunner.run(Fixture.getSpecWithPassingAndFailingTests());
}

@Test
public void fiveTestsAreRun() throws Exception {
assertThat(result.getRunCount(), is(5));
assertThat(this.result.getRunCount(), is(5));
}

@Test
public void twoTestsFail() throws Exception {
assertThat(result.getFailureCount(), is(2));
assertThat(this.result.getFailureCount(), is(2));
}

@Test
public void theFailuresDescribeWhatWentWrong() throws Exception {
final List<Failure> failures = result.getFailures();
final List<Failure> failures = this.result.getFailures();
assertThat(failures.get(0),
is(failure("fails test 1", AssertionError.class, "failure message one")));
assertThat(failures.get(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.runner.Runner;
import org.junit.runner.notification.RunNotifier;
import org.mockito.InOrder;
import org.mockito.Matchers;
import org.mockito.Mockito;

public class WhenRunningTheTests {
Expand All @@ -21,30 +22,30 @@ public class WhenRunningTheTests {
@Before
public void before() throws Exception {
final Runner runner = new Spectrum(Fixture.getSpecWithPassingAndFailingTests());
runNotifier = mock(RunNotifier.class);
this.runNotifier = mock(RunNotifier.class);

runner.run(runNotifier);
runner.run(this.runNotifier);
}

@Test
public void theStartFailureAndFinishedNotificationsAreFiredForFailingTests() throws Exception {
final Description descriptionOfFailingTest =
Description.createTestDescription(CONTEXT_NAME, "fails test 1");

final InOrder inOrder = Mockito.inOrder(runNotifier);
inOrder.verify(runNotifier).fireTestStarted(descriptionOfFailingTest);
inOrder.verify(runNotifier).fireTestFailure(Mockito.any());
inOrder.verify(runNotifier).fireTestFinished(descriptionOfFailingTest);
final InOrder inOrder = Mockito.inOrder(this.runNotifier);
inOrder.verify(this.runNotifier).fireTestStarted(descriptionOfFailingTest);
inOrder.verify(this.runNotifier).fireTestFailure(Matchers.any());
inOrder.verify(this.runNotifier).fireTestFinished(descriptionOfFailingTest);
}

@Test
public void theStartAndFinishedNotificationsAreFiredForPassingTests() throws Exception {
final Description descriptionOfPassingTest =
Description.createTestDescription(CONTEXT_NAME, "passes test 3");

final InOrder inOrder = Mockito.inOrder(runNotifier);
inOrder.verify(runNotifier).fireTestStarted(descriptionOfPassingTest);
inOrder.verify(runNotifier).fireTestFinished(descriptionOfPassingTest);
final InOrder inOrder = Mockito.inOrder(this.runNotifier);
inOrder.verify(this.runNotifier).fireTestStarted(descriptionOfPassingTest);
inOrder.verify(this.runNotifier).fireTestFinished(descriptionOfPassingTest);
}

}
7 changes: 4 additions & 3 deletions src/test/java/matchers/IsFailure.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ protected boolean matchesSafely(final Failure item, final Description mismatchDe

describeTo(mismatchDescription, actualMethodName, actualExceptionType, actualMessage);

return methodName.equals(actualMethodName) && exceptionType.equals(actualExceptionType)
&& failureMessage.equals(actualMessage);
return this.methodName.equals(actualMethodName)
&& this.exceptionType.equals(actualExceptionType)
&& this.failureMessage.equals(actualMessage);
}

private String getMethodName(final Failure failure) {
Expand All @@ -50,7 +51,7 @@ private String getMethodName(final Failure failure) {

@Override
public void describeTo(final Description description) {
describeTo(description, methodName, exceptionType, failureMessage);
describeTo(description, this.methodName, this.exceptionType, this.failureMessage);
}

private void describeTo(final Description description, final String methodName,
Expand Down

0 comments on commit b343b6b

Please sign in to comment.