Skip to content

Commit 7cd5c4e

Browse files
committed
Cleanup: reformat to 2 spaces
1 parent d928bdf commit 7cd5c4e

File tree

3 files changed

+107
-107
lines changed

3 files changed

+107
-107
lines changed

hamcrest/src/main/java/org/hamcrest/exception/ThrowsException.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,65 @@
1616
*/
1717
public class ThrowsException<T extends Runnable> extends TypeSafeMatcher<T> {
1818

19-
private final Matcher<? super Throwable> exceptionMatcher;
20-
private Throwable actualException;
19+
private final Matcher<? super Throwable> exceptionMatcher;
20+
private Throwable actualException;
2121

22-
/**
23-
* Constructor, best called from one of the static factory methods.
24-
*
25-
* @param elementMatcher matches the expected element
26-
*/
27-
public ThrowsException(Matcher<? super Throwable> elementMatcher) {
28-
this.exceptionMatcher = elementMatcher;
29-
}
22+
/**
23+
* Constructor, best called from one of the static factory methods.
24+
*
25+
* @param elementMatcher matches the expected element
26+
*/
27+
public ThrowsException(Matcher<? super Throwable> elementMatcher) {
28+
this.exceptionMatcher = elementMatcher;
29+
}
3030

31-
public static <U extends Runnable> ThrowsException<U> throwsException() {
32-
return new ThrowsException<>(instanceOf(Throwable.class));
33-
}
31+
public static <U extends Runnable> ThrowsException<U> throwsException() {
32+
return new ThrowsException<>(instanceOf(Throwable.class));
33+
}
3434

35-
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(V item) {
36-
return new ThrowsException<>(exceptionEqualTo(item));
37-
}
35+
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(V item) {
36+
return new ThrowsException<>(exceptionEqualTo(item));
37+
}
3838

39-
public static <U extends Runnable> ThrowsException<U> throwsException(Matcher<? super Throwable> exceptionMatcher) {
40-
return new ThrowsException<>(exceptionMatcher);
41-
}
39+
public static <U extends Runnable> ThrowsException<U> throwsException(Matcher<? super Throwable> exceptionMatcher) {
40+
return new ThrowsException<>(exceptionMatcher);
41+
}
4242

43-
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(Class<V> item) {
44-
return new ThrowsException<>(instanceOf(item));
45-
}
43+
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(Class<V> item) {
44+
return new ThrowsException<>(instanceOf(item));
45+
}
4646

47-
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(Class<V> item , String message) {
48-
return new ThrowsException<>(allOf(instanceOf(item), withMessage(message)));
49-
}
47+
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(Class<V> item, String message) {
48+
return new ThrowsException<>(allOf(instanceOf(item), withMessage(message)));
49+
}
5050

51-
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(Class<V> item , Matcher<? super Throwable> exceptionMatcher) {
52-
return new ThrowsException<>(allOf(instanceOf(item), exceptionMatcher));
53-
}
51+
public static <U extends Runnable, V extends Throwable> ThrowsException<U> throwsException(Class<V> item, Matcher<? super Throwable> exceptionMatcher) {
52+
return new ThrowsException<>(allOf(instanceOf(item), exceptionMatcher));
53+
}
5454

55-
@Override
56-
public boolean matchesSafely(T runnable) {
57-
try {
58-
runnable.run();
59-
return false;
60-
} catch (Throwable t) {
61-
actualException = t;
62-
return exceptionMatcher.matches(t);
63-
}
55+
@Override
56+
public boolean matchesSafely(T runnable) {
57+
try {
58+
runnable.run();
59+
return false;
60+
} catch (Throwable t) {
61+
actualException = t;
62+
return exceptionMatcher.matches(t);
6463
}
64+
}
6565

66-
@Override
67-
public void describeTo(Description description) {
68-
description.appendText("a runnable throwing ").appendDescriptionOf(exceptionMatcher);
69-
}
66+
@Override
67+
public void describeTo(Description description) {
68+
description.appendText("a runnable throwing ").appendDescriptionOf(exceptionMatcher);
69+
}
7070

71-
@Override
72-
public void describeMismatchSafely(T runnable, Description mismatchDescription) {
73-
if (actualException == null) {
74-
mismatchDescription.appendText("the runnable didn't throw");
75-
return;
76-
}
77-
mismatchDescription.appendText("the runnable threw ");
78-
exceptionMatcher.describeMismatch(actualException, mismatchDescription);
71+
@Override
72+
public void describeMismatchSafely(T runnable, Description mismatchDescription) {
73+
if (actualException == null) {
74+
mismatchDescription.appendText("the runnable didn't throw");
75+
return;
7976
}
77+
mismatchDescription.appendText("the runnable threw ");
78+
exceptionMatcher.describeMismatch(actualException, mismatchDescription);
79+
}
8080
}

hamcrest/src/main/java/org/hamcrest/exception/ThrowsExceptionEqualTo.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@
99
* @param <T> the type of the expected exception.
1010
*/
1111
public class ThrowsExceptionEqualTo<T extends Throwable> extends TypeSafeDiagnosingMatcher<T> {
12-
private final T expectedException;
12+
private final T expectedException;
1313

14-
/**
15-
* Constructor, best called from one of the static factory methods.
16-
*
17-
* @param expectedException the expected exception.
18-
*/
19-
public ThrowsExceptionEqualTo(T expectedException) {
20-
this.expectedException = expectedException;
21-
}
22-
23-
public static <U extends Throwable> ThrowsExceptionEqualTo<U> exceptionEqualTo(U expectedException) {
24-
return new ThrowsExceptionEqualTo<>(expectedException);
25-
}
14+
/**
15+
* Constructor, best called from one of the static factory methods.
16+
*
17+
* @param expectedException the expected exception.
18+
*/
19+
public ThrowsExceptionEqualTo(T expectedException) {
20+
this.expectedException = expectedException;
21+
}
2622

27-
@Override
28-
public boolean matchesSafely(T item, Description mismatchDescription) {
29-
if (!this.expectedException.getClass().isAssignableFrom(item.getClass())) {
30-
mismatchDescription.appendValue(item.getClass().getName()).appendText(" instead of a ").appendValue(this.expectedException.getClass().getName()).appendText(" exception");
31-
return false;
32-
}
33-
if (!item.getMessage().equals(this.expectedException.getMessage())) {
34-
mismatchDescription.appendValue(item.getClass().getName()).appendText(" with message ").appendValue(item.getMessage()).appendText(" instead of ").appendValue(this.expectedException.getMessage());
35-
return false;
36-
}
23+
public static <U extends Throwable> ThrowsExceptionEqualTo<U> exceptionEqualTo(U expectedException) {
24+
return new ThrowsExceptionEqualTo<>(expectedException);
25+
}
3726

38-
return true;
27+
@Override
28+
public boolean matchesSafely(T item, Description mismatchDescription) {
29+
if (!this.expectedException.getClass().isAssignableFrom(item.getClass())) {
30+
mismatchDescription.appendValue(item.getClass().getName()).appendText(" instead of a ").appendValue(this.expectedException.getClass().getName()).appendText(" exception");
31+
return false;
3932
}
40-
41-
@Override
42-
public void describeTo(Description description) {
43-
description.appendValue(expectedException.getClass().getName()).appendText(" with message ").appendValue(expectedException.getMessage());
33+
if (!item.getMessage().equals(this.expectedException.getMessage())) {
34+
mismatchDescription.appendValue(item.getClass().getName()).appendText(" with message ").appendValue(item.getMessage()).appendText(" instead of ").appendValue(this.expectedException.getMessage());
35+
return false;
4436
}
37+
38+
return true;
39+
}
40+
41+
@Override
42+
public void describeTo(Description description) {
43+
description.appendValue(expectedException.getClass().getName()).appendText(" with message ").appendValue(expectedException.getMessage());
44+
}
4545
}

hamcrest/src/main/java/org/hamcrest/exception/ThrowsExceptionWithMessage.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,37 @@
1212
* @param <T> the type of the expected exception.
1313
*/
1414
public class ThrowsExceptionWithMessage<T extends Throwable> extends TypeSafeDiagnosingMatcher<T> {
15-
private final Matcher<? super String> messageMatcher;
16-
17-
/**
18-
* Constructor, best called from one of the static factory methods.
19-
*
20-
* @param messageMatcher matches the exception message
21-
*/
22-
public ThrowsExceptionWithMessage(Matcher<? super String> messageMatcher) {
23-
this.messageMatcher = messageMatcher;
15+
private final Matcher<? super String> messageMatcher;
16+
17+
/**
18+
* Constructor, best called from one of the static factory methods.
19+
*
20+
* @param messageMatcher matches the exception message
21+
*/
22+
public ThrowsExceptionWithMessage(Matcher<? super String> messageMatcher) {
23+
this.messageMatcher = messageMatcher;
24+
}
25+
26+
public static <U extends Throwable, V extends String> ThrowsExceptionWithMessage<U> withMessage(V message) {
27+
return new ThrowsExceptionWithMessage<>(equalTo(message));
28+
}
29+
30+
public static <U extends Throwable> ThrowsExceptionWithMessage<U> withMessage(Matcher<? super String> messageMatcher) {
31+
return new ThrowsExceptionWithMessage<>(messageMatcher);
32+
}
33+
34+
@Override
35+
protected boolean matchesSafely(T item, Description mismatchDescription) {
36+
if (!this.messageMatcher.matches(item.getMessage())) {
37+
mismatchDescription.appendText("an exception with message ").appendValue(item.getMessage()).appendText(" instead of ").appendDescriptionOf(messageMatcher);
38+
return false;
2439
}
2540

26-
public static <U extends Throwable, V extends String> ThrowsExceptionWithMessage<U> withMessage(V message) {
27-
return new ThrowsExceptionWithMessage<>(equalTo(message));
28-
}
29-
30-
public static <U extends Throwable> ThrowsExceptionWithMessage<U> withMessage(Matcher<? super String> messageMatcher) {
31-
return new ThrowsExceptionWithMessage<>(messageMatcher);
32-
}
33-
34-
@Override
35-
protected boolean matchesSafely(T item, Description mismatchDescription) {
36-
if (!this.messageMatcher.matches(item.getMessage())) {
37-
mismatchDescription.appendText("an exception with message ").appendValue(item.getMessage()).appendText(" instead of ").appendDescriptionOf(messageMatcher);
38-
return false;
39-
}
41+
return true;
42+
}
4043

41-
return true;
42-
}
43-
44-
@Override
45-
public void describeTo(Description description) {
46-
description.appendText("an exception with message ").appendDescriptionOf(messageMatcher);
47-
}
44+
@Override
45+
public void describeTo(Description description) {
46+
description.appendText("an exception with message ").appendDescriptionOf(messageMatcher);
47+
}
4848
}

0 commit comments

Comments
 (0)