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

Format sources #15

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* in case of a test failure.
*/
module org.itsallcode.automatcher {
exports org.itsallcode.matcher.auto;
exports org.itsallcode.matcher.auto;

requires java.sql;
requires java.logging;
requires transitive org.hamcrest;
requires java.sql;
requires java.logging;
requires transitive org.hamcrest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@
*/
public abstract class BaseTypeSafeDiagnosingMatcher<T> extends TypeSafeDiagnosingMatcher<T> {

/**
* Create a new {@link BaseTypeSafeDiagnosingMatcher} with the expected value.
*
* @param expected the expected value.
*/
protected BaseTypeSafeDiagnosingMatcher(final T expected) {
}
/**
* Create a new {@link BaseTypeSafeDiagnosingMatcher} with the expected value.
*
* @param expected the expected value.
*/
protected BaseTypeSafeDiagnosingMatcher(final T expected) {
}

@Override
public final void describeTo(final Description description) {
final DescriptionBuilder builder = DescriptionBuilder.start(description);
describeTo(builder);
builder.close();
}
@Override
public final void describeTo(final Description description) {
final DescriptionBuilder builder = DescriptionBuilder.start(description);
describeTo(builder);
builder.close();
}

/**
* Describe the expected value using the {@link DescriptionBuilder}.
*
* @param description the {@link DescriptionBuilder}.
*/
protected abstract void describeTo(DescriptionBuilder description);
/**
* Describe the expected value using the {@link DescriptionBuilder}.
*
* @param description the {@link DescriptionBuilder}.
*/
protected abstract void describeTo(DescriptionBuilder description);

@Override
protected final boolean matchesSafely(final T actual, final Description mismatchDescription) {
final MismatchReporter mismatchReporter = MismatchReporter.start(mismatchDescription);
reportMismatches(actual, mismatchReporter);
return mismatchReporter.finishAndCheckMatching();
}
@Override
protected final boolean matchesSafely(final T actual, final Description mismatchDescription) {
final MismatchReporter mismatchReporter = MismatchReporter.start(mismatchDescription);
reportMismatches(actual, mismatchReporter);
return mismatchReporter.finishAndCheckMatching();
}

/**
* Report mismatches to the given {@link MismatchReporter}.
*
* @param actual the actual value to compare to the expected value.
* @param mismatchReporter the {@link MismatchReporter}.
*/
protected abstract void reportMismatches(T actual, MismatchReporter mismatchReporter);
/**
* Report mismatches to the given {@link MismatchReporter}.
*
* @param actual the actual value to compare to the expected value.
* @param mismatchReporter the {@link MismatchReporter}.
*/
protected abstract void reportMismatches(T actual, MismatchReporter mismatchReporter);
}
64 changes: 32 additions & 32 deletions src/main/java/org/itsallcode/matcher/DescriptionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@
* {@link org.hamcrest.TypeSafeDiagnosingMatcher#describeTo(Description)}.
*/
public final class DescriptionBuilder {
private final Description description;
private boolean firstElement = true;
private final Description description;
private boolean firstElement = true;

private DescriptionBuilder(final Description description) {
this.description = description;
}
private DescriptionBuilder(final Description description) {
this.description = description;
}

static DescriptionBuilder start(final Description description) {
description.appendText("{");
return new DescriptionBuilder(description);
}
static DescriptionBuilder start(final Description description) {
description.appendText("{");
return new DescriptionBuilder(description);
}

/**
* Append a message and a matcher to the description.
*
* @param message message to append
* @param matcher matcher to append
* @return {@code this} for method chaining
*/
public DescriptionBuilder append(final String message, final SelfDescribing matcher) {
appendComma();
this.description.appendText(message) //
.appendText("=") //
.appendDescriptionOf(matcher);
return this;
}
/**
* Append a message and a matcher to the description.
*
* @param message message to append
* @param matcher matcher to append
* @return {@code this} for method chaining
*/
public DescriptionBuilder append(final String message, final SelfDescribing matcher) {
appendComma();
this.description.appendText(message) //
.appendText("=") //
.appendDescriptionOf(matcher);
return this;
}

private void appendComma() {
if (!this.firstElement) {
this.description.appendText(", ");
}
this.firstElement = false;
}
private void appendComma() {
if (!this.firstElement) {
this.description.appendText(", ");
}
this.firstElement = false;
}

void close() {
this.description.appendText("}");
}
void close() {
this.description.appendText("}");
}
}
90 changes: 45 additions & 45 deletions src/main/java/org/itsallcode/matcher/MismatchReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,55 @@
* description of the mismatch.
*/
public class MismatchReporter {
private final Description mismatchDescription;
private boolean firstMismatch = true;
private boolean matches = true;
private final Description mismatchDescription;
private boolean firstMismatch = true;
private boolean matches = true;

private MismatchReporter(final Description mismatchDescription) {
this.mismatchDescription = mismatchDescription;
}
private MismatchReporter(final Description mismatchDescription) {
this.mismatchDescription = mismatchDescription;
}

static MismatchReporter start(final Description mismatchDescription) {
mismatchDescription.appendText("{");
return new MismatchReporter(mismatchDescription);
}
static MismatchReporter start(final Description mismatchDescription) {
mismatchDescription.appendText("{");
return new MismatchReporter(mismatchDescription);
}

boolean finishAndCheckMatching() {
this.mismatchDescription.appendText("}");
return this.matches;
}
boolean finishAndCheckMatching() {
this.mismatchDescription.appendText("}");
return this.matches;
}

/**
* Check if the actual object matches using the given {@link Matcher} and record
* a message if it does not match.
*
* @param message the message to output in case of a failed match
* @param matcher the {@link Matcher} used for checking the actual value
* @param actual the actual value that will be compared using the
* {@link Matcher}.
* @param <T> the type of the matcher.
* @return this {@link MismatchReporter} allowing a fluent programming style.
*/
public <T> MismatchReporter checkMismatch(final String message, final Matcher<T> matcher, final T actual) {
if (!matcher.matches(actual)) {
reportMismatch(message, matcher, actual);
this.matches = false;
}
return this;
}
/**
* Check if the actual object matches using the given {@link Matcher} and record
* a message if it does not match.
*
* @param message the message to output in case of a failed match
* @param matcher the {@link Matcher} used for checking the actual value
* @param actual the actual value that will be compared using the
* {@link Matcher}.
* @param <T> the type of the matcher.
* @return this {@link MismatchReporter} allowing a fluent programming style.
*/
public <T> MismatchReporter checkMismatch(final String message, final Matcher<T> matcher, final T actual) {
if (!matcher.matches(actual)) {
reportMismatch(message, matcher, actual);
this.matches = false;
}
return this;
}

private void reportMismatch(final String name, final Matcher<?> matcher, final Object actual) {
appendComma();
this.mismatchDescription //
.appendText(name) //
.appendText(" ");
matcher.describeMismatch(actual, this.mismatchDescription);
}
private void reportMismatch(final String name, final Matcher<?> matcher, final Object actual) {
appendComma();
this.mismatchDescription //
.appendText(name) //
.appendText(" ");
matcher.describeMismatch(actual, this.mismatchDescription);
}

private void appendComma() {
if (!this.firstMismatch) {
this.mismatchDescription.appendText(", ");
}
this.firstMismatch = false;
}
private void appendComma() {
if (!this.firstMismatch) {
this.mismatchDescription.appendText(", ");
}
this.firstMismatch = false;
}
}
Loading