public void readInput(Scanner sc) {
while (sc.hasNext())
{
//check if we are in a tag to begin with
String s = new String(sc.next());
if (Pattern.matches("[\\p{Punct}\\p{IsPunctuation}]", s.substring(
s.length() - 1)) && !Pattern.matches("[]", s.substring( s.length() - 1)))
//If word has punctuation at the end
{
Token ta = new Token(s.substring(0, s.length() - 1)); //Token of the word
Token tb = new Token(s.substring(s.length() - 1)); //Token of Punctuation
this.tokens.add(ta);
this.tokens.add(tb);
}
else //if no punctuation add whole word
{
Token t = new Token(s);
this.tokens.add(t);
}
if(s.compareTo("") == 0) {
double startTime = System.nanoTime();//
this.createWindows();
this.printTextBlock();
this.cleanup();
double endTime = System.nanoTime();
double duration = (endTime - startTime)/1000000000; //divide by 1000000 to
get
milliseconds.
System.out.println("\n\n" + duration + " seconds runtime");
}
}
sc.close();
Asked
Active
Viewed 38 times
-3

ravthiru
- 8,878
- 2
- 43
- 52

Daniel Payne
- 1
- 1
-
First stumbling block I see: the code doesn't *compile*... – Makoto Apr 13 '18 at 04:54
-
1What are you trying to test exactly? The scanner behaviour can probably be tested, the methods that seem to be only doing side effects might not be as easy – ghaith Apr 13 '18 at 04:59
-
It's also *usually* considered poor form to close resources you didn't open. – chrylis -cautiouslyoptimistic- Apr 13 '18 at 05:14
1 Answers
0
You need to simulate user input by passing scanner object to readInput Method something like this
String input = "Input";
InputStream in = new ByteArrayInputStream(input.getBytes());
Scanner scanner = new Scanner(in);
readInput(scanner);

ravthiru
- 8,878
- 2
- 43
- 52