Mockito misuse - UnfinishedStubbingException
Aug 15, 2023
Mockito misuse - UnfinishedStubbingException
► ►Personal queries? - Follow me on LinkedIn - https://www.linkedin.com/in/dinesh-va … ► ►This video is part of my Complete Mastering Mockito 3 Course playlist: • Mockito 3 Tutorials ►Source Code - https://github.com/dinesh-varyani/moc … ►Click here to subscribe - https://www.youtube.com/user/hubbersp … Watch all my playlist here: ►Data Structures and Algorithms Course playlist: • Data Structures and Algorithms in Jav… ►Mastering JUnit 5 - https://www.youtube.com/playlist?list … ►Mastering Mockito 3 - • Mockito 3 Tutorials ►Analysis of Algorithms - • Analysis of Algorithms ►Linked List Data Structures - • Linked List Data Structures ►Array Data Structures - • เพลย์ลิสต์ ►Stack Data Structure - • Stack Data Structure ►Queue Data Structure - • Queue Data Structure ►Binary Tree Data Structure - • Binary Tree Data Structure ►Graph Data Structure - • Graph Data Structure ►Binary Heap Data Structure - • Binary Heap Data Structure ►Trie Data Structure - • Trie Data Structure ►Dynamic Programming Algorithms - • Dynamic Programming Algorithms ►Hashing Data Structures - • Hashing Data Structures ►Sorting and Searching - • Sorting and Searching ►String Algorithms - • String Algorithms ►Java Programming Tutorial - • Java Programming Tutorial ►Design Patterns in Java - • Design Patterns in Java Follow Me On Social Media ►Website - http://www.hubberspot.com ►Facebook - https://www.facebook.com/dinesh.varyani/ ►Instagram - https://www.instagram.com/dinu.varyani/ Get complete free course on Data Structures and Algorithms at - • Data Structures and Algorithms in Jav… . Subscribe to the channel for all free courses at - https://www.youtube.com/user/hubbersp … 🙏 Thank you for your continuous love and support. I humbly request you to help this channel grow more, for that please Like, Share and Subscribe to my channel. Your support will motivate me to add more valuable content. || LIKE || SHARE || SUBSCRIBE || For a free complete course download our android app on Mockito 3 Tutorials - https://play.google.com/store/apps/de … COMPLETE SOURCE CODE - https://github.com/dinesh-varyani/moc … Visit my blog for more such free videos - http://www.hubberspot.com
Content
3.3 -> Hello everyone. So, friends in our previous
lecture, we saw that how we can perform
8.37 -> stubbing, using when, along with in return
and do return along with when. And also
18.03 -> friends we saw that in the first approach
when we use when inside is when method we
24.09 -> provided book repository dot find book by
providing method with an argument, but when
32.82 -> we use do return inside when we simply
provided the mock object and we actually call
40.05 -> the method on whatever was returned from the
win. So, from this is a slight difference
46.05 -> between the two approaches. So, what happens
if we do something like this, let's say by
53.25 -> mistakenly
55.5 -> if I simply remove this part and if I use it
here in both approaches, so, you can see the
66.66 -> code compile properly, but if I run the test
is now So, friends you can see the test is
80.49 -> got failed
82.77 -> and it gave an exception or dot mockito dot
exceptions dot misusing and the name of the
91.62 -> exception is unfinished stubbing exception
So, what Margaret is telling us that here you
99.36 -> haven't finished the stubbing and it also
tells us that unfinished stubbing detected
106.11 -> here should also gives the line number, so,
if I click it here, it takes me to this line
115.86 -> and also give an example that then return
maybe missing. So, you can see, it says that
123.18 -> examples of correct serving is when mob.is
okay then return true and some other cases,
130.38 -> which we will discuss in our upcoming
lectures. And it also gives the hints that
135.81 -> missing then written and some other ends
saying that you're trying to start a final
144 -> method, which is not supported. So, friends
and mockito you cannot stop the final method.
150.78 -> So, this is one of the limitations and it
also gives some other ends which we will be
155.52 -> discussing in our upcoming lectures. So,
friends here can see this one and this one
161.58 -> are two different methods.
163.86 -> So, here I will just revert it back and if I
uncomment this part So, you can see that this
177.45 -> one method has a return type of ongoing
stubbing this and this method is present in
189.3 -> all dot mockito dot mockito class and this
one method has a different return type and it
199.14 -> is present in So, if I go to it, you can see
that it takes only a mock object and it is
206.79 -> present in the server class provided by
mockito for the stubbing.
214.949 -> So, friends we need to be careful while using
when then return and do return with when
220.679 -> because it looks like they are the same
method but they are actually not. So, one
225.779 -> whether takes a method which we actually want
to stop and other takes the mock
232.74 -> and whatever is returned. On top of that we
call this method which you want to stop. So,
242.19 -> when this was slightly different between the
two approaches, and in this lecture, we saw a
248.67 -> very common exception, unfinished dubbing
exception. I hope you like this video. Thanks
254.85 -> Have a nice day.
Source: https://www.youtube.com/watch?v=CeRkI2HpZg0