### Question:
ExceptionHandlerAddressResolver { int resolve(String className, int address) { VirtualClass exceptionClass = classManager.getVirtualClass(className); return resolve(exceptionClass, address); } ExceptionHandlerAddressResolver(ClassManager classManager, VirtualMethod localMethod);   }### Answer:
@Test public void overlappingTryBlocksWithMoreThanOneValidHandlerResolvesNearestAncestor() { int currentAddress = 2; int tryStartAddress1 = 1; int tryStartAddress2 = 2; int tryCodeUnits = 10; int handlerCodeAddress1 = 20; int handlerCodeAddress2 = 30; List<BuilderExceptionHandler> handlers1 = new LinkedList<BuilderExceptionHandler>(); handlers1.add(buildHandler(handlerCodeAddress1, exceptionClass1)); tryBlocks.add(buildTryBlock(tryStartAddress1, tryCodeUnits, handlers1)); List<BuilderExceptionHandler> handlers2 = new LinkedList<BuilderExceptionHandler>(); handlers2.add(buildHandler(handlerCodeAddress2, exceptionClass2)); tryBlocks.add(buildTryBlock(tryStartAddress2, tryCodeUnits, handlers2)); ExceptionHandlerAddressResolver exceptionResolver = new ExceptionHandlerAddressResolver(classManager, METHOD); int actual = exceptionResolver.resolve(EXCEPTION3, currentAddress); assertEquals(handlerCodeAddress2, actual); }
@Test public void overlappingTryBlocksWithOneValidHandler() { int currentAddress = 2; int tryStartAddress1 = 1; int tryStartAddress2 = 2; int tryCodeUnits = 10; int handlerCodeAddress1 = 20; int handlerCodeAddress2 = 30; List<BuilderExceptionHandler> handlers1 = new LinkedList<BuilderExceptionHandler>(); handlers1.add(buildHandler(handlerCodeAddress1, exceptionClass1)); tryBlocks.add(buildTryBlock(tryStartAddress1, tryCodeUnits, handlers1)); List<BuilderExceptionHandler> handlers2 = new LinkedList<BuilderExceptionHandler>(); handlers2.add(buildHandler(handlerCodeAddress2, exceptionClass2)); tryBlocks.add(buildTryBlock(tryStartAddress2, tryCodeUnits, handlers2)); ExceptionHandlerAddressResolver exceptionResolver = new ExceptionHandlerAddressResolver(classManager, METHOD); String name = exceptionClass1.getName(); int actual = exceptionResolver.resolve(name, currentAddress); assertEquals(handlerCodeAddress1, actual); }
@Test public void simpleExceptionResolvedCorrectly() { int currentAddress = 1; int tryStartAddress = 1; int tryCodeUnits = 10; int handlerCodeAddress = 20; List<BuilderExceptionHandler> handlers = new LinkedList<BuilderExceptionHandler>(); handlers.add(buildHandler(handlerCodeAddress, exceptionClass1)); tryBlocks.add(buildTryBlock(tryStartAddress, tryCodeUnits, handlers)); ExceptionHandlerAddressResolver exceptionResolver = new ExceptionHandlerAddressResolver(classManager, METHOD); String name = exceptionClass1.getName(); int actual = exceptionResolver.resolve(name, currentAddress); assertEquals(handlerCodeAddress, actual); }