diff options
author | Jens Nyman <jnyman@google.com> | 2024-01-16 09:53:24 +0000 |
---|---|---|
committer | Jens Nyman <jnyman@google.com> | 2024-01-16 09:54:03 +0000 |
commit | 9dd42b625d73ebcc7dd751349fe70c44902f6f0f (patch) | |
tree | 69fe73eb9cc33260c628ac661a7db3496bcab65c | |
parent | 468611d306e5f4a55aec5971fee39197410316cd (diff) | |
download | TestParameterInjector-9dd42b625d73ebcc7dd751349fe70c44902f6f0f.tar.gz |
TestParameterAnnotationMethodProcessor.AnnotationWithMetadata: Stop supporting equals() and hashCode().
This is a preparation for adding a new field to this class, which itself is an implementation change for adding a context-aware value provider for @TestParameter.
https://github.com/google/TestParameterInjector/issues/44
2 files changed, 24 insertions, 0 deletions
diff --git a/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameterAnnotationMethodProcessor.java b/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameterAnnotationMethodProcessor.java index 4a9b163..79ba92b 100644 --- a/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameterAnnotationMethodProcessor.java +++ b/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameterAnnotationMethodProcessor.java @@ -274,6 +274,18 @@ final class TestParameterAnnotationMethodProcessor implements TestMethodProcesso return new AutoValue_TestParameterAnnotationMethodProcessor_AnnotationWithMetadata( annotation, Optional.absent(), Optional.absent()); } + + // Prevent anyone relying on equals() and hashCode() so that it remains possible to add fields + // to this class without breaking existing code. + @Override + public final boolean equals(Object other) { + throw new UnsupportedOperationException("Equality is not supported"); + } + + @Override + public final int hashCode() { + throw new UnsupportedOperationException("hashCode() is not supported"); + } } private final boolean onlyForFieldsAndParameters; diff --git a/junit5/src/main/java/com/google/testing/junit/testparameterinjector/junit5/TestParameterAnnotationMethodProcessor.java b/junit5/src/main/java/com/google/testing/junit/testparameterinjector/junit5/TestParameterAnnotationMethodProcessor.java index cb5ceec..23462ac 100644 --- a/junit5/src/main/java/com/google/testing/junit/testparameterinjector/junit5/TestParameterAnnotationMethodProcessor.java +++ b/junit5/src/main/java/com/google/testing/junit/testparameterinjector/junit5/TestParameterAnnotationMethodProcessor.java @@ -274,6 +274,18 @@ final class TestParameterAnnotationMethodProcessor implements TestMethodProcesso return new AutoValue_TestParameterAnnotationMethodProcessor_AnnotationWithMetadata( annotation, Optional.absent(), Optional.absent()); } + + // Prevent anyone relying on equals() and hashCode() so that it remains possible to add fields + // to this class without breaking existing code. + @Override + public final boolean equals(Object other) { + throw new UnsupportedOperationException("Equality is not supported"); + } + + @Override + public final int hashCode() { + throw new UnsupportedOperationException("hashCode() is not supported"); + } } private final boolean onlyForFieldsAndParameters; |