Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2530: Add spotless check for formatting preferences #2533

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .github/workflows/spotless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Spotless

on:
push:
branches:
- main
pull_request:

jobs:
spotless-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 11
cache: 'maven'
- name: Spotless check
run: mvn spotless:check
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Thank you for your interest in contributing to AssertJ!
We appreciate your effort and to make sure that your pull request is easy to review, we ask you to note the following guidelines including legal contributor agreement:

* Use JDK 11 or newer to build the project
* Use **[AssertJ code Eclipse formatting preferences](src/ide-support/assertj-eclipse-formatter.xml)** (for IntelliJ IDEA users, you can import it with the 'Eclipse Code Formatter' Plugin)
* Use **[AssertJ code Eclipse formatting preferences](src/ide-support/assertj-eclipse-formatter.xml)** (for IntelliJ IDEA users, you can import it with the 'Eclipse Code Formatter' Plugin).
You can also run `mvn spotless:apply` (to apply the formatting preferences) or `mvn spotless:check` (to check that your contribution adheres to them).
* Write complete Javadocs for each assertion method and include a code example (succeeding and failing assertion(s)).
* As we use JUnit 5, favor `package-private` visibility for both test classes and test methods.
* Write one JUnit test class for each assertion method with the following naming convention: `<AssertClass>_<assertion>_Test`.
Expand Down
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,23 @@
<failWhenNoMutations>false</failWhenNoMutations>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<java>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
</includes>

<eclipse>
<file>${project.basedir}/src/ide-support/assertj-eclipse-formatter.xml</file>
</eclipse>
</java>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ private ObjectAssert<RESULT> internalSucceedsWithin(Duration timeout) {
protected ObjectAssert<RESULT> newObjectAssert(RESULT objectUnderTest) {
return new ObjectAssert<>(objectUnderTest);
}

/**
* Waits if necessary for at most the given time for this future to complete, and then returns its result for further assertions.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import java.util.regex.Matcher;
import org.assertj.core.internal.Failures;


/**
* Assertions for {@link java.util.regex.Matcher}
*
* @author Jiashu Zhang
*/
public abstract class AbstractMatcherAssert<SELF extends AbstractMatcherAssert<SELF>> extends
AbstractAssert<SELF, Matcher> {
AbstractAssert<SELF, Matcher> {

protected AbstractMatcherAssert(Matcher actual, Class<?> selfType) {
super(actual, selfType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ public SELF isEqualTo(String dateTimeAsString) {
return isEqualTo(parse(dateTimeAsString));
}


/**
* Verifies that the actual {@code OffsetDateTime} is not equal to the given value according to the comparator in use.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public SELF isPresent() {
public SELF isNotPresent() {
return isEmpty();
}

/**
* Verifies that the actual {@link java.util.OptionalDouble} is empty.
* <p>
Expand Down Expand Up @@ -203,7 +203,8 @@ public SELF hasValueCloseTo(Double expectedValue, Percentage percentage) {
try {
doubles.assertIsCloseToPercentage(info, actual.getAsDouble(), expectedValue, percentage);
} catch (AssertionError assertionError) {
throwAssertionError(shouldHaveValueCloseToPercentage(actual, expectedValue, percentage, abs(expectedValue - actual.getAsDouble())));
throwAssertionError(shouldHaveValueCloseToPercentage(actual, expectedValue, percentage,
abs(expectedValue - actual.getAsDouble())));
}
return myself;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public SELF isPresent() {
public SELF isNotPresent() {
return isEmpty();
}

/**
* Verifies that the actual {@link java.util.OptionalInt} is empty.
* <p>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/assertj/core/api/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public static <T> PredicateAssert<T> assertThat(Predicate<T> actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}


/**
* Create assertion for {@link Predicate}.
* <p>
Expand Down Expand Up @@ -1567,7 +1566,8 @@ public static IOException catchIOException(ThrowingCallable shouldRaiseIOExcepti
* @since 3.22.0
*/
public static ReflectiveOperationException catchReflectiveOperationException(ThrowingCallable shouldRaiseReflectiveOperationException) {
return AssertionsForClassTypes.catchThrowableOfType(shouldRaiseReflectiveOperationException, ReflectiveOperationException.class);
return AssertionsForClassTypes.catchThrowableOfType(shouldRaiseReflectiveOperationException,
ReflectiveOperationException.class);
}

/**
Expand Down Expand Up @@ -1709,7 +1709,7 @@ public static ThrowableTypeAssert<IllegalStateException> assertThatIllegalStateE
*
* @since 3.23.0
*/
public static ThrowableTypeAssert<Exception> assertThatException(){
public static ThrowableTypeAssert<Exception> assertThatException() {
return assertThatExceptionOfType(Exception.class);
}

Expand All @@ -1720,7 +1720,7 @@ public static ThrowableTypeAssert<Exception> assertThatException(){
*
* @since 3.23.0
*/
public static ThrowableTypeAssert<RuntimeException> assertThatRuntimeException(){
public static ThrowableTypeAssert<RuntimeException> assertThatRuntimeException() {
return assertThatExceptionOfType(RuntimeException.class);
}

Expand All @@ -1731,7 +1731,7 @@ public static ThrowableTypeAssert<RuntimeException> assertThatRuntimeException()
*
* @since 3.23.0
*/
public static ThrowableTypeAssert<ReflectiveOperationException> assertThatReflectiveOperationException(){
public static ThrowableTypeAssert<ReflectiveOperationException> assertThatReflectiveOperationException() {
return assertThatExceptionOfType(ReflectiveOperationException.class);
}

Expand All @@ -1742,7 +1742,7 @@ public static ThrowableTypeAssert<ReflectiveOperationException> assertThatReflec
*
* @since 3.23.0
*/
public static ThrowableTypeAssert<IndexOutOfBoundsException> assertThatIndexOutOfBoundsException(){
public static ThrowableTypeAssert<IndexOutOfBoundsException> assertThatIndexOutOfBoundsException() {
return assertThatExceptionOfType(IndexOutOfBoundsException.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static RuntimeException assumptionNotMet(AssertionError assertionError) throws R
Class<?> assumptionExceptionClass = preferredAssumptionException.getAssumptionExceptionClass();
return buildAssumptionException(assumptionExceptionClass, assertionError);
}

@VisibleForTesting
public static PreferredAssumptionException getPreferredAssumptionException() {
return preferredAssumptionException;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/assertj/core/api/AtomicBooleanAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public AtomicBooleanAssert usingComparator(Comparator<? super AtomicBoolean> cus
*/
@Override
@Deprecated
public AtomicBooleanAssert usingComparator(Comparator<? super AtomicBoolean> customComparator, String customComparatorDescription) {
public AtomicBooleanAssert usingComparator(Comparator<? super AtomicBoolean> customComparator,
String customComparatorDescription) {
throw new UnsupportedOperationException("custom Comparator is not supported for AtomicBoolean comparison");
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/assertj/core/api/AtomicIntegerAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ public AtomicIntegerAssert usingComparator(Comparator<? super AtomicInteger> cus

@Override
@CheckReturnValue
public AtomicIntegerAssert usingComparator(Comparator<? super AtomicInteger> customComparator, String customComparatorDescription) {
public AtomicIntegerAssert usingComparator(Comparator<? super AtomicInteger> customComparator,
String customComparatorDescription) {
integers = new Integers(new ComparatorBasedComparisonStrategy(customComparator, customComparatorDescription));
return super.usingComparator(customComparator, customComparatorDescription);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.assertj.core.api;


import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
Expand All @@ -25,12 +24,13 @@
* @author epeee
* @since 2.7.0 / 3.7.0
*/
public class AtomicIntegerFieldUpdaterAssert<OBJECT> extends AbstractAtomicFieldUpdaterAssert<AtomicIntegerFieldUpdaterAssert<OBJECT>, Integer, AtomicIntegerFieldUpdater<OBJECT>, OBJECT> {
public class AtomicIntegerFieldUpdaterAssert<OBJECT> extends
AbstractAtomicFieldUpdaterAssert<AtomicIntegerFieldUpdaterAssert<OBJECT>, Integer, AtomicIntegerFieldUpdater<OBJECT>, OBJECT> {

public AtomicIntegerFieldUpdaterAssert(AtomicIntegerFieldUpdater<OBJECT> actual) {
super(actual, AtomicIntegerFieldUpdaterAssert.class, false);
}

/**
* Verifies that the actual atomic field updater contains the given value at the given object.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.assertj.core.api;


import java.util.concurrent.atomic.AtomicLongFieldUpdater;

/**
Expand All @@ -25,7 +24,8 @@
* @author epeee
* @since 2.7.0 / 3.7.0
*/
public class AtomicLongFieldUpdaterAssert<OBJECT> extends AbstractAtomicFieldUpdaterAssert<AtomicLongFieldUpdaterAssert<OBJECT>, Long, AtomicLongFieldUpdater<OBJECT>, OBJECT> {
public class AtomicLongFieldUpdaterAssert<OBJECT>
extends AbstractAtomicFieldUpdaterAssert<AtomicLongFieldUpdaterAssert<OBJECT>, Long, AtomicLongFieldUpdater<OBJECT>, OBJECT> {

public AtomicLongFieldUpdaterAssert(AtomicLongFieldUpdater<OBJECT> actual) {
super(actual, AtomicLongFieldUpdaterAssert.class, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public AtomicMarkableReferenceAssert(AtomicMarkableReference<VALUE> actual) {
public AtomicMarkableReferenceAssert<VALUE> hasReference(VALUE expectedValue) {
return super.hasReference(expectedValue);
}

@Override
protected VALUE getReference() {
return actual.getReference();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,6 @@ public AtomicReferenceArrayAssert<T> hasExactlyElementsOfTypes(Class<?>... expec
return myself;
}


/**
* Verifies that the actual AtomicReferenceArray does not contain the given object at the given index.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.assertj.core.api;


import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
Expand All @@ -26,7 +25,8 @@
* @author epeee
* @since 2.7.0 / 3.7.0
*/
public class AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT> extends AbstractAtomicFieldUpdaterAssert<AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT>, FIELD, AtomicReferenceFieldUpdater<OBJECT, FIELD>, OBJECT> {
public class AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT> extends
AbstractAtomicFieldUpdaterAssert<AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT>, FIELD, AtomicReferenceFieldUpdater<OBJECT, FIELD>, OBJECT> {

public AtomicReferenceFieldUpdaterAssert(AtomicReferenceFieldUpdater<OBJECT, FIELD> actual) {
super(actual, AtomicReferenceFieldUpdaterAssert.class, true);
Expand Down Expand Up @@ -57,7 +57,7 @@ public AtomicReferenceFieldUpdaterAssert(AtomicReferenceFieldUpdater<OBJECT, FIE
public AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT> hasValue(FIELD expectedValue, OBJECT obj) {
return super.hasValue(expectedValue, obj);
}

@Override
protected FIELD getActualValue(OBJECT obj) {
return actual.get(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.assertj.core.api;


import static org.assertj.core.error.ShouldHaveStamp.shouldHaveStamp;

import java.util.concurrent.atomic.AtomicStampedReference;
Expand All @@ -26,7 +25,8 @@
* @author epeee
* @since 2.7.0 / 3.7.0
*/
public class AtomicStampedReferenceAssert<VALUE> extends AbstractAtomicReferenceAssert<AtomicStampedReferenceAssert<VALUE>, VALUE, AtomicStampedReference<VALUE>> {
public class AtomicStampedReferenceAssert<VALUE>
extends AbstractAtomicReferenceAssert<AtomicStampedReferenceAssert<VALUE>, VALUE, AtomicStampedReference<VALUE>> {

public AtomicStampedReferenceAssert(AtomicStampedReference<VALUE> actual) {
super(actual, AtomicStampedReferenceAssert.class);
Expand All @@ -52,7 +52,7 @@ public AtomicStampedReferenceAssert(AtomicStampedReference<VALUE> actual) {
public AtomicStampedReferenceAssert<VALUE> hasReference(VALUE expectedValue) {
return super.hasReference(expectedValue);
}

@Override
protected VALUE getReference() {
return actual.getReference();
Expand All @@ -72,7 +72,7 @@ protected VALUE getReference() {
* @return this assertion object.
* @since 2.7.0 / 3.7.0
*/
public AtomicStampedReferenceAssert<VALUE> hasStamp(int expectedStamp){
public AtomicStampedReferenceAssert<VALUE> hasStamp(int expectedStamp) {
int timestamp = actual.getStamp();
if (timestamp != expectedStamp) throwAssertionError(shouldHaveStamp(actual, expectedStamp));
return this;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/assertj/core/api/BDDAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,8 @@ public static IOException catchIOException(ThrowingCallable shouldRaiseIOExcepti
* @since 3.22.0
*/
public static ReflectiveOperationException catchReflectiveOperationException(ThrowingCallable shouldRaiseReflectiveOperationException) {
return AssertionsForClassTypes.catchThrowableOfType(shouldRaiseReflectiveOperationException, ReflectiveOperationException.class);
return AssertionsForClassTypes.catchThrowableOfType(shouldRaiseReflectiveOperationException,
ReflectiveOperationException.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ default MatcherAssert then(Matcher actual) {
return proxy(MatcherAssert.class, Matcher.class, actual);
}


/**
* Creates a new instance of <code>{@link LocalDateAssert}</code>.
*
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/assertj/core/api/BigDecimalAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.math.BigDecimal;


/**
* Assertion methods for {@link BigDecimal}s.
* <p>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/assertj/core/api/BooleanArrayAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.assertj.core.api;


/**
* Assertion methods for arrays of {@code boolean}s.
* <p>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/assertj/core/api/Byte2DArrayAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ public Byte2DArrayAssert hasNumberOfRows(int expected) {
return myself;
}


/**
* Verifies that the actual {@code byte[][]} has the same dimensions as the given array.
* <p>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/assertj/core/api/ByteArrayAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.assertj.core.api;


/**
* Assertion methods for arrays of {@code byte}s.
* <p>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/assertj/core/api/CharArrayAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.assertj.core.api;


/**
* Assertion methods for arrays of {@code char}s.
* <p>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/assertj/core/api/ClassAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public class ClassAssert extends AbstractClassAssert<ClassAssert> {
public ClassAssert(Class<?> actual) {
super(actual, ClassAssert.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ClassBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat

// @format:on


public ClassBasedNavigableIterableAssert(ACTUAL actual, Class<?> selfType, Class<ELEMENT_ASSERT> assertClass) {
super(actual, selfType);
this.assertClass = assertClass;
Expand Down