Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Import Guava's MoreAsserts in Eclipse

Tags:

guava

I recently added Google Guava as a library to my Eclipse project (I downloaded the 'guava-16.0.jar' from http://code.google.com/p/guava-libraries/ and added it as an external jar library to my Eclipse project).

Eclipse seems to be able to "see"/use the library (I have successfully made imports to packages like com.google.common.collect). Now I want to use the MoreAsserts class in some of my JUnit tests, but when I type in the import:

import com.google.common.testing.MoreAsserts;

Eclipse gives a red flag saying that "The import com.google.common.testing could not be resolved". It doesn't seem to see the package at all.

[EDIT: I think this might be because MoreAsserts is in Beta version (tagged as @Beta), and so I probably shouldn't use it anyway]

like image 968
user3229293 Avatar asked Jan 01 '26 09:01

user3229293


1 Answers

Contrary to some of the responses here, com.google.common.testing is available for public use. It's just that it's hidden away in a separate guava-testlib artifact at Maven Central.

That said, you won't find MoreAsserts there. It was removed a few years ago. (The source link you gave points to an old version of Guava. I'm kind of curious where you got the link.)

That said, the reason that MoreAsserts was deleted is that it has been replaced by a more comprehensive equals() and hashCode() tester: EqualsTester. EqualsTester is in the current version of guava-testlib.

It's true that the class is @Beta, but that's probably OK for tests. (And practically speaking, EqualsTester is unlikely to change significantly.)

APIs marked with the @Beta annotation at the class or method level are subject to change. They can be modified in any way, or even removed, in any major release. If your code is a library itself (i.e. it is used on the CLASSPATH of users outside your own control), you should not use beta APIs.

like image 133
Chris Povirk Avatar answered Jan 05 '26 21:01

Chris Povirk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!