import static org
![топ 100 блогов](/media/images/default.jpg)
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.junit.Test; public class Sample{ static class A { public static A s; public A(Collection c) { c.add(this); s = this; throw new RuntimeException(); } } @Test public void testResource() throws Exception { List l = new ArrayList(); A a = null; try { a = new A(l); fail("Oops"); } catch (Throwable e) { } assertTrue(l.size() == 1); assertNull(a); assertNotNull(A.s); assertNotNull(l.get(0)); } }
Опаньки. Чтение JLS таки доставляет :)
|
</> |