question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Print the fully qualified class names if the simple class names are the same

See original GitHub issue

I have 2 overloads of a method:

  • setDeadline(java.time.Duration)
  • setDeadline(org.joda.time.Duration)

There’s a mocking failure in a test (calling the wrong overload), but the error message isn’t super helpful:

1) myMethod(com.google.frobber.MyClassTest)
Argument(s) are different! Wanted:
myClass.setDeadline(
    (Duration) PT1S
);
-> at com.google.frobber.MyClassTest.myMethod(MyClassTest.java:287)
Actual invocation has different arguments:
myClass.setDeadline(
    (Duration) PT1S
);

The output attempts to include the classnames to help disambiguate, but in this case, the simple class names are identical (Duration). We should be able to detect this, and print the FQCNs if the simple names are equal.

Alternatively, we could always print the FQCNs:

https://github.com/mockito/mockito/blob/6f9108b833323345bd926f10914224d3e0a11b80/src/main/java/org/mockito/internal/matchers/Equals.java#L55

(We already do something similar in Truth.)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
saurabh7248commented, Jun 9, 2021

@chaehwanli’s changes would have printed the full name even when the classes would have different simple names. I have added a list of indexes in PrintSettings which would do this only for arguments having same simple names.

1reaction
TimvdLippecommented, Jun 8, 2021

@chaehwanli Looking at https://github.com/chaehwanli/mockito/commit/2175bfb43e75d80976d75ab0338aaf751cdee9eb I think that would be the correct fix for this. Do you mind sending that as a PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Find classes with same full qualified name in Java during ...
I think each (fully qualified) class name can refer to only one class in the JRE; see for example this question.
Read more >
Chapter 6. Names - Oracle Help Center
A qualified name N.x may be used to refer to a member of a package or reference type, where N is a simple...
Read more >
Get the fully-qualified name of a class in Java - Tutorialspoint
The fully-qualified class name can be obtained using the getName() method. A program that demonstrates this is given as follows −. Example.
Read more >
Retrieving a Class Name in Java - Baeldung
Explore different ways to retrieve a class name in Java. ... In Java, there are two kinds of names: simple and qualified. A...
Read more >
get_class - Manual - PHP
::class fully qualified class name, instead of get_class <?php namespace my\library\mvc; class Dispatcher {} print Dispatcher::class; // FQN ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found