@@ -0,0 +1,2187 @@
+package com.cisco.oss.foundation.directory.impl;%0A%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0A/**%0A * Test for JDK 7 try-with-resource, so that we close resource%0A * automatically when we got error%0A */%0Apublic class AutoCloseTest %7B%0A%0A    private final AtomicInteger invokerCount = new AtomicInteger(0);%0A    private final Exception myCheckedEx = new Exception(%22myCheckedEx%22);%0A    private final RuntimeException myRuntimeEx = new RuntimeException(%22myRuntimeEx%22);%0A%0A    class MyService implements AutoCloseable%7B%0A%0A        public void doDirtyJobThrowRuntimeEx()%7B%0A           throw myRuntimeEx;%0A        %7D%0A        public void doDirtyJobThrowEx() throws Exception%7B%0A           throw myCheckedEx;%0A%0A        %7D%0A        @Override%0A        public void close()%7B%0A            invokerCount.getAndIncrement();%0A            //System.out.println(%22closed!%22);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testAutoClosableWhenException() %7B%0A        /**%0A         * JDK 7 try-with-resource%0A         */%0A        try(MyService myService = new MyService(); MyService myService2 = new MyService())%7B%0A            myService.doDirtyJobThrowRuntimeEx();%0A            myService2.doDirtyJobThrowEx();%0A        %7Dcatch(Exception e)%7B%0A            //When ex catch, resource already closed%0A            assertEquals(2,invokerCount.get()); //although one failure. all two are closed%0A            assertEquals(myRuntimeEx,e); // runtime ex thrown%0A        %7D%0A%0A        try(MyService myService = new MyService())%7B%0A            myService.doDirtyJobThrowEx();%0A        %7Dcatch(Exception e)%7B%0A            assertEquals(3,invokerCount.get());%0A            assertEquals(myCheckedEx,e); // checked ex thrown%0A        %7D%0A%0A        /**%0A         * JDK 6 traditional way%0A         */%0A        MyService myService = new MyService();%0A        try %7B%0A            myService.doDirtyJobThrowEx();%0A        %7D catch (Exception e) %7B%0A            assertEquals(3,invokerCount.get()); //when exception throw, resource not closed%0A            assertEquals(myCheckedEx,e);%0A        %7D finally %7B%0A            myService.close();%0A        %7D%0A        assertEquals(4,invokerCount.get()); //closed after finally called%0A    %7D%0A%7D%0A

add test for try-with-resource