ImmutableExceptionHandler exceptionHandler = new ImmutableExceptionHandler(exceptionType, codeAddress);
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) { if (exceptionHandler instanceof ImmutableExceptionHandler) { return (ImmutableExceptionHandler)exceptionHandler; } return new ImmutableExceptionHandler( exceptionHandler.getExceptionType(), exceptionHandler.getHandlerCodeAddress()); }
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) { if (exceptionHandler instanceof ImmutableExceptionHandler) { return (ImmutableExceptionHandler)exceptionHandler; } return new ImmutableExceptionHandler( exceptionHandler.getExceptionType(), exceptionHandler.getHandlerCodeAddress()); }
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) { if (exceptionHandler instanceof ImmutableExceptionHandler) { return (ImmutableExceptionHandler)exceptionHandler; } return new ImmutableExceptionHandler( exceptionHandler.getExceptionType(), exceptionHandler.getHandlerCodeAddress()); }
@Test public void testOverlap_Start_End() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 10, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Before_End() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Before_Before() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 3, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 3, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_After_After() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(15, 20, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 10, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5))), new ImmutableTryBlock(15, 5, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Beginning_After() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 10, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(10, 5, ImmutableList.of( new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Before_Start() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 5, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_Middle_End() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5))), new ImmutableTryBlock(5, 5, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testOverlap_End_After() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(10, 20, new ImmutableExceptionHandler("LException2;", 6)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 10, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5))), new ImmutableTryBlock(10, 10, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testHandlerMerge_Same() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException1;", 5)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 15, ImmutableList.of( new ImmutableExceptionHandler("LException1;", 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testSingleCatch_Beginning() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler("Ljava/lang/Exception;", 5)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(0, 10, ImmutableList.of(new ImmutableExceptionHandler("Ljava/lang/Exception;", 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testHandlerMerge_Catchall_Catchall() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler(null, 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler(null, 5)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of( new ImmutableTryBlock(0, 15, ImmutableList.of( new ImmutableExceptionHandler(null, 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testSingleCatchAll_Beginning() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(0, 10, new ImmutableExceptionHandler(null, 5)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(0, 10, ImmutableList.of(new ImmutableExceptionHandler(null, 5)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testSingleCatchAll_Middle() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler(null, 15)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler(null, 15)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testSingleCatch_Middle() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("Ljava/lang/Exception;", 15)); List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks(); List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler("Ljava/lang/Exception;", 15)))); Assert.assertEquals(expected, tryBlocks); }
@Test public void testHandlerMerge_Catchall_Catchall_DifferentAddress() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler(null, 5)); try { tlb.addHandler(0, 15, new ImmutableExceptionHandler(null, 6)); } catch (TryListBuilder.InvalidTryException ex) { return; } Assert.fail(); }
@Test public void testHandlerMerge_DifferentAddress() { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException1;", 6)); // no exception should be thrown... }