44 protected final int errorCode = 21; 45 protected final String[] msgs = {"Exception 1", "cause 1", "Exception 2", 46 "Exception 3", "cause 2"}; 47 48 @BeforeClass 49 public static void setUpClass() throws Exception { 50 } 51 52 @AfterClass 53 public static void tearDownClass() throws Exception { 54 } 55 56 @BeforeMethod 57 public void setUpMethod() throws Exception { 58 } 59 60 @AfterMethod 61 public void tearDownMethod() throws Exception { 62 } 63 64 /** 65 * Take some form of SQLException, serialize and deserialize it 66 * 67 * @param <T> SQLException 68 * @param ex SQLException 69 * @return deserialized SQLException 70 * @throws IOException 71 * @throws ClassNotFoundException 72 */ 73 @SuppressWarnings("unchecked") 74 protected <T extends SQLException> T 75 createSerializedException(T ex) 76 throws IOException, ClassNotFoundException { 77 T ex1; 78 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 79 try (ObjectOutputStream oos = new ObjectOutputStream(baos) ) { 80 oos.writeObject(ex); 81 } 82 try (ObjectInputStream ois = 83 new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { 84 ex1 = (T) ois.readObject(); 85 } 86 return ex1; 87 } 88 89 } | 44 protected final int errorCode = 21; 45 protected final String[] msgs = {"Exception 1", "cause 1", "Exception 2", 46 "Exception 3", "cause 2"}; 47 48 @BeforeClass 49 public static void setUpClass() throws Exception { 50 } 51 52 @AfterClass 53 public static void tearDownClass() throws Exception { 54 } 55 56 @BeforeMethod 57 public void setUpMethod() throws Exception { 58 } 59 60 @AfterMethod 61 public void tearDownMethod() throws Exception { 62 } 63 64 /* 65 * Take some form of SQLException, serialize and deserialize it 66 */ 67 @SuppressWarnings("unchecked") 68 protected <T extends SQLException> T 69 createSerializedException(T ex) 70 throws IOException, ClassNotFoundException { 71 return (T) serializeDeserializeObject(ex); 72 } 73 74 /* 75 * Utility method to serialize and deserialize an object 76 */ 77 @SuppressWarnings("unchecked") 78 protected <T> T serializeDeserializeObject(T o) 79 throws IOException, ClassNotFoundException { 80 T o1; 81 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 82 try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { 83 oos.writeObject(o); 84 } 85 try (ObjectInputStream ois 86 = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { 87 o1 = (T) ois.readObject(); 88 } 89 return o1; 90 } 91 } |