guava icon indicating copy to clipboard operation
guava copied to clipboard

SortedMapTestSuiteBuilder ignores CollectionSize.ZERO / CollectionSize.ONE

Open cdman opened this issue 9 years ago • 3 comments

Even if CollectionSize.ZERO is specified, SortedMapTestSuiteBuilder calls create(Object... elements) with elements having a length different from zero during initialization phase (ie. not during test running phase) - thus preventing all tests from being run.

The same is true for the case where CollectionSize.ONE is specified (in which case we would expect elements.length == 1 - but again, this is not the case).

See here for some unittests reproducing it: https://gist.github.com/cdman/ff2a7953fa5c4d08649e

A quick glance seems to indicate that this is done to initialize some helper collections, in which case perhaps they can use TreeMap (or other SortedMap implementations) instead of calling create which can have size restrictions.

cdman avatar Jan 23 '16 19:01 cdman

Hi Team! Is it still important to fix? Is it a good fix for beginner to work on?

MykolaBova avatar Feb 18 '21 12:02 MykolaBova

This is another thing that is probably not critical, but bugs are always bad. I haven't looked at SortedMapTestSuiteBuilder in a long time, so I don't have a feel for how hard it is. If we're lucky, we might just be able to make SortedMapTestSuiteBuilder.createDerivedSuites skip the submap testers unless the map supports CollectionSize.SEVERAL. However, I'm not entirely sure that that information is directly available to SortedMapTestSuiteBuilder. In fact, I suspect that it is removed by some of the collection-size-specific infrastructure in PerCollectionSizeTestSuiteBuilder and friends. And even if we can pass it through from there, I worry that some of our unusual setup (like our GWT tests that wrap the generated suites) might not understand the result.

It occurs to me that we may encounter this problem in our own tests, such as in TestsForMapsInJavaUtil.testsForEmptyNavigableMap(). There, it looks like we just ignore the given elements entirely. That's not a very principled workaround, but apparently it works.

After that quick look, my guess is that this won't be worth digging into. But it's hard to even make a good guess without, well, digging into it :)

cpovirk avatar Feb 18 '21 14:02 cpovirk

I have been recently using this library extensively and I can actually explain this. This is caused by SortedMapTestSuiteBuilder.createDerivedSuites, but also MapTestSuiteBuilder.createDerivedSuites. Either creating submaps or to test if the KeySet is also a SortedKeySet to ensure that implementations support what is requested. But only if the Map is also a SortedMap.

While this could be identified as a Bug, I Personally think if you are using a "SortedMapTestSuiteBuilder" you should be supporting EmptyMaps too.

Funny thing is EnumMaps kinda have that problem too where they don't support Empty Keys/Values on creation either.

But this should be in the documentation at the very least.

Speiger avatar Jun 10 '22 02:06 Speiger