I created strategy for taking input because I want to test it.
This is my production code for taking input:
//strategy pattern
public interface BarcodeScannerInput {
public String getBarcode();
public int getBarcodeType();
}
//taking input from user (barcode and type)
class TakeInput implements BarcodeScannerInput {
private String barcode;
private int barcodeType;
public String getBarcode(){
System.out.println("Enter barcode: ");
Scanner code = new Scanner(System.in);
barcode=code.nextLine();
return barcode;
}
public int getBarcodeType(){
System.out.println("Enter type of barcode (1-2):");
Scanner type = new Scanner(System.in);
barcodeType = type.nextInt();
return barcodeType;
}
}
And my question is: How should look class for testing this input in junit tests?
Aucun commentaire:
Enregistrer un commentaire