lundi 13 mai 2019

How to test a simple given method

I am new to testing with java so it confuses me a little how to write a proper unit test to a method with no parameters and return value. In general the snippet looks like the below:


public class SplitterService {

private SentenceDAO sentenceObject;
private ObjectToXML objectToXML;
private ObjectToCSV objectToCSV;

public SplitterService(int selector, String inputPath, String outputPath) {
        this(inputPath);
        if (selector == 1)
            objectToCSV = new ObjectToCSV(outputPath, size);
        if (selector == 2)
            objectToXML = new ObjectToXML(outputPath);
    }

public void chooseConverter() {
        if (objectToCSV != null)
            objectToCSV.printRecord(sentenceObject);
        if (objectToXML != null)
            objectToXML.marshal(sentenceObject);
    }
}

There are 3 private fields in the class. There is also a constructor which instantiate a given class. Then in the chooseConverter() method a proper action is taken according to the created object.

Could you please give me some advice how to test the chooseConverter method since there is no return value and a parameter (I know Junit 5 and a little of Mockito). Im not looking for any given solution just a few words how to approach my issue.

Aucun commentaire:

Enregistrer un commentaire