01: /*
02: * FixedSizeListTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import junit.framework.*;
15:
16: /**
17: *
18: * @author support@sql-workbench.net
19: */
20: public class FixedSizeListTest extends TestCase {
21:
22: public FixedSizeListTest(String testName) {
23: super (testName);
24: }
25:
26: public void testList() {
27: try {
28: FixedSizeList<String> list = new FixedSizeList<String>(5);
29: list.addEntry("One");
30: list.addEntry("Two");
31: list.addEntry("Three");
32: list.addEntry("Four");
33: list.addEntry("Five");
34:
35: assertEquals("Wrong size", 5, list.size());
36:
37: list.addEntry("Six");
38: assertEquals("Wrong size", 5, list.size());
39:
40: String firstEntry = list.getFirst();
41: assertEquals("Wrong entry", "Six", firstEntry);
42:
43: // Should put "Three" at the "top"
44: list.addEntry("Three");
45: firstEntry = list.getFirst();
46: assertEquals("Wrong entry", "Three", firstEntry);
47:
48: int index = 0;
49: for (String entry : list.getEntries()) {
50: if (index == 0) {
51: assertEquals("Wrong entry", "Three", entry);
52: } else if (index == 1) {
53: assertEquals("Wrong entry", "Six", entry);
54: } else if (index == 2) {
55: assertEquals("Wrong entry", "Five", entry);
56: } else if (index == 3) {
57: assertEquals("Wrong entry", "Four", entry);
58: } else if (index == 4) {
59: assertEquals("Wrong entry", "Two", entry);
60: }
61: index++;
62: }
63: } catch (Exception e) {
64: e.printStackTrace();
65: fail(e.getMessage());
66: }
67: }
68:
69: }
|