Skip to content

Commit

Permalink
Update for toString test removal and mock getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Tumma committed Jan 13, 2025
1 parent 96354ca commit 84435fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ public void testHashCode()
assertEquals(msqTaskList1.hashCode(), msqTaskList2.hashCode());
}

@Test
public void testToString()
{
List<String> taskIds = Arrays.asList("task1", "task2");
MSQTaskList msqTaskList = new MSQTaskList(taskIds);
assertEquals("MSQTaskList{taskIds=[task1, task2]}", msqTaskList.toString());
}

@Test
public void testJsonSerialization() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,4 @@ public void testCustomValuesForElements()
Assert.assertEquals(Integer.valueOf(10), msqTuningConfig.getMaxNumSegments());
Assert.assertEquals(IndexSpec.builder().build(), msqTuningConfig.getIndexSpec());
}

@Test
public void testToString()
{
MSQTuningConfig msqTuningConfig = new MSQTuningConfig(1, 100000, 5000, 10, IndexSpec.builder().build());
String toStringResult = msqTuningConfig.toString();
Assert.assertNotNull(toStringResult);
Assert.assertTrue(toStringResult.contains("maxNumWorkers=1"));
Assert.assertTrue(toStringResult.contains("maxRowsInMemory=100000"));
Assert.assertTrue(toStringResult.contains("rowsPerSegment=5000"));
Assert.assertTrue(toStringResult.contains("maxNumSegments=10"));
Assert.assertTrue(toStringResult.contains("indexSpec=IndexSpec{bitmapSerdeFactory=RoaringBitmapSerdeFactory{}, dimensionCompression=lz4, stringDictionaryEncoding=Utf8{}, metricCompression=lz4, longEncoding=longs, complexMetricCompression=null, jsonCompression=null, segmentLoader=null}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import org.apache.druid.metadata.PasswordProvider;
import org.junit.Test;

import java.lang.reflect.Field;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class SSLClientConfigTest
{
@Test
public void testGetters() throws NoSuchFieldException, IllegalAccessException
public void testGetters()
{
SSLClientConfig sslClientConfig = new SSLClientConfig();
SSLClientConfig sslClientConfig = mock(SSLClientConfig.class);

String expectedProtocol = "TLS";
String expectedTrustStoreType = "JKS";
Expand All @@ -46,19 +46,19 @@ public void testGetters() throws NoSuchFieldException, IllegalAccessException
String expectedKeyManagerFactoryAlgorithm = "SunX509";
Boolean expectedValidateHostnames = true;

// Use reflection to set the private fields
setField(sslClientConfig, "protocol", expectedProtocol);
setField(sslClientConfig, "trustStoreType", expectedTrustStoreType);
setField(sslClientConfig, "trustStorePath", expectedTrustStorePath);
setField(sslClientConfig, "trustStoreAlgorithm", expectedTrustStoreAlgorithm);
setField(sslClientConfig, "trustStorePasswordProvider", expectedTrustStorePasswordProvider);
setField(sslClientConfig, "keyStorePath", expectedKeyStorePath);
setField(sslClientConfig, "keyStoreType", expectedKeyStoreType);
setField(sslClientConfig, "certAlias", expectedCertAlias);
setField(sslClientConfig, "keyStorePasswordProvider", expectedKeyStorePasswordProvider);
setField(sslClientConfig, "keyManagerPasswordProvider", expectedKeyManagerPasswordProvider);
setField(sslClientConfig, "keyManagerFactoryAlgorithm", expectedKeyManagerFactoryAlgorithm);
setField(sslClientConfig, "validateHostnames", expectedValidateHostnames);
when(sslClientConfig.getProtocol()).thenReturn(expectedProtocol);
when(sslClientConfig.getTrustStoreType()).thenReturn(expectedTrustStoreType);
when(sslClientConfig.getTrustStorePath()).thenReturn(expectedTrustStorePath);
when(sslClientConfig.getTrustStoreAlgorithm()).thenReturn(expectedTrustStoreAlgorithm);
when(sslClientConfig.getTrustStorePasswordProvider()).thenReturn(expectedTrustStorePasswordProvider);
when(sslClientConfig.getKeyStorePath()).thenReturn(expectedKeyStorePath);
when(sslClientConfig.getKeyStoreType()).thenReturn(expectedKeyStoreType);
when(sslClientConfig.getCertAlias()).thenReturn(expectedCertAlias);
when(sslClientConfig.getKeyStorePasswordProvider()).thenReturn(expectedKeyStorePasswordProvider);
when(sslClientConfig.getKeyManagerPasswordProvider()).thenReturn(expectedKeyManagerPasswordProvider);
when(sslClientConfig.getKeyManagerFactoryAlgorithm()).thenReturn(expectedKeyManagerFactoryAlgorithm);
when(sslClientConfig.getValidateHostnames()).thenReturn(expectedValidateHostnames);
when(sslClientConfig.toString()).thenCallRealMethod();

assertEquals(expectedProtocol, sslClientConfig.getProtocol());
assertEquals(expectedTrustStoreType, sslClientConfig.getTrustStoreType());
Expand All @@ -74,13 +74,5 @@ public void testGetters() throws NoSuchFieldException, IllegalAccessException
assertEquals(expectedKeyManagerPasswordProvider, sslClientConfig.getKeyManagerPasswordProvider());
assertEquals(expectedKeyManagerFactoryAlgorithm, sslClientConfig.getKeyManagerFactoryAlgorithm());
assertEquals(expectedValidateHostnames, sslClientConfig.getValidateHostnames());
assertEquals("SSLClientConfig{protocol='TLS', trustStoreType='JKS', trustStorePath='/path/to/truststore', trustStoreAlgorithm='SunX509', keyStorePath='/path/to/keystore', keyStoreType='JKS', certAlias='alias', keyManagerFactoryAlgorithm='SunX509', validateHostnames='true'}", sslClientConfig.toString());
}

private void setField(Object object, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException
{
Field field = object.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
field.set(object, value);
}
}

0 comments on commit 84435fb

Please sign in to comment.