0

I'm using Google Guava 21.x and AssertJ 3.8 to run a test, but it's complaining below:

[junit] Testcase: testModule took 7.062 sec
    [junit]     Caused an ERROR
    [junit] com.google.common.base.Objects.toStringHelper(Ljava/lang/Class;)Lcom/google/common/base/Objects$ToStringHelper;
    [junit] java.lang.NoSuchMethodError: com.google.common.base.Objects.toStringHelper(Ljava/lang/Class;)Lcom/google/common/base/Objects$ToStringHelper;
    [junit]     at com.google.inject.internal.FactoryProxy.toString(FactoryProxy.java:63)
    [junit]     at com.google.inject.internal.InjectorImpl$2.toString(InjectorImpl.java:1030)
    [junit]     at org.assertj.core.presentation.StandardRepresentation.toStringOf(StandardRepresentation.java:170)
    [junit]     at org.assertj.core.presentation.StandardRepresentation.format(StandardRepresentation.java:436)
    [junit]     at org.assertj.core.presentation.StandardRepresentation.singleLineFormat(StandardRepresentation.java:450)
    [junit]     at org.assertj.core.presentation.StandardRepresentation.smartFormat(StandardRepresentation.java:464)
    [junit]     at org.assertj.core.presentation.StandardRepresentation.toStringOf(StandardRepresentation.java:166)
    [junit]     at org.assertj.core.error.MessageFormatter.asText(MessageFormatter.java:77)
    [junit]     at org.assertj.core.error.MessageFormatter.format(MessageFormatter.java:68)
    [junit]     at org.assertj.core.error.MessageFormatter.format(MessageFormatter.java:61)
    [junit]     at org.assertj.core.error.BasicErrorMessageFactory.create(BasicErrorMessageFactory.java:110)
    [junit]     at org.assertj.core.internal.Failures.failure(Failures.java:116)
    [junit]     at org.assertj.core.internal.CommonValidations.checkSizes(CommonValidations.java:119)
    [junit]     at org.assertj.core.internal.Iterables.assertHasSize(Iterables.java:185)
    [junit]     at org.assertj.core.api.AbstractIterableAssert.hasSize(AbstractIterableAssert.java:170)
    [junit]     at com.fishercoder.worker.WorkersModuleTest.testModule(WorkersModuleTest.java:31)
    [junit]
    [junit] Test com.fishercoder.worker.WorkersModuleTest FAILED

I did some research and found this method is scheduled to be deprecated: https://guava.dev/releases/20.0/api/docs/deprecated-list.html but this is all dependency code calling Google Guava, any insight on how this can be fixed would be greatly appreciated?

Fisher Coder
  • 3,278
  • 12
  • 49
  • 84
  • If this method is missing in Guava 21, and a dependency needs it, you need to downgrade the Guava version to a supported version (20 might work). – dunni Oct 08 '19 at 17:17
  • Thanks @dunni but I just tried Guava 20, the same error occurs again. – Fisher Coder Oct 08 '19 at 17:26
  • What's the output of `mvn dependency:tree`? – dunni Oct 08 '19 at 17:26
  • I'm not using maven, but our internal build system, cannot post it here, any other info you'd like to know to help solve this? – Fisher Coder Oct 08 '19 at 17:33
  • Ah ok. Can you make sure that you have indeed Guava 20 on the classpath? Maven sometimes would still override it with newer versions, maybe your own buildsystem does it as well? – dunni Oct 08 '19 at 17:34
  • I see, but I don't think downgrade Guava to 20 would be a fix, since many of our other code/tests need Guava 21, any other way to fix this issue? Thanks – Fisher Coder Oct 08 '19 at 17:36
  • No. Either the dependencies have already released a new version which works with Guava 21 (so you would upgrade the dependencies), or you need to remove features in your code/tests, that need Guava 21. – dunni Oct 08 '19 at 17:38
  • Keep your dependencies up to date. Guava 21 is nearly 3 years old and we're at 28.1 now... If some open source library is the latest but very old, copy it internally and update the packages locally. You're shooting yourself in the foot by using such old versions – Olivier Grégoire Oct 08 '19 at 21:21

0 Answers0