JavaHamcrest | Java version of Hamcrest
kandi X-RAY | JavaHamcrest Summary
kandi X-RAY | JavaHamcrest Summary
Hamcrest is a library of matchers, which can be combined in to create flexible expressions of intent in tests. They’ve also been used for other purposes.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Appends the given value to the output
- Appends an Iterator to the description
- Appends the given character to the Java syntax
- Validates that a string matches a regular expression
- Creates a matcher that matches the specified regular expression
- Validates a regular expression against a regular expression
- Creates a matcher that matches the specified regular expression
- Creates a Matcher that matches the specified property at the specified path
- Compile an XPath expression
- Find the expected type for the given class
- Returns true if the collection matches the provided matcher
- Determines whether an object matches a mismatch
- Matches the actual value of the feature to match
- Checks if the item matches the given item
- Returns the number of elements of the given iterable
- Simplified step with read method
- Returns true if the array matches the elements in the given array
- Checks if the given item matches the mismatch
- Returns true if the substring matches a given substring
- Add values to the description
- Called to describe a mismatch
- Attempts to match the expected class
- Step that evaluates to an XPath node
JavaHamcrest Key Features
JavaHamcrest Examples and Code Snippets
Community Discussions
Trending Discussions on JavaHamcrest
QUESTION
I'm new to Java, learning Hamcrest framework.
I've read the code of the Matcher interface, and I don't understand the comment and the method signature of matches(Object actual)
. I expected it to be matches(T actual)
, and use the generic type T
instead of Object
which accept everything.
This is the source code: https://github.com/hamcrest/JavaHamcrest/blob/master/hamcrest/src/main/java/org/hamcrest/Matcher.java
for the matches
method:
ANSWER
Answered 2020-Feb-12 at 09:54You're right, you'd expect T
at first instead of Object
, but knowing that Generics are a compile time feature and not available during runtime (when the tests runs and needs the matcher) (see Type Erasure) it makes sense to highlight the fact that technically it could be something that's not T thus forcing you to check to create clearer error messages in that case.
Type Erasure (paraphrased from Oracle):
Type erasure makes sure that there are no additional classes generated for different generics. It
- replaces all generic types by their boundary or Object.
- introduces automatic casts
- creates adapter methods to preserve polymorphism.
So that ther will be no runtime overhead.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install JavaHamcrest
You can use JavaHamcrest like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the JavaHamcrest component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page