Conversation
Generate changelog in
|
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview💡 Improvements
|
db2e753 to
5cdd197
Compare
5cdd197 to
f3c898a
Compare
|
|
||
| @Test | ||
| public void testSanity() { | ||
| ErrorType actualType = ErrorType.FAILED_PRECONDITION; |
There was a problem hiding this comment.
Replicating the test cases in
There was a problem hiding this comment.
Wondering whether we could simply have a main testing class that tests the abstract base class, once we do the changes I proposed to share more of the actual implementation and methods?
| abstract class AbstractServiceExceptionAssert<T extends AbstractThrowableAssert<T, U>, U extends Throwable> | ||
| extends AbstractThrowableAssert<T, U> { | ||
|
|
||
| protected AbstractServiceExceptionAssert(U throwable, Class<T> selfType) { | ||
| super(throwable, selfType); | ||
| } | ||
|
|
||
| void hasCode(ErrorType.Code code, ErrorType.Code actualCode) { | ||
| isNotNull(); | ||
| failIfNotEqual("Expected ErrorType.Code to be %s, but found %s", code, actualCode); | ||
| } |
There was a problem hiding this comment.
Instead of defining methods that take the actual value and redefining methods in the implementation, could you just do this instead?
| abstract class AbstractServiceExceptionAssert<T extends AbstractThrowableAssert<T, U>, U extends Throwable> | |
| extends AbstractThrowableAssert<T, U> { | |
| protected AbstractServiceExceptionAssert(U throwable, Class<T> selfType) { | |
| super(throwable, selfType); | |
| } | |
| void hasCode(ErrorType.Code code, ErrorType.Code actualCode) { | |
| isNotNull(); | |
| failIfNotEqual("Expected ErrorType.Code to be %s, but found %s", code, actualCode); | |
| } | |
| abstract class AbstractServiceExceptionAssert<T extends AbstractThrowableAssert<T, U>, U extends Throwable> | |
| extends AbstractThrowableAssert<T, U> { | |
| protected AbstractServiceExceptionAssert(U throwable, Class<T> selfType) { | |
| super(throwable, selfType); | |
| } | |
| protected abstract ErrorType actualErrorType(); | |
| public final void hasCode(ErrorType.Code code) { | |
| isNotNull(); | |
| failIfNotEqual("Expected ErrorType.Code to be %s, but found %s", code, actualErrorType().code(); | |
| } |
?
I realize that EndpointServiceException and ServiceException unfortunately don't implement any shared interface (which they probably should to be honest?), but we should still be able to share most of the implementation and thereby also guarantee that they have the exact same methods, without having to redefine them in the concrete implementation either
| import org.assertj.core.api.AbstractThrowableAssert; | ||
| import org.assertj.core.util.Throwables; | ||
|
|
||
| abstract class AbstractServiceExceptionAssert<T extends AbstractThrowableAssert<T, U>, U extends Throwable> |
There was a problem hiding this comment.
| abstract class AbstractServiceExceptionAssert<T extends AbstractThrowableAssert<T, U>, U extends Throwable> | |
| abstract class AbstractServiceExceptionAssert<T extends AbstractServiceExceptionAssert<T, U>, U extends Throwable> |
|
|
||
| @Test | ||
| public void testSanity() { | ||
| ErrorType actualType = ErrorType.FAILED_PRECONDITION; |
There was a problem hiding this comment.
Wondering whether we could simply have a main testing class that tests the abstract base class, once we do the changes I proposed to share more of the actual implementation and methods?
Before this PR
We have test utilities for asserting properties of
ServiceExceptionbut do not have any utilities forEndpointServiceException.After this PR
==COMMIT_MSG==
Add
EndpointServiceExceptionAssert==COMMIT_MSG==
Possible downsides?