SERG-Delft / andy

Andy assesses student's test code. It's used in CSE1110, TU Delft.
MIT License
78 stars 22 forks source link

Alternate construct #216

Closed adonev42 closed 1 year ago

adonev42 commented 1 year ago

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 be desiredMethod() -> 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 previous

We only memorize the previous, if it is not a when, because if we encounter our matching methodName, 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 lose desiredMethod()

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.

mauricioaniche commented 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.

adonev42 commented 1 year ago

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.

martinmladenov commented 1 year ago

@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

mauricioaniche commented 1 year ago

@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!

mauricioaniche commented 1 year ago

@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! :)

adonev42 commented 1 year ago

Hello @mauricioaniche, The method should be added as an exception