sis.db.KeyFileTest


 package sis.db; import junit.framework.*; import java.io.*; import java.util.*; import sis.util.*; public class KeyFileTest extends TestCase {    private static final String FILENAME = "keyfiletest.idx";    private static final String KEY = "key";    private static final long POSITION = 1;    private static final int LENGTH = 100;    private KeyFile keyFile;    protected void setUp() throws IOException {       TestUtil.delete(FILENAME);       keyFile = new KeyFile(FILENAME);    }    protected void tearDown() throws IOException {       TestUtil.delete(FILENAME);       keyFile.close();    }    public void testCreate() {       assertEquals(0, keyFile.size());    }    public void testAddEntry()  {       keyFile.add(KEY, POSITION, LENGTH) ;       assertEquals(1, keyFile.size());       assertTrue(keyFile.containsKey(KEY));       assertEquals(POSITION, keyFile.getPosition(KEY));       assertEquals(LENGTH, keyFile.getLength(KEY));    }    public void testReopen() throws IOException {       keyFile.add(KEY, POSITION, LENGTH);       keyFile.close();       keyFile = new KeyFile(FILENAME);       assertEquals(1, keyFile.size());       assertEquals(POSITION, keyFile.getPosition(KEY));       assertEquals(LENGTH, keyFile.getLength(KEY));    } } 

KeyFileTest demonstrates the ability to add keys (unique ids) to a KeyFile. A key is stored with the position of the associated data in the DataFile object as well as with the length of that data. The data position and length can be retrieved from the KeyFile using the unique key.

The third test, testReopen, ensures that you can create a new KeyFile object using the name of an existing key file. The KeyFile object must load the already-persisted key data.



Agile Java. Crafting Code with Test-Driven Development
Agile Javaв„ў: Crafting Code with Test-Driven Development
ISBN: 0131482394
EAN: 2147483647
Year: 2003
Pages: 391
Authors: Jeff Langr

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net