java - Mocking Objects Created Inside method Under test -
I have a class that I would like to test. Whenever possible I will inject dependency for that class which depends on the object other sections. But, I ran into a case where I want to duplicate the object without reorganizing the code and I'm not using D.
Here is the class under test:
public class dealer {public at show (carlist class car) {print print = new print (); & Lt; String & gt; List = new linked list & lt; String & gt; (); List = car.getList (); System.out.println ("Size of car list:" + list.size ()); Int printedLines = car.printDelegate (print); System.out.println ("Number of Written Print" + Printed Lines); Return number; }}
And for my test class it is:
public class examiner {dealer dealer; Car List Class Car = Fake (CarListClass.class); & Lt; String & gt; CarTest; Print Print = Fake (print class); @ First public set up () throws exceptions {dealer = new dealer ()); CarteSt = new linked list & lt; String & gt; (); CarTest.add ("Ford-Mustang"); . When (car.getList ()) thenReturn (carTest); When (car.printDelegate (print)) thenReturn (9). } @Test Public Zero Test () {int no = dealer.show (car); AssertEquals (2, number); // Not worried about emphasis as now}}
I could not duplicate the print object within the dealer class. Since, I duplicate it in the test class, but under test, it is made in this method. I did my research but found no good resources.
I know that this method and injection are the best way to print the creation of an object, but I would like to check that code, as the print object is being made inside the method. There is no way to do this
If you just want to duplicate the return of the car's return valve. Print Delegate (), How to mock about any print installation for calls?
when (car.printDelegate (org.mockito.Matchers.any (Print.class))) thenReturn (9).
Anyway, I'm confused about your following code: -
list & lt; String & gt; List = new linked list & lt; String & gt; (); // Assign a blank list worth the list = car.getList (); // nothing, but wasting memory ... return number; // No definition, do you mean printed lines?
Comments
Post a Comment