@@ -0,0 +1,2178 @@
+package hudson;%0A%0Aimport hudson.model.Saveable;%0Aimport junit.framework.TestCase;%0A%0Aimport java.io.IOException;%0A%0A/**%0A * Tests %7B@link BulkChange%7D.%0A *%0A * @author Kohsuke Kawaguchi%0A */%0Apublic class BulkChangeTest extends TestCase %7B%0A%0A    private class Point implements Saveable %7B%0A        /**%0A         * Don't actually do any save, but just remember how many the actual I/O would have happened.%0A         */%0A        int saveCount = 0;%0A%0A        int x,y;%0A%0A        public void setX(int x) throws IOException %7B%0A            this.x = x;%0A            save();%0A        %7D%0A%0A        public void setY(int y) throws IOException %7B%0A            this.y = y;%0A            save();%0A        %7D%0A%0A        public void set(int x, int y) throws IOException %7B%0A            setX(x);%0A            setY(y);%0A        %7D%0A%0A        public void save() throws IOException %7B%0A            if(BulkChange.contains(this))   return;%0A            saveCount++;%0A        %7D%0A    %7D%0A%0A    /**%0A     * If there is no BulkChange, we should see two saves.%0A     */%0A    public void testNoBulkChange() throws Exception %7B%0A        Point pt = new Point();%0A        pt.set(0,0);%0A        assertEquals(2,pt.saveCount);%0A    %7D%0A%0A    /**%0A     * With a %7B@link BulkChange%7D, this will become just one save.%0A     */%0A    public void testBulkChange() throws Exception %7B%0A        Point pt = new Point();%0A        BulkChange bc = new BulkChange(pt);%0A        try %7B%0A            pt.set(0,0);%0A        %7D finally %7B%0A            bc.commit();%0A        %7D%0A        assertEquals(1,pt.saveCount);%0A    %7D%0A%0A    /**%0A     * %7B@link BulkChange%7Ds can be nested.%0A     */%0A    public void testNestedBulkChange() throws Exception %7B%0A        Point pt = new Point();%0A        Point _ = new Point();%0A        BulkChange bc1 = new BulkChange(pt);%0A        try %7B%0A            BulkChange bc2 = new BulkChange(_);%0A            try %7B%0A                BulkChange bc3 = new BulkChange(pt);%0A                try %7B%0A                    pt.set(0,0);%0A                %7D finally %7B%0A                    bc3.commit();%0A                %7D%0A            %7D finally %7B%0A                bc2.commit();%0A            %7D%0A            pt.set(0,0);%0A        %7D finally %7B%0A            bc1.commit();%0A        %7D%0A        assertEquals(1,pt.saveCount);%0A    %7D%0A%7D%0A

test case for BulkChange