test/testlibrary_tests/OutputAnalyzerTest.java

Print this page


   1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 171         throw new Exception("shouldNotMatch() failed to throw exception");
 172     } catch (RuntimeException e) {
 173         // expected
 174     }
 175 
 176     {
 177       String aaaa = "aaaa";
 178       String result = output.firstMatch(aaaa);
 179       if (!aaaa.equals(result)) {
 180         throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result);
 181       }
 182     }
 183 
 184     {
 185       String aa = "aa";
 186       String aa_grouped_aa = aa + "(" + aa + ")";
 187       String result = output.firstMatch(aa_grouped_aa, 1);
 188       if (!aa.equals(result)) {
 189         throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result);
 190       }



















 191     }
 192   }
 193 }
   1 /*
   2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 171         throw new Exception("shouldNotMatch() failed to throw exception");
 172     } catch (RuntimeException e) {
 173         // expected
 174     }
 175 
 176     {
 177       String aaaa = "aaaa";
 178       String result = output.firstMatch(aaaa);
 179       if (!aaaa.equals(result)) {
 180         throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result);
 181       }
 182     }
 183 
 184     {
 185       String aa = "aa";
 186       String aa_grouped_aa = aa + "(" + aa + ")";
 187       String result = output.firstMatch(aa_grouped_aa, 1);
 188       if (!aa.equals(result)) {
 189         throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result);
 190       }
 191     }
 192 
 193     {
 194         output = new OutputAnalyzer(stdout);
 195         String actual = output.getStdout();
 196         if (!stdout.equals(actual)) {
 197             throw new RuntimeException(String.format(
 198                     "The expected stdout  '%s' doesn't equal to '%s'",
 199                     stdout, actual));
 200         }
 201         if (!output.getStderr().isEmpty()) {
 202             throw new RuntimeException(String.format(
 203                     "The expected stderr should be empty, '%s'", actual));
 204         }
 205         if (!stdout.equals(output.getOutput())) {
 206             throw new RuntimeException(String.format(
 207                     "The expected output '%s' doesn't equal to '%s'",
 208                     stdout, actual));
 209         }
 210     }
 211   }
 212 }