1 6 package com.hp.hpl.jena.rdf.model.test; 7 8 import java.util.ArrayList ; 9 import java.util.Arrays ; 10 import java.util.List ; 11 12 import junit.framework.Assert; 13 14 import com.hp.hpl.jena.rdf.model.Model; 15 import com.hp.hpl.jena.rdf.model.ModelChangedListener; 16 import com.hp.hpl.jena.rdf.model.Statement; 17 import com.hp.hpl.jena.rdf.model.StmtIterator; 18 19 20 class RecordingModelListener implements ModelChangedListener 21 { 22 List history = new ArrayList (); 23 24 public void addedStatement( Statement s ) 25 { record( "add", s ); } 26 27 public void addedStatements( Statement [] statements ) 28 { record( "add[]", Arrays.asList( statements ) ); } 29 30 public void addedStatements( List statements ) 31 { record( "addList", statements ); } 32 33 public void addedStatements( StmtIterator statements ) 34 { record( "addIterator", ModelTestBase.iteratorToList( statements ) ); } 35 36 public void addedStatements( Model m ) 37 { record( "addModel", m ); } 38 39 public void removedStatements( Statement [] statements ) 40 { record( "remove[]", Arrays.asList( statements ) ); } 41 42 public void removedStatement( Statement s ) 43 { record( "remove", s ); } 44 45 public void removedStatements( List statements ) 46 { record( "removeList", statements ); } 47 48 public void removedStatements( StmtIterator statements ) 49 { record( "removeIterator", ModelTestBase.iteratorToList( statements ) ); } 50 51 public void removedStatements( Model m ) 52 { record( "removeModel", m ); } 53 54 public void notifyEvent( Model m, Object event ) 55 { record( "someEvent", m, event ); } 56 57 protected void record( String tag, Object x, Object y ) 58 { history.add( tag ); history.add( x ); history.add( y ); } 59 60 protected void record( String tag, Object info ) 61 { history.add( tag ); history.add( info ); } 62 63 boolean has( Object [] things ) 64 { return history.equals( Arrays.asList( things ) ); } 65 66 void assertHas( Object [] things ) 67 { 68 if (has( things ) == false) 69 ModelTestBase.fail( "expected " + Arrays.asList( things ) + " but got " + history ); 70 } 71 72 public boolean has( List things ) 73 { return history.equals( things ); } 74 75 public boolean hasStart( List L ) 76 { return L.size() <= history.size() && L.equals( history.subList( 0, L.size() ) ); } 77 78 public boolean hasEnd( List L ) 79 { return L.size() <= history.size() && L.equals( history.subList( history.size() - L.size(), history.size() ) ); } 80 81 public void assertHas( List things ) 82 { if (has( things ) == false) Assert.fail( "expected " + things + " but got " + history ); } 83 84 public void assertHasStart( Object [] start ) 85 { 86 List L = Arrays.asList( start ); 87 if (hasStart( L ) == false) Assert.fail( "expected " + L + " at the beginning of " + history ); 88 } 89 90 public void assertHasEnd( Object [] end ) 91 { 92 List L = Arrays.asList( end ); 93 if (hasEnd( L ) == false) Assert.fail( "expected " + L + " at the end of " + history ); 94 } 95 } 96 97 | Popular Tags |