package com.strider.datadefender.database;

import com.strider.datadefender.DbConfig;

import java.sql.Connection;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
 * Using mock to test Connection.
 * @author Akira Matsuo
 */
@ExtendWith(MockitoExtension.class)
public class DbConnectionTest {

    @Mock
    DbConfig config;
    @Mock
    Connection mockConnection;

    @Test
    public void testConnect() throws Exception {
        final DbConnection test = new DbConnection(config) {
            @Override
            public Connection connect() throws DatabaseException {
                return doConnect(() -> mockConnection);
            }
        };
        assertEquals(mockConnection, test.connect());
        verify(mockConnection).setAutoCommit(false);
    }

    @Test
    public void testConnectSupplier() throws Exception {
        when(config.getUrl()).thenReturn("jdbc:h2:mem:utest;MODE=MySQL;DB_CLOSE_DELAY=-1");
        when(config.getUsername()).thenReturn("username");
        when(config.getUsername()).thenReturn("password");

        final DbConnection test = new DbConnection(config);
        final Connection con = test.connect();
        assertNotNull(con);
        assertFalse(con.isClosed());
        assertFalse(con.getAutoCommit());

        verify(config.getUrl(), atLeast(1));
        verify(config.getUsername(), atLeast(1));
        verify(config.getPassword(), atLeast(1));
    }
}

@@ -1486,25 +1486,16 @@
 y(config
-.getUrl()
 , atLeas
@@ -1491,32 +1491,41 @@
 fig, atLeast(1))
+.getUrl()
 ;%0A        verify
@@ -1527,24 +1527,37 @@
 erify(config
+, atLeast(1))
 .getUsername
@@ -1558,29 +1558,16 @@
 ername()
-, atLeast(1))
 ;%0A      
@@ -1577,24 +1577,37 @@
 erify(config
+, atLeast(1))
 .getPassword
@@ -1611,21 +1611,8 @@
 ord(
-), atLeast(1)
 );%0A 

Fix verify