From bdcc7b023d0594780b8d54e51fdd77ba4498192d Mon Sep 17 00:00:00 2001 From: akashissu <111304105+akashissu@users.noreply.github.com> Date: Mon, 31 Oct 2022 13:41:12 +0530 Subject: [PATCH] Create JenkinsPipelineUnit - unable to mock getId() called within script block --- ...to mock getId() called within script block | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 JenkinsPipelineUnit - unable to mock getId() called within script block diff --git a/JenkinsPipelineUnit - unable to mock getId() called within script block b/JenkinsPipelineUnit - unable to mock getId() called within script block new file mode 100644 index 00000000..aadbfc29 --- /dev/null +++ b/JenkinsPipelineUnit - unable to mock getId() called within script block @@ -0,0 +1,20 @@ +@RunWith(MockitoJunitRunner.class) +class FooTest { + @Mock // Same as "someThing = Mockito.mock(SomeThing.class)" + private SomeThing someThing, + + private final Foo foo; + + @Before + public void setup() throws Exception { + foo = new Foo(); // our instance of Foo we will be testing + foo.setSomeThing(someThing); // we "inject" our mocked SomeThing + } + + @Test + public void testFoo() throws Exception { + when(someThing.compute(anyInt()).thenReturn(2); // we define some behavior + assertEquals(2, foo.bar(5)); // test assertion + verify(someThing).compute(7); // verify behavior. + } +}