Ejemplo n.º 1
0
 @Test
 public void testTerminate() throws Exception {
   ProBInstance proBInstance = mock(ProBInstance.class);
   BufferedReader reader = new BufferedReader(new StringReader("foo"));
   when(proBInstance.isShuttingDown()).thenReturn(true);
   Logger logger = mock(Logger.class);
   ConsoleListener listener = new ConsoleListener(proBInstance, reader, logger);
   listener.logLines();
   verify(logger, never()).debug("foo");
 }
Ejemplo n.º 2
0
 @Test
 public void testSingleLineRead() throws Exception {
   ProBInstance proBInstance = mock(ProBInstance.class);
   BufferedReader reader = new BufferedReader(new StringReader("foo"));
   Logger logger = mock(Logger.class);
   ConsoleListener listener = new ConsoleListener(proBInstance, reader, logger);
   String line = listener.readAndLog();
   assertEquals("foo", line);
   verify(logger).debug("foo");
 }
Ejemplo n.º 3
0
 @Test
 public void testTerminateNull() throws Exception {
   ProBInstance proBInstance = mock(ProBInstance.class);
   BufferedReader reader = new BufferedReader(new StringReader(""));
   when(proBInstance.isShuttingDown()).thenReturn(true);
   Logger logger = mock(Logger.class);
   ConsoleListener listener = new ConsoleListener(proBInstance, reader, logger);
   String line = listener.readAndLog();
   assertNull(line);
   verifyNoMoreInteractions(logger);
 }
Ejemplo n.º 4
0
 @Test
 public void testMultiLineReadAndTerminate() throws Exception {
   ProBInstance proBInstance = mock(ProBInstance.class);
   BufferedReader reader = new BufferedReader(new StringReader("foo\nbar\ngoo"));
   Logger logger = mock(Logger.class);
   ConsoleListener listener = new ConsoleListener(proBInstance, reader, logger);
   when(proBInstance.isShuttingDown()).thenReturn(false, false, true);
   listener.logLines();
   verify(logger).debug("foo");
   verify(logger).debug("bar");
   verifyNoMoreInteractions(logger);
 }
Ejemplo n.º 5
0
  /**
   * @param source
   * @param cmd
   * @param ev
   */
  public void cmdAnalyser(ConsoleListener source, String cmd, ViewEvent ev) {

    boolean badArgument = true;
    int i;
    int j;
    int iIndexEnd;
    int jIndexEnd;
    String sFlag;
    try {
      while (badArgument) {

        if (cmd.length() == 0) {
          throw new InvalidCommandException();

        } else if (cmd.equals("h")) {
          this.help();
          badArgument = false;
          source.catchViewEvent(ev);
        } else if ("d".equals(cmd.substring(0, 1))) {
          iIndexEnd = cmd.indexOf(" ", 2);
          i = Integer.valueOf(cmd.substring(2, iIndexEnd));
          j = Integer.valueOf(cmd.substring(iIndexEnd + 1));
          i--;
          j--;
          badArgument = false;
          Minesweeper.getInstance().getRules().demine(i, j);

        } else if ("m".equals(cmd.substring(0, 1))) {
          iIndexEnd = cmd.indexOf(" ", 2);
          jIndexEnd = cmd.indexOf(" ", iIndexEnd + 1);
          i = Integer.valueOf(cmd.substring(2, iIndexEnd));
          j = Integer.valueOf(cmd.substring(iIndexEnd + 1, jIndexEnd));
          sFlag = cmd.substring(jIndexEnd + 1);
          i--;
          j--;
          badArgument = false;
          Minesweeper.getInstance().getRules().flag(i, j, sFlag);

        } else if ("q".equals(cmd.substring(0, 1)) && cmd.length() == 1) {
          Minesweeper.getInstance().exit();
          badArgument = false;

        } else if (cmd.equals("o")) {
          Minesweeper.getInstance().jumToOptions();
          badArgument = false;

        } else if (cmd.equals("r")) {
          Minesweeper.getInstance().restart();
          badArgument = false;

        } else {
          throw new InvalidCommandException();
        }
      }
    } catch (RuntimeException e) {
      throw new InvalidCommandException();
    }
  }
 private void fireConsoleInitializedEvent(LanguageConsoleView consoleView) {
   for (ConsoleListener listener : myConsoleListeners) {
     listener.handleConsoleInitialized(consoleView);
   }
 }