package org.sagebionetworks.repo.manager.table;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.sagebionetworks.repo.manager.table.metadata.MetadataIndexProviderFactory;
import org.sagebionetworks.repo.model.entity.IdAndVersion;
import org.sagebionetworks.table.cluster.ConnectionFactory;
import org.sagebionetworks.table.cluster.TableIndexDAO;
import org.sagebionetworks.table.cluster.metadata.ObjectFieldModelResolverFactory;
import org.sagebionetworks.table.cluster.search.TableRowSearchProcessor;

@ExtendWith(MockitoExtension.class)
public class TableIndexConnectionFactoryImplTest {
	
	@Mock
	private TableIndexDAO mockTableIndexDAO;
	@Mock
	private ConnectionFactory mockDaoConnectionFactory;
	@Mock
	private TableManagerSupport mockManagerSupport;
	@Mock
	private MetadataIndexProviderFactory mockMetaDataIndexProviderFactory;
	@Mock
	private ObjectFieldModelResolverFactory mockObjectFieldModelResolverFactory;
	@Mock
	private TableRowSearchProcessor mockSearchProcessor;
	
	@InjectMocks
	private TableIndexConnectionFactoryImpl indexFactory;
	
	private IdAndVersion tableId;
	
	@BeforeEach
	public void before(){
		tableId = IdAndVersion.parse("syn456");
	}
	
	@Test
	public void testConnectToTableIndex(){
		assertThrows(IllegalArgumentException.class, () -> {
			indexFactory.connectToTableIndex(null);
		});
	}
	
	@Test
	public void testConnectToTableIndexHappy(){
		when(mockDaoConnectionFactory.getConnection(tableId)).thenReturn(mockTableIndexDAO);
		TableIndexManager manager = indexFactory.connectToTableIndex(tableId);
		assertNotNull(manager);
	}
	
	@Test
	public void testConnectToTableUnavailabl(){
		when(mockDaoConnectionFactory.getConnection(tableId)).thenReturn(null);
		
		assertThrows(TableIndexConnectionUnavailableException.class, () -> {
			indexFactory.connectToTableIndex(tableId);
		});
	}
	
	@Test
	public void testGetFirstConnection(){
		when(mockDaoConnectionFactory.getFirstConnection()).thenReturn(mockTableIndexDAO);
		TableIndexManager manager = indexFactory.connectToFirstIndex();
		assertNotNull(manager);
	}

}

@@ -72,28 +72,43 @@
 nit.
+jupiter.api.
 Assert
+ions
 .assert
-NotNull
+Equals
 ;%0D%0Ai
@@ -172,91 +172,8 @@
 s;%0D%0A
-import static org.mockito.Mockito.when;%0D%0A%0D%0Aimport org.junit.jupiter.api.BeforeEach;
 %0D%0Aim
@@ -373,1937 +373,446 @@
 n;%0D%0A
-import org.sagebionetworks.repo.manager.table.metadata.MetadataIndexProviderFactory;%0D%0Aimport org.sagebionetworks.repo.model.entity.IdAndVersion;%0D%0Aimport org.sagebionetworks.table.cluster.ConnectionFactory;%0D%0Aimport org.sagebionetworks.table.cluster.TableIndexDAO;%0D%0Aimport org.sagebionetworks.table.cluster.metadata.ObjectFieldModelResolverFactory;%0D%0Aimport org.sagebionetworks.table.cluster.search.TableRowSearchProcessor;%0D%0A%0D%0A@ExtendWith(MockitoExtension.class)%0D%0Apublic class TableIndexConnectionFactoryImplTest %7B%0D%0A%09%0D%0A%09@Mock%0D%0A%09private TableIndexDAO mockTableIndexDAO;%0D%0A%09@Mock%0D%0A%09private ConnectionFactory mockDaoConnectionFactory;%0D%0A%09@Mock%0D%0A%09private TableManagerSupport mockManagerSupport;%0D%0A%09@Mock%0D%0A%09private MetadataIndexProviderFactory mockMetaDataIndexProviderFactory;%0D%0A%09@Mock%0D%0A%09private ObjectFieldModelResolverFactory mockObjectFieldModelResolverFactory;%0D%0A%09@Mock%0D%0A%09private TableRowSearchProcessor mockSearchProcessor;%0D%0A%09%0D%0A%09@InjectMocks%0D%0A%09private TableIndexConnectionFactoryImpl indexFactory;%0D%0A%09%0D%0A%09private IdAndVersion tableId;%0D%0A%09%0D%0A%09@BeforeEach%0D%0A%09public void before()%7B%0D%0A%09%09tableId = IdAndVersion.parse(%22syn456%22);%0D%0A%09%7D%0D%0A%09%0D%0A%09@Test%0D%0A%09public void testConnectToTableIndex()%7B%0D%0A%09%09assertThrows(IllegalArgumentException.class, () -%3E %7B%0D%0A%09%09%09indexFactory.connectToTableIndex(null);%0D%0A%09%09%7D);%0D%0A%09%7D%0D%0A%09%0D%0A%09@Test%0D%0A%09public void testConnectToTableIndexHappy()%7B%0D%0A%09%09when(mockDaoConnectionFactory.getConnection(tableId)).thenReturn(mockTableIndexDAO);%0D%0A%09%09TableIndexManager manager = indexFactory.connectToTableIndex(tableId);%0D%0A%09%09assertNotNull(manager);%0D%0A%09%7D%0D%0A%09%0D%0A%09@Test%0D%0A%09public void testConnectToTableUnavailabl()%7B%0D%0A%09%09when(mockDaoConnectionFactory.getConnection(tableId)).thenReturn(null);%0D%0A%09%09%0D%0A%09%09assertThrows(TableIndexConnectionUnavailableException.class, () -%3E %7B%0D%0A%09%09%09indexFactory.connectToTableIndex(tableId);%0D%0A%09%09%7D);%0D%0A%09%7D%0D%0A%09%0D%0A%09@Test%0D%0A%09public void testGetFirstConnection()%7B%0D%0A%09%09when(mockDaoConnectionFactory.getFirstConnection()).thenReturn(mockTableIndexDAO);
+%0D%0A@ExtendWith(MockitoExtension.class)%0D%0Apublic class TableIndexConnectionFactoryImplTest %7B%0D%0A%09%0D%0A%09@Mock%0D%0A%09private TableIndexManager mockIndexManager;%0D%0A%09%0D%0A%09@InjectMocks%0D%0A%09private TableIndexConnectionFactoryImpl indexFactory;%0D%0A%09%0D%0A%09%0D%0A%09@Test%0D%0A%09public void testConnectToTableIndex()%7B%0D%0A%09%09assertThrows(IllegalArgumentException.class, () -%3E %7B%0D%0A%09%09%09indexFactory.connectToTableIndex(null);%0D%0A%09%09%7D);%0D%0A%09%7D%0D%0A%09%09%0D%0A%09@Test%0D%0A%09public void testGetFirstConnection()%7B
 %0D%0A%09%09
@@ -888,16 +888,33 @@
 sert
-NotNull(
+Equals(mockIndexManager, 
 mana

test fix