author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sun, 22 Jun 2014 17:46:43 +0200 | |
branch | defprop |
changeset 1634 | 783acbc99199 |
permissions | -rw-r--r-- |
jaroslav@1313 | 1 |
/** |
jaroslav@1313 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@1313 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@1313 | 4 |
* |
jaroslav@1313 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@1313 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@1313 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@1313 | 8 |
* |
jaroslav@1313 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@1313 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@1313 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@1313 | 12 |
* GNU General Public License for more details. |
jaroslav@1313 | 13 |
* |
jaroslav@1313 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@1313 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@1313 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@1313 | 17 |
*/ |
jaroslav@1313 | 18 |
package org.apidesign.bck2brwsr.tck; |
jaroslav@1313 | 19 |
|
jaroslav@1313 | 20 |
import java.io.ByteArrayOutputStream; |
jaroslav@1313 | 21 |
import java.io.PrintStream; |
jaroslav@1313 | 22 |
import java.io.PrintWriter; |
jaroslav@1313 | 23 |
import java.io.StringWriter; |
jaroslav@1313 | 24 |
import java.io.UnsupportedEncodingException; |
jaroslav@1313 | 25 |
import org.apidesign.bck2brwsr.vmtest.Compare; |
jaroslav@1313 | 26 |
import org.apidesign.bck2brwsr.vmtest.VMTest; |
jaroslav@1313 | 27 |
import org.testng.annotations.Factory; |
jaroslav@1313 | 28 |
|
jaroslav@1313 | 29 |
/** |
jaroslav@1313 | 30 |
* |
jaroslav@1313 | 31 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@1313 | 32 |
*/ |
jaroslav@1313 | 33 |
public class ExceptionsTest { |
jaroslav@1313 | 34 |
@Compare public String firstLineIsTheSame() throws UnsupportedEncodingException { |
jaroslav@1313 | 35 |
MyException ex = new MyException("Hello"); |
jaroslav@1313 | 36 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
jaroslav@1313 | 37 |
PrintStream ps = new PrintStream(out); |
jaroslav@1313 | 38 |
ex.printStackTrace(ps); |
jaroslav@1313 | 39 |
ps.flush(); |
jaroslav@1313 | 40 |
|
jaroslav@1313 | 41 |
String s = new String(out.toByteArray(), "UTF-8"); |
jaroslav@1313 | 42 |
int newLine = s.indexOf('\n'); |
jaroslav@1313 | 43 |
return s.substring(0, newLine); |
jaroslav@1313 | 44 |
} |
jaroslav@1313 | 45 |
|
jaroslav@1313 | 46 |
@Compare public String firstLineIsTheSameWithWriter() throws UnsupportedEncodingException { |
jaroslav@1313 | 47 |
MyException ex = new MyException("Hello"); |
jaroslav@1313 | 48 |
StringWriter sw = new StringWriter(); |
jaroslav@1313 | 49 |
PrintWriter pw = new PrintWriter(sw); |
jaroslav@1313 | 50 |
ex.printStackTrace(pw); |
jaroslav@1313 | 51 |
pw.flush(); |
jaroslav@1313 | 52 |
|
jaroslav@1313 | 53 |
String s = sw.toString(); |
jaroslav@1313 | 54 |
int newLine = s.indexOf('\n'); |
jaroslav@1313 | 55 |
return s.substring(0, newLine); |
jaroslav@1313 | 56 |
} |
jaroslav@1313 | 57 |
|
jaroslav@1313 | 58 |
static class MyException extends Exception { |
jaroslav@1313 | 59 |
public MyException(String message) { |
jaroslav@1313 | 60 |
super(message); |
jaroslav@1313 | 61 |
} |
jaroslav@1313 | 62 |
} |
jaroslav@1313 | 63 |
|
jaroslav@1313 | 64 |
|
jaroslav@1313 | 65 |
@Factory public static Object[] create() { |
jaroslav@1313 | 66 |
return VMTest.create(ExceptionsTest.class); |
jaroslav@1313 | 67 |
} |
jaroslav@1313 | 68 |
} |