KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > jdbc > CachedSqlTokenizerTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.jdbc;
17
18 import scriptella.AbstractTestCase;
19
20 import java.io.IOException JavaDoc;
21 import java.io.StringReader JavaDoc;
22 import java.util.Arrays JavaDoc;
23
24 /**
25  * Tests for {@link CachedSqlTokenizer}.
26  *
27  * @author Fyodor Kupolov
28  * @version 1.0
29  */

30 public class CachedSqlTokenizerTest extends AbstractTestCase {
31     public void test() throws IOException JavaDoc {
32         SqlTokenizer target = new SqlReaderTokenizer(new StringReader JavaDoc("s1;s2;s3?v"));
33         SqlTokenizer tok = new CachedSqlTokenizer(target);
34         String JavaDoc[] expectedSt = new String JavaDoc[] {"s1", "s2", "s3?v"};
35         int[][] expectedInj = new int[][] {{}, {}, {2}};
36         for (int i=0;i<10000;i++) {
37             for (int j=0;j<3;j++) {
38                 String JavaDoc s = tok.nextStatement();
39                 assertEquals(expectedSt[j], s);
40                 assertTrue(Arrays.equals(expectedInj[j], tok.getInjections()));
41             }
42             assertNull(tok.nextStatement());
43             assertTrue(tok.getInjections().length==0); //Null would be better, but need to fix SqlReaderTokenizer
44
tok.close();
45         }
46     }
47 }
48
Popular Tags