/*
 	(c) Copyright 2006 Hewlett-Packard Development Company, LP
 	All rights reserved - see end of file.
 	$Id: TestConcurrentModificationException.java,v 1.3 2006-04-28 08:23:57 chris-dollin Exp $
*/

package com.hp.hpl.jena.mem.faster.test;

import java.util.*;

import junit.framework.*;

import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.mem.*;
import com.hp.hpl.jena.rdf.model.test.ModelTestBase;

public class TestConcurrentModificationException extends ModelTestBase
    {
    public TestConcurrentModificationException( String name )
        { super( name ); }

    public static TestSuite suite()
        { return new TestSuite( TestConcurrentModificationException.class ); }

    public void testArrayBunchCME() 
        { 
        testBunchCME( new ArrayBunch() );
        }
    
    public void testSetBunchCME()
        {
        testBunchCME( new SetBunch( new ArrayBunch() ) );
        }
    
    public void testHashedBunchCME()
        {
        testBunchCME( new HashedTripleBunch( new ArrayBunch() ) );
        }

    private void testBunchCME( TripleBunch b )
        {
        b.add( Triple.create( "a P b" ) );
        b.add( Triple.create( "c Q d" ) );
        Iterator it = b.iterator();
        it.next();
        b.add( Triple.create( "change its state" ) );
        try { it.next(); fail( "should have thrown ConcurrentModificationException" ); }
        catch (ConcurrentModificationException e) { pass(); }
        }
    }


/*
 * (c) Copyright 2006 Hewlett-Packard Development Company, LP
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@@ -150,17 +150,17 @@
 ava,v 1.
-3
+4
  2006-04
@@ -170,13 +170,13 @@
  08:
-23:57
+46:25
  chr
@@ -413,16 +413,25 @@
 %0Apublic 
+abstract 
 class Te
@@ -597,64 +597,390 @@
 lic 
-static TestSuite suite()%0A        %7B return new TestSuite(
+abstract TripleBunch getBunch();%0A    %0A    public static TestSuite suite()%0A        %7B %0A        TestSuite result = new TestSuite();%0A        result.addTestSuite( TestArrayBunchCME.class ); %0A        result.addTestSuite( TestSetBunchCME.class ); %0A        result.addTestSuite( TestHashedBunchCME.class ); %0A        return result;%0A        %7D%0A%0A    public static class TestArrayBunchCME extends
  Tes
@@ -1015,21 +1015,23 @@
 tion
-.class ); %7D%0A%0A
+%0A        %7B%0A    
     
@@ -1037,22 +1037,17 @@
  public 
-void t
+T
 estArray
@@ -1059,43 +1059,111 @@
 CME(
-) %0A        %7B %0A        testBunchCME(
+String name)%0A            %7B super( name ); %7D%0A%0A        public TripleBunch getBunch()%0A            %7B return
  new
@@ -1175,19 +1175,19 @@
 yBunch()
- );
+; %7D
 %0A       
@@ -1209,62 +1209,225 @@
 lic 
-void testSetBunchCME()%0A        %7B%0A        testBunchCME(
+static class TestSetBunchCME extends TestConcurrentModificationException%0A        %7B%0A        public TestSetBunchCME(String name)%0A            %7B super( name ); %7D%0A%0A        public TripleBunch getBunch()%0A            %7B return
  new
@@ -1447,35 +1447,35 @@
 w ArrayBunch() )
- );
+; %7D
 %0A        %7D%0A    %0A
@@ -1485,22 +1485,30 @@
  public 
-void t
+static class T
 estHashe
@@ -1520,95 +1520,320 @@
 hCME
-()%0A        %7B%0A        testBunchCME( new HashedTripleBunch( new ArrayBunch() ) );%0A       
+ extends TestConcurrentModificationException%0A        %7B%0A        public TestHashedBunchCME(String name)%0A            %7B super( name ); %7D%0A%0A        public TripleBunch getBunch()%0A            %7B return new HashedTripleBunch( new ArrayBunch() ); %7D%0A        %7D%0A%0A    public void testCME()%0A        %7B testBunchCME( getBunch() );
  %7D%0A%0A

Refactored the test class to support multiple tests over the three different kinds of bunch.