001         package com.croftsoft.core.util.queue;
002    
003         import com.croftsoft.core.lang.NullArgumentException;
004         import com.croftsoft.core.lang.Testable;
005    
006         /*********************************************************************
007         * Black box testing of Queue implementations.
008         *
009         * @author
010         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
011         * @version
012         *   2003-05-22
013         * @since
014         *   2003-05-22
015         *********************************************************************/
016    
017         public final class  QueueTest
018           implements Testable
019         //////////////////////////////////////////////////////////////////////
020         //////////////////////////////////////////////////////////////////////
021         {
022    
023         public static void  main ( String [ ]  args )
024         //////////////////////////////////////////////////////////////////////
025         {
026           System.out.println ( test ( args ) );
027         }
028    
029         public static boolean  test ( String [ ]  args )
030         //////////////////////////////////////////////////////////////////////
031         {
032           try
033           {
034             if ( !test ( new ListQueue ( ) ) )
035             {
036               return false;
037             }
038    
039             if ( !test ( new VectorQueue ( ) ) )
040             {
041               return false;
042             }
043           }
044           catch ( Exception  ex )
045           {
046             ex.printStackTrace ( );
047    
048             return false;
049           }
050    
051           return true;
052         }
053    
054         public static boolean  test ( Queue  queue )
055         //////////////////////////////////////////////////////////////////////
056         {
057           NullArgumentException.check ( queue );
058    
059           try
060           {
061             Object  object = null;
062    
063             System.out.println ( "Empty queue pull with 3 second timeout" );
064    
065             object = queue.pull ( 3000 );
066    
067             if ( object != null )
068             {
069               return false;
070             }
071    
072             System.out.println ( "Empty queue poll" );
073    
074             object = queue.poll ( );
075    
076             if ( object != null )
077             {
078               return false;
079             }
080    
081             System.out.println ( "Non-empty queue pull" );
082    
083             if ( !queue.append ( new Object ( ) ) )
084             {
085               return false;
086             }
087    
088             object = queue.pull ( );
089    
090             if ( object == null )
091             {
092               return false;
093             }
094    
095             System.out.println ( "Queue replace" );
096    
097             queue.replace ( new String ( "test" ) );
098    
099             queue.replace ( new String ( "test" ) );
100    
101             object = queue.pull ( );
102    
103             if ( object == null )
104             {
105               return false;
106             }
107    
108             object = queue.poll ( );
109    
110             if ( object != null )
111             {
112               return false;
113             }
114    
115             System.out.println ( "Negative timeout argument" );
116    
117             boolean  passed = false;
118    
119             try
120             {
121               queue.pull ( -1 );
122             }
123             catch ( IllegalArgumentException  ex )
124             {
125               passed = true;
126             }
127    
128             if ( !passed )
129             {
130               return false;
131             }
132           }
133           catch ( Exception  ex )
134           {
135             ex.printStackTrace ( );
136    
137             return false;
138           }
139    
140           return true;
141         }
142    
143         //////////////////////////////////////////////////////////////////////
144         //////////////////////////////////////////////////////////////////////
145    
146         private  QueueTest ( ) { }
147    
148         //////////////////////////////////////////////////////////////////////
149         //////////////////////////////////////////////////////////////////////
150         }