hamcrest / JavaHamcrest

Java (and original) version of Hamcrest
http://hamcrest.org/
BSD 3-Clause "New" or "Revised" License
2.11k stars 379 forks source link

Add matchers for JDK 8 Optionals #82

Closed odrotbohm closed 3 months ago

odrotbohm commented 9 years ago

There's a Hamcrest-Extras library that has matchers for Guava's Optional. It would be cool to have the standard Hamcrest library provide these kinds of matchers for the pure JDK 8 Optionals as well.

devluencer-089 commented 9 years ago

+1

SiliconMeeple commented 9 years ago

:+1:

npryce commented 9 years ago

Yes, but not in core, because we support old versions of the Java language that is still used in embedded systems. Matchers for Java 8 classes will have to go in their own add-on library for now.

odrotbohm commented 9 years ago

You can have support for Java 8 types but keep compatibility with former version if you just use a JDK 8 to compile the code with e.g. 1.6 target. If the code using the newly introduced types is in dedicated classes, this doesn't cause any issues. Spring Framework makes heavy use of this technique.

reardonm commented 9 years ago

:+1:

npathai commented 9 years ago

I have some String related utilities that I have created for my personal use. I would love to contribute those. Have we decided the way we have to package those classes? Will it be an extra library for 1.8 as well?

npryce commented 9 years ago

I suggest publishing them as an extension library to start with.

On Wednesday, 1 July 2015, Narendra Pathai notifications@github.com wrote:

I have some String related utilities that I have created for my personal use. I would love to contribute those. Have we decided the way we have to package those classes? Will it be an extra library for 1.8 as well?

— Reply to this email directly or view it on GitHub https://github.com/hamcrest/JavaHamcrest/issues/82#issuecomment-117516673 .

npathai commented 9 years ago

@npryce @olivergierke I have an initial implementation at https://github.com/npathai/hamcrest-jdk8-extras Please go through it and provide some inputs. There are three methods: isPresent(), isEmpty() and isPresentAnd(Matcher). Out of which first two are obvious. The third one is useful for applying matchers on value inside the Optional instance.

scheffield commented 9 years ago

@npryce @npathai https://github.com/npathai/hamcrest-jdk8-extras looks good, despite the double execution of the matcher in isPresentAnd(Matcher). Is there a chance to get it into hamcrest soon?

npathai commented 9 years ago

@scheffield Great. I will get to it soon n remove double execution. I have been busy lately. I will change it this weekend.

npathai commented 9 years ago

@scheffield I have resolved the issue. I will further refine the implementation if I get some reviews.

npathai commented 9 years ago

Does anyone feel we need matchers for new DateTime API of Java8?

mateusz-lisik commented 9 years ago

@npathai I would rather see your extras merged into core project, but I think you should cover it, since you called your project "jdk8" :)

npathai commented 9 years ago

@matteprl Yes I would like that too. But I didn't get your point.

stefanbirkner commented 9 years ago

@npathai's hamcrest-jdk8-extras has been renamed to https://github.com/npathai/hamcrest-optional.

mateusz-lisik commented 9 years ago

@npathai @stefanbirkner Thank you for information. I know that library is single file project. But have you considered putting it into maven? I like to keep my dependencies managed, and some people - just like me sometimes use search tool on sites like mvnrepository.com and just type hamcrest jdk8. I think it would also make more people use your library. :)

npathai commented 9 years ago

@matteprl Yes we are already considering that. It will be available very soon. Thanks for your inputs.

cod3hulk commented 8 years ago

Any update about when this will make it into hamcrest project? I have seen that hamcrest-optional from @npathai was forked by @baev for maven release integration (https://github.com/baev/hamcrest-optional). But I would like to see an "official" hamcrest integration. From my point of view it makes totally sense to integrate the hamcrest-optional lib into hamcrest project.

npathai commented 8 years ago

@cod3hulk @matteprl @scheffield I have released hamcrest-optional to maven central

<dependency>
  <groupId>com.github.npathai</groupId>
  <artifactId>hamcrest-optional</artifactId>
  <version>1.0</version>
</dependency>
davidxia commented 7 years ago

Hi all. We at Spotify have open-sourced some matchers for Optionals here https://github.com/spotify/java-hamcrest. Hopefully you find these useful and maybe we can even get some of these into upstream.

Let us know if you have questions or ideas.

CC007 commented 3 years ago

We are now at java 15 going on 16 and Java 7 is now very much end-of-life. Isn't it time to include optionals into the standard java hamcrest library?

tumbarumba commented 3 months ago

Closing this issue, discussion can continue on #206