KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > example > test > AccountCleanerTest


1 package sample.example.test;
2
3 import junit.framework.TestCase;
4 import sample.example.*;
5
6 public class AccountCleanerTest extends TestCase {
7     public AccountCleanerTest( String JavaDoc s ) {
8         super(s);
9     }
10 /*
11
12     public void testBalances() {
13
14         // check correct query is used for database.select().
15         DatabaseMock database = new DatabaseMock();
16         database.addExpectedSelectValues( "SELECT account, balance, credit FROM accounts" );
17
18         // return some dummy data from database.select().
19         RowsMock rows = new RowsMock();
20         setupAccountRow( rows, 123, 999, true ); // correct
21         setupAccountRow( rows, 124, -999, false ); // correct
22         setupAccountRow( rows, 125, -1, true ); // should be corrected to false
23         setupAccountRow( rows, 126, 5, false ); // should be corrected to true
24         rows.setupHasNext( false );
25         database.setupSelect( rows );
26
27         // these are the expectations that need to be met to pass the test.
28         database.addExpectedExecuteValues( "UPDATE accounts SET credit = false WHERE account = 125" );
29         database.addExpectedExecuteValues( "UPDATE accounts SET credit = true WHERE account = 126" );
30
31         // execute method to be tested.
32         AccountCleaner cleaner = new AccountCleaner( database );
33         cleaner.fixCreditFlags();
34
35         // check it met our expectations.
36         database.verify();
37
38     }
39
40     private void setupAccountRow( RowsMock rows, long account, long balance, boolean credit ) {
41         rows.setupHasNext( true );
42         rows.setupGetLong( account );
43         rows.setupGetLong( balance );
44         rows.setupGetBoolean( credit );
45     }
46 */

47 }
48
Popular Tags