The problem is how some compilers and interpreters generate the executable here with the Nextline() as a procedure call. If we express this to a series of IF statements then it is clearer what can go wrong.
if input.newline() = "test 1":
System.out.println("right on");
break;
if input.newline() = "test 2":
System.out.println("try again");
break;
if input.newline() = "test":
System.out.println("and?");
break;
At this point we can see that in the worst case the input.newline() will be executed 3 times each time obtaining a new value. input.newline() is a destructive method which returns a different segment of a stream each time it is called.
I cannot say how this is implemented in Java, but as a matter of form it is better to assign the result of newline to a temp variable and validate the input against that. But as the previous poster stated switches on strings this way is not great form as there is commonly a better way.