Closed adonev42 closed 1 year ago
@adonev42 Note that this commit breaks our linting rules. There's a method with more than 30 lines of code: - visit/1[nl.tudelft.cse1110.andy.codechecker.checks.MethodInvocation] in class nl.tudelft.cse1110.andy.codechecker.checks.MockitoWhen has a total lines of code of 31
.
Hi, @mauricioaniche I fixed the things that you pointed out as comments. I will now mark this PR as active and if there is any need for adjustments, please text me, so I can implement them.
@adonev42 Thank you for your contribution!
It seems like this still fails our linting rules: - visit/1[nl.tudelft.cse1110.andy.codechecker.checks.MethodInvocation] in class nl.tudelft.cse1110.andy.codechecker.checks.MockitoWhen has a total lines of code of 27
@martinmladenov We should put this method in the exception list. It crosses the limit because of the comments which are not ignored by codesheriff I guess. Maybe best is to put a real linter here instead of my toy project!
@adonev42 can you add this class as an exception? See the CodeSheriffTests
, and add the MockitoWhen
class as an exception there! And we merge it right away, on time for this to be available to the exam! :)
Hello @mauricioaniche, The method should be added as an exception
With the normal syntax, if we encounter a match in method name, it will be right after when(...). Example: when(mockedList.add("2")).thenReturn(true). The order in which they will be processed is thenReturn(...) -> when(...) -> add(...)
With the other syntax we can encounter a match either before when or after "when" invocation Example:
doNothing().when(mockedList).desiredMethod()
. The order will bedesiredMethod()
->when(...)
->doNothing()
Alternatively, we can also write doReturn(true).when(mockedList.add("1")) the order will be
when(...)
->doReturn(...)
->add(...)
So we check if we encounter match on the current command or on the previousWe only memorize the previous, if it is not a
when
, because if we encounter our matchingmethodName
, before reaching when mode, we will miss it. Example:doNothing().when(mockedList).desiredMethod()
As stated above if we memorize every previous element, after reaching when mode we would losedesiredMethod()
Furthermore, there is a list with allowed do* constructs. So if support for more methods is needed, they can simply be added to the list and tests must be written to ensure, that they are working.