Mockito is weird and awesome at the same time. I'm still fuzzy on a lot of
things.

A very very quick pass I think its line 44 (
https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java#L44
)

when(jobHMS.getBuilds()).thenReturn(RunList.fromRuns(buildListHMS));

Mockito doesn't actually let you return the results of a function, you'll
have to assign it to a local variable first.

Its related to
https://github.com/mockito/mockito/wiki/FAQ#can-i-thenreturn-an-inlined-mock-
I think.

That being said, its probably way easier and sustainable to use a
jenkinsrule and not try and mock things.

On Sun, Jul 7, 2019 at 7:33 PM 'Benjamin Beggs' via Jenkins Developers <
[email protected]> wrote:

> I'm working on an update to the enhanced-old-build-discarder plugin that
> allows for some greater configuration specificity in the discard logic. The
> plugin functions as expected in my local Jenkins instance, but I'm having
> trouble with the unit testing.
>
> The relevant pull request is here:
> https://github.com/jenkinsci/enhanced-old-build-discarder/pull/2.
> The relevant test file is here:
> https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java
> .
>
> I must be doing something incorrectly with my mock Job data. I generate a
> build history suitable for my usage cases and use Mockito "when" to have
> this represent the build history of the mock Job. An instance of the plugin
> class is instantiated and this Job is passed to it as an argument. I'm then
> trying to verify that delete commands are either logged or not logged for
> the build histories as is appropriate to the usage case. No matter the
> circumstance builds are never verified to be deleted.
>
> Does anyone have an idea what the issue is here? I expect it won't take
> much to fix but I'm puzzled by it.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DutmLXe3aR5PMNOi1UhXeciJy5WcRhaFhYbxsK1YuQhzEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to