Open TWiStErRob opened 6 years ago
Here's an IntelliJ IDEA structural search inspection to find instances
(in inspectionProfiles/Project_Default.xml
):
<inspection_tool class="SSBasedInspection" enabled="true" level="WARNING" enabled_by_default="true">
<replaceConfiguration name="JFixture: Invalid usage of sameInstance, use useSubType instead" text="$o$.sameInstance($x$, $y$)" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="false" shortenFQN="false" replacement="$o$.useSubType($x$, $y$)">
<constraint name="o" nameOfExprType="com.flextrade.jfixture.FluentCustomisation" exprTypeWithinHierarchy="true" formalTypeWithinHierarchy="true" within="" contains="" />
<constraint name="x" nameOfFormalType="java.lang.Class" negateName="true" negateFormalType="true" wholeWordsOnly="true" within="" contains="" />
<constraint name="y" nameOfExprType="java.lang.Class" within="" contains="" />
</replaceConfiguration>
The following typo leads to false positive tests. Meaning the set-up completes successfully and this may never be discovered depending on accesses to the list. Here's a test case that should be added to JFixture's test suite:
Asking for a
List<X>
I get aList<Class>
. Since JFixture found X.class in the registry, it could very simply check that thesameInstance
that we passed in is indeed an instance of X (or null) and not something else. This validation could be even done at the timesameInstance
is called.Note:
sameInstance
has generic protection (<T>
andClass<T>
), but it's not applied here:sameInstance(X.class, Y.class)
calls the(Type, T)
overload.Disclaimer: I know you're not maintaining this repo, just wanted to record this bug/enhancement.