1 6 7 package com.hp.hpl.jena.graph.test; 8 9 import com.hp.hpl.jena.graph.*; 10 11 import junit.framework.*; 12 import java.util.*; 13 14 18 public class RecordingListener implements GraphListener 19 { 20 public List history = new ArrayList(); 21 22 public void notifyAddTriple( Graph g, Triple t ) 23 { record( "add", g, t ); } 24 25 public void notifyAddArray( Graph g, Triple [] triples ) 26 { record( "add[]", g, triples ); } 27 28 public void notifyAddList( Graph g, List triples ) 29 { record( "addList", g, triples ); } 30 31 public void notifyAddIterator( Graph g, Iterator it ) 32 { record( "addIterator", g, GraphTestBase.iteratorToList( it ) ); } 33 34 public void notifyAddGraph( Graph g, Graph added ) 35 { record( "addGraph", g, added ); } 36 37 public void notifyDeleteTriple( Graph g, Triple t ) 38 { record( "delete", g, t ); } 39 40 public void notifyDeleteArray( Graph g, Triple [] triples ) 41 { record( "delete[]", g, triples ); } 42 43 public void notifyDeleteList( Graph g, List triples ) 44 { record( "deleteList", g, triples ); } 45 46 public void notifyDeleteIterator( Graph g, Iterator it ) 47 { record( "deleteIterator", g, GraphTestBase.iteratorToList( it ) ); } 48 49 public void notifyDeleteGraph( Graph g, Graph removed ) 50 { record( "deleteGraph", g, removed ); } 51 52 public void notifyEvent( Graph source, Object event ) 53 { record( "someEvent", source, event ); } 54 55 protected void record( String tag, Object x, Object y ) 56 { history.add( tag ); history.add( x ); history.add( y ); } 57 58 protected void record( String tag, Object info ) 59 { history.add( tag ); history.add( info ); } 60 61 public void clear() 62 { history.clear(); } 63 64 public boolean has( List things ) 65 { return history.equals( things ); } 66 67 public boolean hasStart( List L ) 68 { return L.size() <= history.size() && L.equals( history.subList( 0, L.size() ) ); } 69 70 public boolean hasEnd( List L ) 71 { return L.size() <= history.size() && L.equals( history.subList( history.size() - L.size(), history.size() ) ); } 72 73 public boolean has( Object [] things ) 74 { return has( Arrays.asList( things ) ); } 75 76 public void assertHas( List things ) 77 { if (has( things ) == false) Assert.fail( "expected " + things + " but got " + history ); } 78 79 public void assertHas( Object [] things ) 80 { assertHas( Arrays.asList( things ) ); } 81 82 public void assertHasStart( Object [] start ) 83 { 84 List L = Arrays.asList( start ); 85 if (hasStart( L ) == false) Assert.fail( "expected " + L + " at the beginning of " + history ); 86 } 87 88 public void assertHasEnd( Object [] end ) 89 { 90 List L = Arrays.asList( end ); 91 if (hasEnd( L ) == false) Assert.fail( "expected " + L + " at the end of " + history ); 92 } 93 } 94 95 | Popular Tags |