jaroslav@1313: /** jaroslav@1313: * Back 2 Browser Bytecode Translator jaroslav@1313: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1313: * jaroslav@1313: * This program is free software: you can redistribute it and/or modify jaroslav@1313: * it under the terms of the GNU General Public License as published by jaroslav@1313: * the Free Software Foundation, version 2 of the License. jaroslav@1313: * jaroslav@1313: * This program is distributed in the hope that it will be useful, jaroslav@1313: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1313: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1313: * GNU General Public License for more details. jaroslav@1313: * jaroslav@1313: * You should have received a copy of the GNU General Public License jaroslav@1313: * along with this program. Look for COPYING file in the top folder. jaroslav@1313: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1313: */ jaroslav@1313: package org.apidesign.bck2brwsr.tck; jaroslav@1313: jaroslav@1313: import java.io.ByteArrayOutputStream; jaroslav@1313: import java.io.PrintStream; jaroslav@1313: import java.io.PrintWriter; jaroslav@1313: import java.io.StringWriter; jaroslav@1313: import java.io.UnsupportedEncodingException; jaroslav@1313: import org.apidesign.bck2brwsr.vmtest.Compare; jaroslav@1313: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@1313: import org.testng.annotations.Factory; jaroslav@1313: jaroslav@1313: /** jaroslav@1313: * jaroslav@1313: * @author Jaroslav Tulach jaroslav@1313: */ jaroslav@1313: public class ExceptionsTest { jaroslav@1313: @Compare public String firstLineIsTheSame() throws UnsupportedEncodingException { jaroslav@1313: MyException ex = new MyException("Hello"); jaroslav@1313: ByteArrayOutputStream out = new ByteArrayOutputStream(); jaroslav@1313: PrintStream ps = new PrintStream(out); jaroslav@1313: ex.printStackTrace(ps); jaroslav@1313: ps.flush(); jaroslav@1313: jaroslav@1313: String s = new String(out.toByteArray(), "UTF-8"); jaroslav@1313: int newLine = s.indexOf('\n'); jaroslav@1313: return s.substring(0, newLine); jaroslav@1313: } jaroslav@1313: jaroslav@1313: @Compare public String firstLineIsTheSameWithWriter() throws UnsupportedEncodingException { jaroslav@1313: MyException ex = new MyException("Hello"); jaroslav@1313: StringWriter sw = new StringWriter(); jaroslav@1313: PrintWriter pw = new PrintWriter(sw); jaroslav@1313: ex.printStackTrace(pw); jaroslav@1313: pw.flush(); jaroslav@1313: jaroslav@1313: String s = sw.toString(); jaroslav@1313: int newLine = s.indexOf('\n'); jaroslav@1313: return s.substring(0, newLine); jaroslav@1313: } jaroslav@1313: jaroslav@1313: static class MyException extends Exception { jaroslav@1313: public MyException(String message) { jaroslav@1313: super(message); jaroslav@1313: } jaroslav@1313: } jaroslav@1313: jaroslav@1313: jaroslav@1313: @Factory public static Object[] create() { jaroslav@1313: return VMTest.create(ExceptionsTest.class); jaroslav@1313: } jaroslav@1313: }