-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing the IllegalStateException types and updating the assertions …
…to use the built in expected/actual fields for better tool support
- Loading branch information
1 parent
9bebfdc
commit 9298046
Showing
15 changed files
with
335 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/redfin/insist/AbortedFailedValidationExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright: (c) 2016 Redfin | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.redfin.insist; | ||
|
||
import com.redfin.validity.ValidityUtils; | ||
import org.opentest4j.TestAbortedException; | ||
|
||
/** | ||
* Concrete subclass of the {@link AbstractStackTrimmingFailedValidationExecutor} that | ||
* throws {@link TestAbortedException} exceptions upon failure. | ||
*/ | ||
public final class AbortedFailedValidationExecutor | ||
extends AbstractStackTrimmingFailedValidationExecutor<TestAbortedException> { | ||
|
||
@Override | ||
protected String getDefaultMessage() { | ||
return "Test aborted"; | ||
} | ||
|
||
@Override | ||
protected <T> TestAbortedException buildThrowable(String expected, | ||
T actual, | ||
String message) { | ||
if (null == expected) { | ||
throw new NullPointerException(ValidityUtils.nullArgumentMessage("expected")); | ||
} | ||
return new TestAbortedException(String.format("%s\n expected : %s\n actual : <%s>", | ||
message, | ||
expected, | ||
ValidityUtils.describe(actual))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/redfin/insist/AssertionFailedValidationExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright: (c) 2016 Redfin | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.redfin.insist; | ||
|
||
import com.redfin.validity.ValidityUtils; | ||
import org.opentest4j.AssertionFailedError; | ||
|
||
/** | ||
* Concrete subclass of the {@link AbstractStackTrimmingFailedValidationExecutor} that | ||
* throws {@link AssertionFailedError} errors upon failure. | ||
*/ | ||
public final class AssertionFailedValidationExecutor | ||
extends AbstractStackTrimmingFailedValidationExecutor<AssertionFailedError> { | ||
|
||
@Override | ||
protected String getDefaultMessage() { | ||
return "Assertion failure"; | ||
} | ||
|
||
@Override | ||
protected <T> AssertionFailedError buildThrowable(String expected, | ||
T actual, | ||
String message) { | ||
if (null == expected) { | ||
throw new NullPointerException(ValidityUtils.nullArgumentMessage("expected")); | ||
} | ||
return new AssertionFailedError(message, | ||
expected, | ||
actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/java/com/redfin/insist/AbortedFailedValidationExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright: (c) 2016 Redfin | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.redfin.insist; | ||
|
||
import com.redfin.validity.FailedValidationExecutor; | ||
import org.opentest4j.TestAbortedException; | ||
|
||
final class AbortedFailedValidationExecutorTest | ||
implements StackTrimmingFailedValidationExecutorContract<TestAbortedException, AbortedFailedValidationExecutor> { | ||
|
||
@Override | ||
public AbortedFailedValidationExecutor getStackTrimmingFailedValidationExecutor() { | ||
return new AbortedFailedValidationExecutor(); | ||
} | ||
|
||
@Override | ||
public FailedValidationExecutor<TestAbortedException> getFailedValidationExecutor() { | ||
return getStackTrimmingFailedValidationExecutor(); | ||
} | ||
|
||
@Override | ||
public Class<TestAbortedException> getThrowableClass() { | ||
return TestAbortedException.class; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/com/redfin/insist/AbstractStackTrimmingFailedValidationExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright: (c) 2016 Redfin | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.redfin.insist; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
final class AbstractStackTrimmingFailedValidationExecutorTest { | ||
|
||
private static class MockImplementation | ||
extends AbstractStackTrimmingFailedValidationExecutor<IllegalArgumentException> { | ||
|
||
@Override | ||
protected String getDefaultMessage() { | ||
return "hello"; | ||
} | ||
|
||
@Override | ||
protected <T> IllegalArgumentException buildThrowable(String expected, | ||
T actual, | ||
String message) { | ||
return null; | ||
} | ||
} | ||
|
||
@Test | ||
void testFailThrowsForNullThrowableReturnedbySubclass() { | ||
Assertions.assertThrows(NullPointerException.class, | ||
() -> new MockImplementation().fail("t -> t.equals(\"hello\")", "world", () -> "default message"), | ||
"AbstractStackTrimmingFailedValidationExecutor should throw an exception if buildThrowable returns a null throwable."); | ||
} | ||
} |
Oops, something went wrong.