Search in sources :

Example 1 with StubStatement

use of com.zaxxer.hikari.mocks.StubStatement in project HikariCP by brettwooldridge.

the class TestFastList method testAddRemoveTail.

@Test
public void testAddRemoveTail() {
    ArrayList<Statement> verifyList = new ArrayList<>();
    FastList<Statement> list = new FastList<>(Statement.class);
    for (int i = 0; i < 32; i++) {
        StubStatement statement = new StubStatement(null);
        list.add(statement);
        verifyList.add(statement);
    }
    for (int i = 31; i >= 0; i--) {
        assertNotNull("Element " + i, list.get(i));
        int size = list.size();
        list.remove(verifyList.get(i));
        assertSame(size - 1, list.size());
    }
}
Also used : Statement(java.sql.Statement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with StubStatement

use of com.zaxxer.hikari.mocks.StubStatement in project HikariCP by brettwooldridge.

the class TestFastList method testAddRemove.

@Test
public void testAddRemove() {
    ArrayList<Statement> verifyList = new ArrayList<>();
    FastList<Statement> list = new FastList<>(Statement.class);
    for (int i = 0; i < 32; i++) {
        StubStatement statement = new StubStatement(null);
        list.add(statement);
        verifyList.add(statement);
    }
    for (int i = 0; i < 32; i++) {
        assertNotNull("Element " + i + " was null but should be " + verifyList.get(i), list.get(0));
        int size = list.size();
        list.remove(verifyList.get(i));
        assertSame(size - 1, list.size());
    }
}
Also used : Statement(java.sql.Statement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with StubStatement

use of com.zaxxer.hikari.mocks.StubStatement in project HikariCP by brettwooldridge.

the class TestFastList method testRemoveLast.

@Test
public void testRemoveLast() {
    FastList<Statement> list = new FastList<>(Statement.class);
    Statement last = null;
    for (int i = 0; i < 100; i++) {
        StubStatement statement = new StubStatement(null);
        list.add(statement);
        last = statement;
    }
    assertEquals(last, list.removeLast());
    assertEquals(99, list.size());
}
Also used : Statement(java.sql.Statement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) Test(org.junit.Test)

Example 4 with StubStatement

use of com.zaxxer.hikari.mocks.StubStatement in project HikariCP by brettwooldridge.

the class TestFastList method testClear.

@Test
public void testClear() {
    FastList<Statement> list = new FastList<>(Statement.class);
    for (int i = 0; i < 100; i++) {
        StubStatement statement = new StubStatement(null);
        list.add(statement);
    }
    assertNotEquals(0, list.size());
    list.clear();
    assertEquals(0, list.size());
    // also check that all elements are now null
    for (int i = 0; i < 100; i++) {
        assertEquals(null, list.get(i));
    }
}
Also used : Statement(java.sql.Statement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) Test(org.junit.Test)

Example 5 with StubStatement

use of com.zaxxer.hikari.mocks.StubStatement in project HikariCP by brettwooldridge.

the class TestFastList method testIterator.

@Test
public void testIterator() {
    FastList<Statement> list = new FastList<>(Statement.class);
    for (int i = 0; i < 100; i++) {
        StubStatement statement = new StubStatement(null);
        list.add(statement);
    }
    Iterator<Statement> iter = list.iterator();
    for (int i = 0; i < list.size(); i++) {
        assertSame(list.get(i), iter.next());
    }
}
Also used : Statement(java.sql.Statement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) StubStatement(com.zaxxer.hikari.mocks.StubStatement) Test(org.junit.Test)

Aggregations

StubStatement (com.zaxxer.hikari.mocks.StubStatement)7 Test (org.junit.Test)7 Statement (java.sql.Statement)6 ArrayList (java.util.ArrayList)3 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 StubConnection (com.zaxxer.hikari.mocks.StubConnection)1 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1