There is a class that performs the dividing logic in a column, the results of the calculation are stored in its variables.

public class IntegerDivisionLogic { private Integer dividend; private Integer divisor; private int quotient; private ArrayList<Integer> remaindersCollection = new ArrayList<>(); 

Next, the IntegerDivisionLogic class transfers all the data to the .json file.

  { "dividend": 12341234, "divisor": 1234, "quotient": 10001, "remaindersCollection": [ 1234, 1234, 1234, 1234, 0 ] } 

After that, the IntegerDivisionDrawer drawing class reads data from .json, recording it in its fields.

 public class IntegerDivisionDrawer { private Integer dividend; private Integer divisor; private Integer quotient; private ArrayList<Integer> remaindersCollection = new ArrayList<>(); 

Based on the data builds the algorithm for drawing division.

 String drawIntegerDivision() { buildHead(); buildBody(); buildTail(); return result.toString(); } 

You need to write unit tests for the IntegerDivisionDrawer class using the mockito, (they say the easiest way). But I do not know where to start writing and how to approach it. For for the class IntegerDivisionLogic tests are written.

    1 answer 1

    I see 2 topics for discussion:

    1. Class design
    2. Testing without mockito

    According to the best OOP traditions, your drawing class should accept a ready-made object for drawing and not its responsibility to parse json. And as a result, you no longer need to duplicate all the fields of the first class, but simply create a field with the first class type:

     class IntegerDivisionDrawer { private final IntegerDivisionLogic logic; IntegerDivisionDrawer(IntegerDivisionLogic logic) { this.logic = logic; } } 

    Now you can test without mockito.

    And reading and parsing json can be done in a separate method:

     IntegerDivisionLogic getFromJsonFile(String fileName) {...} 

    Now on the caller will be like this:

     IntegerDivisionLogic logicFromFile = getFromJsonFile("/user/bob/my.json"); IntegerDivisionDrawer drawer = new IntegerDivisionDrawer(logicFromFile); drawer.drawIntegerDivision(); 

    The question remains how to test parsing json? Create a json string and pass to the method, waiting for the constructed object to exit. In this case it is not necessary to get wet.