From 89a84c871dc3f5c7c86981e1ad06abf7188192c6 Mon Sep 17 00:00:00 2001 From: Joseph Grogan Date: Tue, 19 May 2026 14:39:51 -0400 Subject: [PATCH] Various test clean up --- config/spotbugs/exclude.xml | 10 ++ .../hoptimator/PendingDeleteTest.java | 5 +- .../avro/AvroTableValidatorTest.java | 19 ++-- .../jdbc/HoptimatorDatabaseMetaDataTest.java | 78 ++++++-------- .../jdbc/HoptimatorDdlUtilsTest.java | 14 +-- .../k8s/K8sApiErrorResponseTest.java | 8 +- .../hoptimator/k8s/K8sConnectorTest.java | 3 +- .../hoptimator/k8s/K8sContextTest.java | 5 +- .../hoptimator/k8s/K8sDatabaseTableTest.java | 1 - .../k8s/K8sValidatorProviderTest.java | 3 +- .../hoptimator/k8s/K8sYamlApiTest.java | 34 +++--- .../kafka/KafkaTopicReconcilerTest.java | 6 +- .../hoptimator/kafka/KafkaDeployerTest.java | 100 ++++++++---------- .../logical/LogicalTableDeployerTest.java | 5 +- .../mcp/server/HoptimatorMcpServerTest.java | 30 ++---- .../hoptimator/mysql/MySqlDriverTest.java | 3 +- .../pipeline/PipelineReconcilerTest.java | 6 +- .../SubscriptionReconcilerTest.java | 57 +++++----- .../trigger/TableTriggerReconcilerTest.java | 6 +- .../operator/trigger/ViewReconcilerTest.java | 6 +- .../util/planner/HoptimatorJdbcTableTest.java | 4 +- .../hoptimator/venice/VeniceStoreTest.java | 3 +- 22 files changed, 191 insertions(+), 215 deletions(-) diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index 152a1884..5f0e63f5 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -27,4 +27,14 @@ + + + + + + diff --git a/hoptimator-api/src/test/java/com/linkedin/hoptimator/PendingDeleteTest.java b/hoptimator-api/src/test/java/com/linkedin/hoptimator/PendingDeleteTest.java index 99abc023..4a711dae 100644 --- a/hoptimator-api/src/test/java/com/linkedin/hoptimator/PendingDeleteTest.java +++ b/hoptimator-api/src/test/java/com/linkedin/hoptimator/PendingDeleteTest.java @@ -2,6 +2,9 @@ import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Map; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -77,7 +80,7 @@ void toStringOmitsSelfOwnerWhenOnlyOneFieldSet() { @Test void targetGenericTypeIsPreserved() { - Source source = new Source("db", java.util.List.of("schema", "tbl"), java.util.Map.of()); + Source source = new Source("db", List.of("schema", "tbl"), Map.of()); PendingDelete pd = new PendingDelete<>(source); Source unwrapped = pd.target(); assertEquals("tbl", unwrapped.table()); diff --git a/hoptimator-avro/src/test/java/com/linkedin/hoptimator/avro/AvroTableValidatorTest.java b/hoptimator-avro/src/test/java/com/linkedin/hoptimator/avro/AvroTableValidatorTest.java index b843bf96..233968e3 100644 --- a/hoptimator-avro/src/test/java/com/linkedin/hoptimator/avro/AvroTableValidatorTest.java +++ b/hoptimator-avro/src/test/java/com/linkedin/hoptimator/avro/AvroTableValidatorTest.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -90,11 +91,10 @@ protected Map getTableMap() { CalciteSchema calciteSchema = CalciteSchema.createRootSchema(false, false, "root", innerSchema); // Mock the SchemaPlus: tables() returns newTable; unwrap returns the CalciteSchema with originalTable - @SuppressWarnings("unchecked") - Lookup tableLookup = mock(Lookup.class); - when(tableLookup.getNames(any())).thenReturn(Set.of("MY_TABLE")); - when(tableLookup.get("MY_TABLE")).thenReturn(newTable); - when(schema.tables()).thenReturn(tableLookup); + Lookup tableLookup = mock(Lookup.class); + doReturn(Set.of("MY_TABLE")).when(tableLookup).getNames(any()); + doReturn(newTable).when(tableLookup).get("MY_TABLE"); + doReturn(tableLookup).when(schema).tables(); when(schema.unwrap(CalciteSchema.class)).thenReturn(calciteSchema); AvroTableValidator validator = new AvroTableValidator(schema); @@ -128,11 +128,10 @@ protected Map getTableMap() { }; CalciteSchema calciteSchema = CalciteSchema.createRootSchema(false, false, "root", innerSchema); - @SuppressWarnings("unchecked") - Lookup
tableLookup = mock(Lookup.class); - when(tableLookup.getNames(any())).thenReturn(Set.of("MY_TABLE")); - when(tableLookup.get("MY_TABLE")).thenReturn(sameTable); - when(schema.tables()).thenReturn(tableLookup); + Lookup tableLookup = mock(Lookup.class); + doReturn(Set.of("MY_TABLE")).when(tableLookup).getNames(any()); + doReturn(sameTable).when(tableLookup).get("MY_TABLE"); + doReturn(tableLookup).when(schema).tables(); when(schema.unwrap(CalciteSchema.class)).thenReturn(calciteSchema); AvroTableValidator validator = new AvroTableValidator(schema); diff --git a/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDatabaseMetaDataTest.java b/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDatabaseMetaDataTest.java index bda62b41..e15c50f9 100644 --- a/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDatabaseMetaDataTest.java +++ b/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDatabaseMetaDataTest.java @@ -155,7 +155,6 @@ void testGetSchemasWithSchemaPatternFiltersNonMatching() throws SQLException { } @Test - @SuppressWarnings("unchecked") void testGetSchemasExpandsCatalogWhenSchemaNull() throws SQLException { ResultSet mockRs = mock(ResultSet.class); when(mockRs.next()).thenReturn(true, false); @@ -168,13 +167,13 @@ void testGetSchemasExpandsCatalogWhenSchemaNull() throws SQLException { when(mockPreparedStatement.executeQuery()).thenReturn(mockRs); SchemaPlus mockRootSchema = mock(SchemaPlus.class); - Lookup mockRootSubSchemas = mock(Lookup.class); + Lookup mockRootSubSchemas = mock(Lookup.class); SchemaPlus mockCatalogSchema = mock(SchemaPlus.class); - Lookup mockCatalogSubSchemas = mock(Lookup.class); + Lookup mockCatalogSubSchemas = mock(Lookup.class); when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema); doReturn(mockRootSubSchemas).when(mockRootSchema).subSchemas(); - when(mockRootSubSchemas.get("myCatalog")).thenReturn(mockCatalogSchema); + doReturn(mockCatalogSchema).when(mockRootSubSchemas).get("myCatalog"); doReturn(mockCatalogSubSchemas).when(mockCatalogSchema).subSchemas(); doReturn(Set.of("subSchema1")).when(mockCatalogSubSchemas).getNames(any()); @@ -187,7 +186,6 @@ void testGetSchemasExpandsCatalogWhenSchemaNull() throws SQLException { } @Test - @SuppressWarnings("unchecked") void testGetSchemasExpandsCatalogWithNullSubSchema() throws SQLException { ResultSet mockRs = mock(ResultSet.class); when(mockRs.next()).thenReturn(true, false); @@ -199,11 +197,11 @@ void testGetSchemasExpandsCatalogWithNullSubSchema() throws SQLException { when(mockPreparedStatement.executeQuery()).thenReturn(mockRs); SchemaPlus mockRootSchema = mock(SchemaPlus.class); - Lookup mockRootSubSchemas = mock(Lookup.class); + Lookup mockRootSubSchemas = mock(Lookup.class); when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema); doReturn(mockRootSubSchemas).when(mockRootSchema).subSchemas(); - when(mockRootSubSchemas.get("missingCatalog")).thenReturn(null); + doReturn(null).when(mockRootSubSchemas).get("missingCatalog"); ResultSet rs = metaData.getSchemas(null, null); @@ -265,7 +263,6 @@ void testGetSchemasWithCatalogFiltersSetsParameter() throws SQLException { } @Test - @SuppressWarnings("unchecked") void testGetTablesReturnsResultSet() throws SQLException { // Mock getSchemas to return one schema row ResultSet mockSchemaRs = mock(ResultSet.class); @@ -281,20 +278,20 @@ void testGetTablesReturnsResultSet() throws SQLException { SchemaPlus mockRootSchema = mock(SchemaPlus.class); SchemaPlus mockCatalogSchema = mock(SchemaPlus.class); SchemaPlus mockDbSchema = mock(SchemaPlus.class); - Lookup mockRootSubSchemas = mock(Lookup.class); - Lookup mockCatSubSchemas = mock(Lookup.class); - Lookup
mockTablesLookup = mock(Lookup.class); + Lookup mockRootSubSchemas = mock(Lookup.class); + Lookup mockCatSubSchemas = mock(Lookup.class); + Lookup mockTablesLookup = mock(Lookup.class); when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema); doReturn(mockRootSubSchemas).when(mockRootSchema).subSchemas(); - when(mockRootSubSchemas.get("myCat")).thenReturn(mockCatalogSchema); + doReturn(mockCatalogSchema).when(mockRootSubSchemas).get("myCat"); doReturn(mockCatSubSchemas).when(mockCatalogSchema).subSchemas(); - when(mockCatSubSchemas.get("mySchema")).thenReturn(mockDbSchema); + doReturn(mockDbSchema).when(mockCatSubSchemas).get("mySchema"); doReturn(mockTablesLookup).when(mockDbSchema).tables(); doReturn(Set.of("table1")).when(mockTablesLookup).getNames(any()); Table mockTable = mock(Table.class); - when(mockTablesLookup.get("table1")).thenReturn(mockTable); + doReturn(mockTable).when(mockTablesLookup).get("table1"); when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.TABLE); ResultSet rs = metaData.getTables("myCat", "mySchema", null, null); @@ -308,7 +305,6 @@ void testGetTablesReturnsResultSet() throws SQLException { } @Test - @SuppressWarnings("unchecked") void testGetTablesWithTypeFilter() throws SQLException { ResultSet mockSchemaRs = mock(ResultSet.class); when(mockSchemaRs.next()).thenReturn(true, false); @@ -322,20 +318,20 @@ void testGetTablesWithTypeFilter() throws SQLException { SchemaPlus mockRootSchema = mock(SchemaPlus.class); SchemaPlus mockCatalogSchema = mock(SchemaPlus.class); SchemaPlus mockDbSchema = mock(SchemaPlus.class); - Lookup mockRootSub = mock(Lookup.class); - Lookup mockCatSub = mock(Lookup.class); - Lookup
mockTables = mock(Lookup.class); + Lookup mockRootSub = mock(Lookup.class); + Lookup mockCatSub = mock(Lookup.class); + Lookup mockTables = mock(Lookup.class); when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema); doReturn(mockRootSub).when(mockRootSchema).subSchemas(); - when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema); + doReturn(mockCatalogSchema).when(mockRootSub).get("cat"); doReturn(mockCatSub).when(mockCatalogSchema).subSchemas(); - when(mockCatSub.get("sch")).thenReturn(mockDbSchema); + doReturn(mockDbSchema).when(mockCatSub).get("sch"); doReturn(mockTables).when(mockDbSchema).tables(); doReturn(Set.of("t1")).when(mockTables).getNames(any()); Table mockTable = mock(Table.class); - when(mockTables.get("t1")).thenReturn(mockTable); + doReturn(mockTable).when(mockTables).get("t1"); when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.VIEW); // Filter by TABLE type only - should exclude VIEW @@ -346,7 +342,6 @@ void testGetTablesWithTypeFilter() throws SQLException { } @Test - @SuppressWarnings("unchecked") void testGetTablesWithMatchingTypeFilter() throws SQLException { ResultSet mockSchemaRs = mock(ResultSet.class); when(mockSchemaRs.next()).thenReturn(true, false); @@ -360,20 +355,20 @@ void testGetTablesWithMatchingTypeFilter() throws SQLException { SchemaPlus mockRootSchema = mock(SchemaPlus.class); SchemaPlus mockCatalogSchema = mock(SchemaPlus.class); SchemaPlus mockDbSchema = mock(SchemaPlus.class); - Lookup mockRootSub = mock(Lookup.class); - Lookup mockCatSub = mock(Lookup.class); - Lookup
mockTables = mock(Lookup.class); + Lookup mockRootSub = mock(Lookup.class); + Lookup mockCatSub = mock(Lookup.class); + Lookup mockTables = mock(Lookup.class); when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema); doReturn(mockRootSub).when(mockRootSchema).subSchemas(); - when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema); + doReturn(mockCatalogSchema).when(mockRootSub).get("cat"); doReturn(mockCatSub).when(mockCatalogSchema).subSchemas(); - when(mockCatSub.get("sch")).thenReturn(mockDbSchema); + doReturn(mockDbSchema).when(mockCatSub).get("sch"); doReturn(mockTables).when(mockDbSchema).tables(); doReturn(Set.of("t1")).when(mockTables).getNames(any()); Table mockTable = mock(Table.class); - when(mockTables.get("t1")).thenReturn(mockTable); + doReturn(mockTable).when(mockTables).get("t1"); when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.TABLE); // Filter by TABLE type - should include @@ -447,7 +442,6 @@ void testGetSchemasWithWildcardPatternMatchesAll() throws SQLException { } @Test - @SuppressWarnings("unchecked") void testGetTablesWithViewTypeFilterIncludesViewExcludesTable() throws SQLException { // Tests that types=["VIEW"] only returns view tables ResultSet mockSchemaRs = mock(ResultSet.class); @@ -462,20 +456,20 @@ void testGetTablesWithViewTypeFilterIncludesViewExcludesTable() throws SQLExcept SchemaPlus mockRootSchema = mock(SchemaPlus.class); SchemaPlus mockCatalogSchema = mock(SchemaPlus.class); SchemaPlus mockDbSchema = mock(SchemaPlus.class); - Lookup mockRootSub = mock(Lookup.class); - Lookup mockCatSub = mock(Lookup.class); - Lookup
mockTables = mock(Lookup.class); + Lookup mockRootSub = mock(Lookup.class); + Lookup mockCatSub = mock(Lookup.class); + Lookup mockTables = mock(Lookup.class); when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema); doReturn(mockRootSub).when(mockRootSchema).subSchemas(); - when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema); + doReturn(mockCatalogSchema).when(mockRootSub).get("cat"); doReturn(mockCatSub).when(mockCatalogSchema).subSchemas(); - when(mockCatSub.get("sch")).thenReturn(mockDbSchema); + doReturn(mockDbSchema).when(mockCatSub).get("sch"); doReturn(mockTables).when(mockDbSchema).tables(); doReturn(Set.of("v1")).when(mockTables).getNames(any()); Table mockView = mock(Table.class); - when(mockTables.get("v1")).thenReturn(mockView); + doReturn(mockView).when(mockTables).get("v1"); when(mockView.getJdbcTableType()).thenReturn(Schema.TableType.VIEW); // Filter by VIEW — should include the view @@ -489,7 +483,6 @@ void testGetTablesWithViewTypeFilterIncludesViewExcludesTable() throws SQLExcept } @Test - @SuppressWarnings("unchecked") void testGetTablesSchemaPatternFiltersNonMatchingSchemas() throws SQLException { // Tests that non-matching schemaPattern yields empty result ResultSet mockSchemaRs = mock(ResultSet.class); @@ -506,7 +499,6 @@ void testGetTablesSchemaPatternFiltersNonMatchingSchemas() throws SQLException { } @Test - @SuppressWarnings("unchecked") void testGetTablesWithNullTypesIncludesBothTablesAndViews() throws SQLException { // types=null means all types — tests the `types != null && types.length > 0` condition ResultSet mockSchemaRs = mock(ResultSet.class); @@ -521,20 +513,20 @@ void testGetTablesWithNullTypesIncludesBothTablesAndViews() throws SQLException SchemaPlus mockRootSchema = mock(SchemaPlus.class); SchemaPlus mockCatalogSchema = mock(SchemaPlus.class); SchemaPlus mockDbSchema = mock(SchemaPlus.class); - Lookup mockRootSub = mock(Lookup.class); - Lookup mockCatSub = mock(Lookup.class); - Lookup
mockTables = mock(Lookup.class); + Lookup mockRootSub = mock(Lookup.class); + Lookup mockCatSub = mock(Lookup.class); + Lookup mockTables = mock(Lookup.class); when(mockCalciteConnection.getRootSchema()).thenReturn(mockRootSchema); doReturn(mockRootSub).when(mockRootSchema).subSchemas(); - when(mockRootSub.get("cat")).thenReturn(mockCatalogSchema); + doReturn(mockCatalogSchema).when(mockRootSub).get("cat"); doReturn(mockCatSub).when(mockCatalogSchema).subSchemas(); - when(mockCatSub.get("sch")).thenReturn(mockDbSchema); + doReturn(mockDbSchema).when(mockCatSub).get("sch"); doReturn(mockTables).when(mockDbSchema).tables(); doReturn(Set.of("t1")).when(mockTables).getNames(any()); Table mockTable = mock(Table.class); - when(mockTables.get("t1")).thenReturn(mockTable); + doReturn(mockTable).when(mockTables).get("t1"); when(mockTable.getJdbcTableType()).thenReturn(Schema.TableType.VIEW); // types=null — VIEW should still be included diff --git a/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDdlUtilsTest.java b/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDdlUtilsTest.java index 29a11973..703bf656 100644 --- a/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDdlUtilsTest.java +++ b/hoptimator-jdbc/src/test/java/com/linkedin/hoptimator/jdbc/HoptimatorDdlUtilsTest.java @@ -1,5 +1,6 @@ package com.linkedin.hoptimator.jdbc; +import com.linkedin.hoptimator.Database; import com.linkedin.hoptimator.Deployer; import com.linkedin.hoptimator.Job; import com.linkedin.hoptimator.Pipeline; @@ -9,6 +10,7 @@ import com.linkedin.hoptimator.jdbc.ddl.SqlCreateDatabase; import com.linkedin.hoptimator.jdbc.ddl.SqlCreateMaterializedView; import com.linkedin.hoptimator.jdbc.ddl.SqlCreateTable; +import com.linkedin.hoptimator.util.planner.HoptimatorJdbcTable; import com.linkedin.hoptimator.util.planner.PipelineRel; import org.apache.calcite.jdbc.CalcitePrepare; import org.apache.calcite.jdbc.CalciteSchema; @@ -1189,8 +1191,7 @@ void processCreateMaterializedViewThrowsWhenOverwritingHoptimatorJdbcTable() thr .add("TEST_JDBC_DB", new TestDatabaseSchema("test-jdbc-db")); // Create a mock HoptimatorJdbcTable and register it - com.linkedin.hoptimator.util.planner.HoptimatorJdbcTable jdbcTable = - mock(com.linkedin.hoptimator.util.planner.HoptimatorJdbcTable.class); + HoptimatorJdbcTable jdbcTable = mock(HoptimatorJdbcTable.class); jdbcDbSchema.add("physicalTable", jdbcTable); // replace=false, ifNotExists=false, but we're trying to overwrite a HoptimatorJdbcTable @@ -1592,8 +1593,7 @@ void specifyFromSqlForCreateDatabaseReturnsEmptySpecsWhenNoDeployersRegistered() } } - static class TestDatabaseSchema extends AbstractSchema - implements com.linkedin.hoptimator.Database { + static class TestDatabaseSchema extends AbstractSchema implements Database { private final String name; TestDatabaseSchema(String name) { @@ -1628,7 +1628,7 @@ void removeTableFromSchemaRemovesFromRootWhenNoSchema() throws SQLException { HoptimatorDdlUtils.removeTableFromSchema(connection, null, null, "ROOT_TMP"); - assertEquals(null, rootSchema.tables().get("ROOT_TMP")); + assertNull(rootSchema.tables().get("ROOT_TMP")); } } @@ -1649,7 +1649,7 @@ void removeTableFromSchemaRemovesFromTierSchema() throws SQLException { HoptimatorDdlUtils.removeTableFromSchema(connection, null, "KAFKA", "my_topic"); - assertEquals(null, tierSchema.tables().get("my_topic")); + assertNull(tierSchema.tables().get("my_topic")); } } @@ -1669,7 +1669,7 @@ void removeTableFromSchemaRemovesFromCatalogAndSchema() throws SQLException { HoptimatorDdlUtils.removeTableFromSchema(connection, "CAT", "DB", "t"); - assertEquals(null, dbSchema.tables().get("t")); + assertNull(dbSchema.tables().get("t")); } } diff --git a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sApiErrorResponseTest.java b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sApiErrorResponseTest.java index ff9cd7f9..117e0d88 100644 --- a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sApiErrorResponseTest.java +++ b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sApiErrorResponseTest.java @@ -16,6 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -78,16 +79,15 @@ void deleteThrowsWhenResponseIsErrorStatus() throws ApiException { } @Test - @SuppressWarnings("unchecked") void updateThrowsWhenResponseIsErrorStatusOnFinalUpdate() throws ApiException { V1alpha1Pipeline pipeline = makePipeline("bad-pipeline", "test-ns"); V1alpha1Pipeline existing = makePipeline("bad-pipeline", "test-ns"); existing.getMetadata().setResourceVersion("rv1"); - KubernetesApiResponse existingResp = mock(KubernetesApiResponse.class); + KubernetesApiResponse existingResp = mock(KubernetesApiResponse.class); when(existingResp.isSuccess()).thenReturn(true); - when(existingResp.getObject()).thenReturn(existing); - when(mockErrApi.get(eq("test-ns"), eq("bad-pipeline"))).thenReturn(existingResp); + doReturn(existing).when(existingResp).getObject(); + doReturn(existingResp).when(mockErrApi).get(eq("test-ns"), eq("bad-pipeline")); ApiException apiEx = new ApiException(500, "Internal Server Error"); when(mockErrApi.update(any(V1alpha1Pipeline.class))).thenReturn(mockErrResponse); diff --git a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sConnectorTest.java b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sConnectorTest.java index 422bf7b7..82e89239 100644 --- a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sConnectorTest.java +++ b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sConnectorTest.java @@ -18,6 +18,7 @@ import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.schema.SchemaPlus; import org.apache.calcite.schema.Table; +import org.apache.calcite.schema.impl.AbstractSchema; import org.apache.calcite.schema.impl.AbstractTable; import org.apache.calcite.sql.type.SqlTypeFactoryImpl; import org.apache.calcite.sql.type.SqlTypeName; @@ -422,7 +423,7 @@ private void installRootSchemaWithTable(Source source, Table table) { SchemaPlus root = CalciteSchema.createRootSchema(false).plus(); SchemaPlus parent = root; for (String part : source.path().subList(0, source.path().size() - 1)) { - parent = parent.add(part, new org.apache.calcite.schema.impl.AbstractSchema()); + parent = parent.add(part, new AbstractSchema()); } parent.add(source.table(), table); diff --git a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sContextTest.java b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sContextTest.java index 1a8970ef..4082b436 100644 --- a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sContextTest.java +++ b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sContextTest.java @@ -1,6 +1,7 @@ package com.linkedin.hoptimator.k8s; import com.linkedin.hoptimator.jdbc.HoptimatorConnection; +import com.linkedin.hoptimator.k8s.models.V1alpha1View; import io.kubernetes.client.informer.SharedInformerFactory; import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.models.V1ObjectMeta; @@ -172,7 +173,7 @@ void ownWithNonDynamicKubernetesObject() { K8sContext owned = context.withOwner(owner); // Use a non-DynamicKubernetesObject (V1alpha1View) - com.linkedin.hoptimator.k8s.models.V1alpha1View view = new com.linkedin.hoptimator.k8s.models.V1alpha1View(); + V1alpha1View view = new V1alpha1View(); view.setMetadata(new V1ObjectMeta().name("test-view").namespace("ns")); owned.own(view); @@ -188,7 +189,7 @@ void ownNonDynamicObjectDoesNotDuplicate() { .kind("View").apiVersion("hoptimator.linkedin.com/v1alpha1"); K8sContext owned = context.withOwner(owner); - com.linkedin.hoptimator.k8s.models.V1alpha1View view = new com.linkedin.hoptimator.k8s.models.V1alpha1View(); + V1alpha1View view = new V1alpha1View(); List existing = new ArrayList<>(); existing.add(new V1OwnerReference().name("owner").uid("uid-789")); view.setMetadata(new V1ObjectMeta().name("test-view").namespace("ns").ownerReferences(existing)); diff --git a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sDatabaseTableTest.java b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sDatabaseTableTest.java index 5a12c1d5..fd2d14b0 100644 --- a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sDatabaseTableTest.java +++ b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sDatabaseTableTest.java @@ -274,7 +274,6 @@ void addDatabasesWithNoCatalog() throws Exception { assertNotNull(root.subSchemas().get("TESTSCH")); } - @SuppressWarnings("unchecked") @Test void addDatabasesWithCatalog() throws Exception { List databases = new ArrayList<>(); diff --git a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sValidatorProviderTest.java b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sValidatorProviderTest.java index 52372e6b..0b4efdfc 100644 --- a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sValidatorProviderTest.java +++ b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sValidatorProviderTest.java @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; @@ -18,7 +19,7 @@ class K8sValidatorProviderTest { private static Source testSource() { - return new Source("kafka1", java.util.List.of("KAFKA", "my-topic"), Map.of()); + return new Source("kafka1", List.of("KAFKA", "my-topic"), Map.of()); } @Test diff --git a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sYamlApiTest.java b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sYamlApiTest.java index d640d7da..c903269a 100644 --- a/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sYamlApiTest.java +++ b/hoptimator-k8s/src/test/java/com/linkedin/hoptimator/k8s/K8sYamlApiTest.java @@ -90,18 +90,16 @@ class RealMethodTests { @Mock private K8sContext mockContext; - @SuppressWarnings("unchecked") - private KubernetesApiResponse successResponse(DynamicKubernetesObject obj) { - KubernetesApiResponse resp = mock(KubernetesApiResponse.class); + private KubernetesApiResponse successResponse(DynamicKubernetesObject obj) { + KubernetesApiResponse resp = mock(KubernetesApiResponse.class); lenient().when(resp.isSuccess()).thenReturn(true); lenient().when(resp.getHttpStatusCode()).thenReturn(200); - lenient().when(resp.getObject()).thenReturn(obj); + lenient().doReturn(obj).when(resp).getObject(); return resp; } - @SuppressWarnings("unchecked") - private KubernetesApiResponse notFoundResponse() { - KubernetesApiResponse resp = mock(KubernetesApiResponse.class); + private KubernetesApiResponse notFoundResponse() { + KubernetesApiResponse resp = mock(KubernetesApiResponse.class); lenient().when(resp.isSuccess()).thenReturn(false); lenient().when(resp.getHttpStatusCode()).thenReturn(404); return resp; @@ -421,12 +419,11 @@ class CreateWithMetadataSideEffectTests { @Mock private K8sContext mockContext; - @SuppressWarnings("unchecked") - private KubernetesApiResponse successResponse(DynamicKubernetesObject obj) { - KubernetesApiResponse resp = mock(KubernetesApiResponse.class); + private KubernetesApiResponse successResponse(DynamicKubernetesObject obj) { + KubernetesApiResponse resp = mock(KubernetesApiResponse.class); lenient().when(resp.isSuccess()).thenReturn(true); lenient().when(resp.getHttpStatusCode()).thenReturn(200); - lenient().when(resp.getObject()).thenReturn(obj); + lenient().doReturn(obj).when(resp).getObject(); return resp; } @@ -616,18 +613,16 @@ class UpdateSideEffectTests { @Mock private K8sContext mockContext; - @SuppressWarnings("unchecked") - private KubernetesApiResponse successResponse(DynamicKubernetesObject obj) { - KubernetesApiResponse resp = mock(KubernetesApiResponse.class); + private KubernetesApiResponse successResponse(DynamicKubernetesObject obj) { + KubernetesApiResponse resp = mock(KubernetesApiResponse.class); lenient().when(resp.isSuccess()).thenReturn(true); lenient().when(resp.getHttpStatusCode()).thenReturn(200); - lenient().when(resp.getObject()).thenReturn(obj); + lenient().doReturn(obj).when(resp).getObject(); return resp; } - @SuppressWarnings("unchecked") - private KubernetesApiResponse notFoundResponse() { - KubernetesApiResponse resp = mock(KubernetesApiResponse.class); + private KubernetesApiResponse notFoundResponse() { + KubernetesApiResponse resp = mock(KubernetesApiResponse.class); lenient().when(resp.isSuccess()).thenReturn(false); lenient().when(resp.getHttpStatusCode()).thenReturn(404); return resp; @@ -771,8 +766,7 @@ void getIfExistsReturnsObjectFor200AndNotNullFor200Status() throws SQLException @Test void getIfExistsThrowsForNon404ErrorResponse() throws ApiException, SQLException { - @SuppressWarnings("unchecked") - KubernetesApiResponse errorResp = mock(KubernetesApiResponse.class); + KubernetesApiResponse errorResp = mock(KubernetesApiResponse.class); lenient().when(errorResp.isSuccess()).thenReturn(false); lenient().when(errorResp.getHttpStatusCode()).thenReturn(500); ApiException apiEx = new ApiException(500, "Server Error"); diff --git a/hoptimator-kafka-controller/src/test/java/com/linkedin/hoptimator/operator/kafka/KafkaTopicReconcilerTest.java b/hoptimator-kafka-controller/src/test/java/com/linkedin/hoptimator/operator/kafka/KafkaTopicReconcilerTest.java index 9c04a676..0fbcb8ff 100644 --- a/hoptimator-kafka-controller/src/test/java/com/linkedin/hoptimator/operator/kafka/KafkaTopicReconcilerTest.java +++ b/hoptimator-kafka-controller/src/test/java/com/linkedin/hoptimator/operator/kafka/KafkaTopicReconcilerTest.java @@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -85,7 +86,6 @@ void testReconcileNonDeletedSqlExceptionRequeues() throws Exception { assertTrue(result.isRequeue()); } - @SuppressWarnings("unchecked") @Test void testReconcileCreatesNewTopic() throws Exception { V1alpha1KafkaTopic topic = buildKafkaTopic("my-topic", 5, 3); @@ -93,9 +93,9 @@ void testReconcileCreatesNewTopic() throws Exception { // Admin describe throws UnknownTopicOrPartitionException (topic doesn't exist yet) DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture> allFuture = mock(KafkaFuture.class); + KafkaFuture allFuture = mock(KafkaFuture.class); when(allFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.allTopicNames()).thenReturn(allFuture); + doReturn(allFuture).when(describeResult).allTopicNames(); when(mockAdmin.describeTopics(anyCollection())).thenReturn(describeResult); // CreateTopics succeeds diff --git a/hoptimator-kafka/src/test/java/com/linkedin/hoptimator/kafka/KafkaDeployerTest.java b/hoptimator-kafka/src/test/java/com/linkedin/hoptimator/kafka/KafkaDeployerTest.java index 42848533..985ca0f7 100644 --- a/hoptimator-kafka/src/test/java/com/linkedin/hoptimator/kafka/KafkaDeployerTest.java +++ b/hoptimator-kafka/src/test/java/com/linkedin/hoptimator/kafka/KafkaDeployerTest.java @@ -39,6 +39,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -68,15 +70,14 @@ private KafkaDeployer createDeployer(Source source) { // --- create()/update() tests --- - @SuppressWarnings("unchecked") @Test void testCreateNewTopic() throws Exception { Source source = new Source("db", List.of("KAFKA", "NewTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("NewTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))).when(failedFuture).get(); + doReturn(Map.of("NewTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); CreateTopicsResult createResult = mock(CreateTopicsResult.class); @@ -181,16 +182,15 @@ void testCreateExistingTopicDoesNotDecreasePartitions() throws Exception { verify(mockAdmin, never()).incrementalAlterConfigs(any()); } - @SuppressWarnings("unchecked") @Test void testCreateWithCustomPartitionsAndReplicationFactor() throws Exception { Source source = new Source("db", List.of("KAFKA", "CustomTopic"), Map.of("partitions", "32", "replicationFactor", "5")); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("CustomTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))).when(failedFuture).get(); + doReturn(Map.of("CustomTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); CreateTopicsResult createResult = mock(CreateTopicsResult.class); @@ -204,15 +204,14 @@ void testCreateWithCustomPartitionsAndReplicationFactor() throws Exception { verify(mockAdmin).createTopics(anyList()); } - @SuppressWarnings("unchecked") @Test void testCreatePropagatesNonTopicNotFoundError() throws Exception { Source source = new Source("db", List.of("KAFKA", "ErrorTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new RuntimeException("connection refused"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("ErrorTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new RuntimeException("connection refused"))).when(failedFuture).get(); + doReturn(Map.of("ErrorTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); KafkaDeployer deployer = createDeployer(source); @@ -302,15 +301,14 @@ void testRestoreNoOpWhenNotCreated() { deployer.restore(); } - @SuppressWarnings("unchecked") @Test void testRestoreLogsWarningAfterCreate() throws Exception { Source source = new Source("db", List.of("KAFKA", "CreatedTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("CreatedTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))).when(failedFuture).get(); + doReturn(Map.of("CreatedTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); CreateTopicsResult createResult = mock(CreateTopicsResult.class); @@ -331,7 +329,7 @@ void testDeleteTopic() throws Exception { DeleteTopicsResult deleteResult = mock(DeleteTopicsResult.class); KafkaFuture deleteFuture = KafkaFuture.completedFuture(null); - when(deleteResult.all()).thenReturn(deleteFuture); + doReturn(deleteFuture).when(deleteResult).all(); when(mockAdmin.deleteTopics(anyList())).thenReturn(deleteResult); KafkaDeployer deployer = createDeployer(source); @@ -341,15 +339,14 @@ void testDeleteTopic() throws Exception { verify(mockAdmin).close(); } - @SuppressWarnings("unchecked") @Test void testDeleteTopicThrowsException() throws Exception { Source source = new Source("db", List.of("KAFKA", "ErrorTopic"), Collections.emptyMap()); DeleteTopicsResult deleteResult = mock(DeleteTopicsResult.class); - KafkaFuture deleteFuture = mock(KafkaFuture.class); - when(deleteFuture.get()).thenThrow(new ExecutionException(new RuntimeException("Delete failed"))); - when(deleteResult.all()).thenReturn(deleteFuture); + KafkaFuture deleteFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new RuntimeException("Delete failed"))).when(deleteFuture).get(); + doReturn(deleteFuture).when(deleteResult).all(); when(mockAdmin.deleteTopics(anyList())).thenReturn(deleteResult); KafkaDeployer deployer = createDeployer(source); @@ -358,15 +355,14 @@ void testDeleteTopicThrowsException() throws Exception { assertTrue(exception.getMessage().contains("Failed to delete topic ErrorTopic")); } - @SuppressWarnings("unchecked") @Test void testDeleteNonExistentTopic() throws Exception { Source source = new Source("db", List.of("KAFKA", "NonExistentTopic"), Collections.emptyMap()); DeleteTopicsResult deleteResult = mock(DeleteTopicsResult.class); - KafkaFuture deleteFuture = mock(KafkaFuture.class); - when(deleteFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("Topic not found"))); - when(deleteResult.all()).thenReturn(deleteFuture); + KafkaFuture deleteFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("Topic not found"))).when(deleteFuture).get(); + doReturn(deleteFuture).when(deleteResult).all(); when(mockAdmin.deleteTopics(anyList())).thenReturn(deleteResult); KafkaDeployer deployer = createDeployer(source); @@ -413,16 +409,15 @@ void testValidateAdminClientThrowsGenericException() { assertTrue(issues.toString().contains("Failed to validate topic")); } - @SuppressWarnings("unchecked") @Test void testValidateAdminClientThrowsNonTopicNotFound() throws Exception { Source source = new Source("db", List.of("KAFKA", "AuthFailTopic"), Map.of("partitions", "10")); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new RuntimeException("auth failed"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("AuthFailTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new RuntimeException("auth failed"))).when(failedFuture).get(); + doReturn(Map.of("AuthFailTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); KafkaDeployer deployer = createDeployer(source); @@ -452,15 +447,14 @@ void testCreateExistingTopicSkipsCreation() throws Exception { verify(mockAdmin).close(); } - @SuppressWarnings("unchecked") @Test void testCreateTopicExistsCheckThrowsGenericException() throws Exception { Source source = new Source("db", List.of("KAFKA", "BrokenTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new InterruptedException("interrupted")); - when(describeResult.topicNameValues()).thenReturn(Map.of("BrokenTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new InterruptedException("interrupted")).when(failedFuture).get(); + doReturn(Map.of("BrokenTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); KafkaDeployer deployer = createDeployer(source); @@ -471,15 +465,14 @@ void testCreateTopicExistsCheckThrowsGenericException() throws Exception { // --- describeTopic() coverage via update() --- - @SuppressWarnings("unchecked") @Test void testUpdateCreatesTopicWhenNotExists() throws Exception { Source source = new Source("db", List.of("KAFKA", "MissingTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("MissingTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))).when(failedFuture).get(); + doReturn(Map.of("MissingTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); CreateTopicsResult createResult = mock(CreateTopicsResult.class); @@ -494,15 +487,14 @@ void testUpdateCreatesTopicWhenNotExists() throws Exception { verify(mockAdmin).close(); } - @SuppressWarnings("unchecked") @Test void testUpdateDescribeTopicThrowsNonTopicException() throws Exception { Source source = new Source("db", List.of("KAFKA", "AuthFailTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new RuntimeException("auth failed"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("AuthFailTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new RuntimeException("auth failed"))).when(failedFuture).get(); + doReturn(Map.of("AuthFailTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); KafkaDeployer deployer = createDeployer(source); @@ -511,15 +503,14 @@ void testUpdateDescribeTopicThrowsNonTopicException() throws Exception { assertTrue(exception.getMessage().contains("Failed to describe topic AuthFailTopic")); } - @SuppressWarnings("unchecked") @Test void testUpdateDescribeTopicThrowsGenericException() throws Exception { Source source = new Source("db", List.of("KAFKA", "BrokenTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new InterruptedException("interrupted")); - when(describeResult.topicNameValues()).thenReturn(Map.of("BrokenTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new InterruptedException("interrupted")).when(failedFuture).get(); + doReturn(Map.of("BrokenTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); KafkaDeployer deployer = createDeployer(source); @@ -530,16 +521,15 @@ void testUpdateDescribeTopicThrowsGenericException() throws Exception { // --- update() with custom retention on new topic --- - @SuppressWarnings("unchecked") @Test void testUpdateCreatesTopicWithCustomRetention() throws Exception { Source source = new Source("db", List.of("KAFKA", "RetentionNewTopic"), Map.of("retention", "86400000")); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("RetentionNewTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))).when(failedFuture).get(); + doReturn(Map.of("RetentionNewTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); CreateTopicsResult createResult = mock(CreateTopicsResult.class); @@ -582,9 +572,9 @@ void testCreateTopicWithCustomRetentionPassesRetentionToNewTopic() throws Except Map.of("retention", String.valueOf(customRetention))); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("RetentionConfigTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))).when(failedFuture).get(); + doReturn(Map.of("RetentionConfigTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); CreateTopicsResult createResult = mock(CreateTopicsResult.class); @@ -608,9 +598,9 @@ void testCreateTopicWithDefaultRetentionUsesDefaultRetentionValue() throws Excep Source source = new Source("db", List.of("KAFKA", "DefaultRetentionTopic"), Collections.emptyMap()); DescribeTopicsResult describeResult = mock(DescribeTopicsResult.class); - KafkaFuture failedFuture = mock(KafkaFuture.class); - when(failedFuture.get()).thenThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))); - when(describeResult.topicNameValues()).thenReturn(Map.of("DefaultRetentionTopic", failedFuture)); + KafkaFuture failedFuture = mock(KafkaFuture.class); + doThrow(new ExecutionException(new UnknownTopicOrPartitionException("not found"))).when(failedFuture).get(); + doReturn(Map.of("DefaultRetentionTopic", failedFuture)).when(describeResult).topicNameValues(); when(mockAdmin.describeTopics(anyList())).thenReturn(describeResult); CreateTopicsResult createResult = mock(CreateTopicsResult.class); diff --git a/hoptimator-logical/src/test/java/com/linkedin/hoptimator/logical/LogicalTableDeployerTest.java b/hoptimator-logical/src/test/java/com/linkedin/hoptimator/logical/LogicalTableDeployerTest.java index f90ab57f..7cd98b85 100644 --- a/hoptimator-logical/src/test/java/com/linkedin/hoptimator/logical/LogicalTableDeployerTest.java +++ b/hoptimator-logical/src/test/java/com/linkedin/hoptimator/logical/LogicalTableDeployerTest.java @@ -51,6 +51,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -940,7 +941,7 @@ void implicitTriggerSkippedWhenNoOfflineTier() throws Exception { deployerWithJobTemplates(testSource(), props, mockContext(), dbApi, jobTemplates, capture) .create(); - assertEquals(null, capture.trigger, + assertNull(capture.trigger, "No offline tier → implicit trigger must not be created"); } @@ -957,7 +958,7 @@ void implicitTriggerSkippedWhenNoMatchingJobTemplate() throws Exception { deployerWithJobTemplates(testSource(), twoTierProps("nearline-db", "offline-db"), mockContext(), dbApi, jobTemplates, capture).create(); - assertEquals(null, capture.trigger, + assertNull(capture.trigger, "No JobTemplate declares the offline DB → implicit trigger must be skipped"); } diff --git a/hoptimator-mcp-server-app/src/test/java/com/linkedin/hoptimator/mcp/server/HoptimatorMcpServerTest.java b/hoptimator-mcp-server-app/src/test/java/com/linkedin/hoptimator/mcp/server/HoptimatorMcpServerTest.java index 764371db..1b18c361 100644 --- a/hoptimator-mcp-server-app/src/test/java/com/linkedin/hoptimator/mcp/server/HoptimatorMcpServerTest.java +++ b/hoptimator-mcp-server-app/src/test/java/com/linkedin/hoptimator/mcp/server/HoptimatorMcpServerTest.java @@ -96,8 +96,7 @@ void testFetchSchemasTool() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List schemas = gson.fromJson(text, List.class); + List schemas = gson.fromJson(text, List.class); assertNotNull(schemas, "Schemas is null"); assertFalse(schemas.isEmpty(), "Schemas are empty"); System.out.println("Schemas: " + schemas); @@ -128,8 +127,7 @@ void testFetchSchemasToolWithCatalog() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List schemas = gson.fromJson(text, List.class); + List schemas = gson.fromJson(text, List.class); assertNotNull(schemas, "Schemas is null"); assertFalse(schemas.isEmpty(), "Schemas are empty"); System.out.println("Schemas in MYSQL catalog: " + schemas); @@ -156,8 +154,7 @@ void testFetchTablesTool() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List tables = gson.fromJson(text, List.class); + List tables = gson.fromJson(text, List.class); assertFalse(tables.isEmpty()); System.out.println("Tables: " + tables); } @@ -185,8 +182,7 @@ void testFetchTablesToolWithSchema() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List tables = gson.fromJson(text, List.class); + List tables = gson.fromJson(text, List.class); assertFalse(tables.isEmpty()); System.out.println("Tables in ADS schema: " + tables); } @@ -214,8 +210,7 @@ void testFetchTablesToolWithCatalog() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List tables = gson.fromJson(text, List.class); + List tables = gson.fromJson(text, List.class); assertFalse(tables.isEmpty()); System.out.println("Tables in MYSQL catalog: " + tables); } @@ -244,8 +239,7 @@ void testFetchTablesToolWithSchemaAndCatalog() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List tables = gson.fromJson(text, List.class); + List tables = gson.fromJson(text, List.class); assertFalse(tables.isEmpty()); System.out.println("Tables in MYSQL.testdb: " + tables); } @@ -271,8 +265,7 @@ void testFetchPipelines() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List pipelines = gson.fromJson(text, List.class); + List pipelines = gson.fromJson(text, List.class); System.out.println("Pipelines: " + pipelines); } @@ -323,8 +316,7 @@ void testDescribeTable() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List tableDefinitions = gson.fromJson(text, List.class); + List tableDefinitions = gson.fromJson(text, List.class); assertFalse(tableDefinitions.isEmpty()); System.out.println("Table definitions for AD_CLICKS: " + tableDefinitions); } @@ -376,8 +368,7 @@ void testPlanTool() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List planResults = gson.fromJson(text, List.class); + List planResults = gson.fromJson(text, List.class); assertFalse(planResults.isEmpty()); System.out.println("Plan results: " + planResults); } @@ -405,8 +396,7 @@ void testQueryTool() throws Exception { assertFalse(text.isEmpty(), "Text is empty"); assertFalse(text.contains("ERROR")); - @SuppressWarnings("unchecked") - List queryResults = gson.fromJson(text, List.class); + List queryResults = gson.fromJson(text, List.class); assertFalse(queryResults.isEmpty()); System.out.println("Query results: " + queryResults); } diff --git a/hoptimator-mysql/src/test/java/com/linkedin/hoptimator/mysql/MySqlDriverTest.java b/hoptimator-mysql/src/test/java/com/linkedin/hoptimator/mysql/MySqlDriverTest.java index ad9534c1..db1af646 100644 --- a/hoptimator-mysql/src/test/java/com/linkedin/hoptimator/mysql/MySqlDriverTest.java +++ b/hoptimator-mysql/src/test/java/com/linkedin/hoptimator/mysql/MySqlDriverTest.java @@ -5,6 +5,7 @@ import org.apache.calcite.schema.impl.AbstractSchema; import org.apache.calcite.schema.lookup.IgnoreCaseLookup; import org.apache.calcite.schema.lookup.LikePattern; +import org.apache.calcite.schema.lookup.Lookup; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @@ -33,7 +34,7 @@ private MySqlDriver driverWithMockRootSchema() { protected AbstractSchema createMySqlRootSchema(Properties properties) { return new AbstractSchema() { @Override - public org.apache.calcite.schema.lookup.Lookup subSchemas() { + public Lookup subSchemas() { return new IgnoreCaseLookup<>() { @Override public Schema get(String name) { return null; diff --git a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/pipeline/PipelineReconcilerTest.java b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/pipeline/PipelineReconcilerTest.java index faff9b69..ffd9c4bc 100644 --- a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/pipeline/PipelineReconcilerTest.java +++ b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/pipeline/PipelineReconcilerTest.java @@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -176,11 +177,10 @@ void reconcileWithMixedStatusesRequeues() { } @Test - @SuppressWarnings("unchecked") void controllerCreatesControllerFromContext() { SharedInformerFactory mockInformerFactory = mock(SharedInformerFactory.class); - SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); - when(mockInformerFactory.getExistingSharedIndexInformer(V1alpha1Pipeline.class)).thenReturn(mockInformer); + SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); + doReturn(mockInformer).when(mockInformerFactory).getExistingSharedIndexInformer(V1alpha1Pipeline.class); K8sContext mockContext = mock(K8sContext.class); when(mockContext.informerFactory()).thenReturn(mockInformerFactory); diff --git a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/subscription/SubscriptionReconcilerTest.java b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/subscription/SubscriptionReconcilerTest.java index edafbf25..9550a665 100644 --- a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/subscription/SubscriptionReconcilerTest.java +++ b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/subscription/SubscriptionReconcilerTest.java @@ -45,6 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.lenient; @@ -72,7 +73,7 @@ class SubscriptionReconcilerTest { private Database mockDatabase; @Mock - private GenericKubernetesApi mockSubscriptionApi; + private GenericKubernetesApi mockSubscriptionApi; @Mock private KubernetesApiResponse mockUpdateStatusResponse; @@ -113,10 +114,9 @@ void setUp() { } // ── Helper: stub the apiFor(SUBSCRIPTION).updateStatus(...).onFailure(...) chain - @SuppressWarnings("unchecked") private void stubUpdateStatus() throws ApiException { - when(operator.apiFor(anyString())).thenReturn((GenericKubernetesApi) mockSubscriptionApi); - when(mockSubscriptionApi.updateStatus(any(), any())).thenReturn(mockUpdateStatusResponse); + doReturn(mockSubscriptionApi).when(operator).apiFor(anyString()); + doReturn(mockUpdateStatusResponse).when(mockSubscriptionApi).updateStatus(any(), any()); when(mockUpdateStatusResponse.onFailure(any())).thenReturn(mockUpdateStatusResponse); } @@ -314,7 +314,6 @@ void divergedWhenHintsDiffer() throws Exception { // .status.attributes field @Test - @SuppressWarnings("unchecked") void fetchAttributesFromStatusAttributesField() throws Exception { V1alpha1Subscription sub = buildSubscription("ns", "my-sub", "SELECT 1"); V1alpha1SubscriptionStatus status = new V1alpha1SubscriptionStatus(); @@ -347,13 +346,13 @@ void fetchAttributesFromStatusAttributesField() throws Exception { DynamicKubernetesApi mockDynApi = mock(DynamicKubernetesApi.class); when(operator.apiFor(any(DynamicKubernetesObject.class))).thenReturn(mockDynApi); - KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); - when(mockDynApi.get(anyString(), anyString())).thenReturn(mockResp); - when(mockResp.onFailure(any())).thenReturn(mockResp); + KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); + doReturn(mockResp).when(mockDynApi).get(anyString(), anyString()); + doReturn(mockResp).when(mockResp).onFailure(any()); when(mockResp.isSuccess()).thenReturn(true); DynamicKubernetesObject dynObj = new DynamicKubernetesObject(raw); dynObj.setMetadata(new V1ObjectMeta().name("cm1").namespace("ns")); - when(mockResp.getObject()).thenReturn(dynObj); + doReturn(dynObj).when(mockResp).getObject(); stubUpdateStatus(); @@ -365,7 +364,6 @@ void fetchAttributesFromStatusAttributesField() throws Exception { // .status.jobStatus field @Test - @SuppressWarnings("unchecked") void fetchAttributesFromStatusJobStatusField() throws Exception { V1alpha1Subscription sub = buildSubscription("ns", "my-sub", "SELECT 1"); V1alpha1SubscriptionStatus status = new V1alpha1SubscriptionStatus(); @@ -397,13 +395,13 @@ void fetchAttributesFromStatusJobStatusField() throws Exception { DynamicKubernetesApi mockDynApi = mock(DynamicKubernetesApi.class); when(operator.apiFor(any(DynamicKubernetesObject.class))).thenReturn(mockDynApi); - KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); - when(mockDynApi.get(anyString(), anyString())).thenReturn(mockResp); - when(mockResp.onFailure(any())).thenReturn(mockResp); + KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); + doReturn(mockResp).when(mockDynApi).get(anyString(), anyString()); + doReturn(mockResp).when(mockResp).onFailure(any()); when(mockResp.isSuccess()).thenReturn(true); DynamicKubernetesObject dynObj = new DynamicKubernetesObject(raw); dynObj.setMetadata(new V1ObjectMeta().name("flink-job").namespace("ns")); - when(mockResp.getObject()).thenReturn(dynObj); + doReturn(dynObj).when(mockResp).getObject(); stubUpdateStatus(); @@ -415,7 +413,6 @@ void fetchAttributesFromStatusJobStatusField() throws Exception { // API call fails → empty attributes @Test - @SuppressWarnings("unchecked") void fetchAttributesReturnsEmptyWhenApiFails() throws Exception { V1alpha1Subscription sub = buildSubscription("ns", "my-sub", "SELECT 1"); V1alpha1SubscriptionStatus status = new V1alpha1SubscriptionStatus(); @@ -434,9 +431,9 @@ void fetchAttributesReturnsEmptyWhenApiFails() throws Exception { DynamicKubernetesApi mockDynApi = mock(DynamicKubernetesApi.class); when(operator.apiFor(any(DynamicKubernetesObject.class))).thenReturn(mockDynApi); - KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); - when(mockDynApi.get(anyString(), anyString())).thenReturn(mockResp); - when(mockResp.onFailure(any())).thenReturn(mockResp); + KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); + doReturn(mockResp).when(mockDynApi).get(anyString(), anyString()); + doReturn(mockResp).when(mockResp).onFailure(any()); when(mockResp.isSuccess()).thenReturn(false); stubUpdateStatus(); @@ -449,12 +446,10 @@ void fetchAttributesReturnsEmptyWhenApiFails() throws Exception { // Returns non-null Controller @Test - @SuppressWarnings("unchecked") void controllerReturnsNonNull() { SharedInformerFactory mockInformerFactory = mock(SharedInformerFactory.class); - SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); - when(mockInformerFactory.getExistingSharedIndexInformer(V1alpha1Subscription.class)) - .thenReturn(mockInformer); + SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); + doReturn(mockInformer).when(mockInformerFactory).getExistingSharedIndexInformer(V1alpha1Subscription.class); when(operator.informerFactory()).thenReturn(mockInformerFactory); Controller controller = SubscriptionReconciler.controller(operator, plannerFactory, @@ -497,7 +492,6 @@ void outerExceptionHandlerRequeuedWhenFetchThrows() { // .status direct fields (no attributes/jobStatus) @Test - @SuppressWarnings("unchecked") void fetchAttributesFromStatusDirectFields() throws Exception { V1alpha1Subscription sub = buildSubscription("ns", "my-sub", "SELECT 1"); V1alpha1SubscriptionStatus status = new V1alpha1SubscriptionStatus(); @@ -529,13 +523,13 @@ void fetchAttributesFromStatusDirectFields() throws Exception { DynamicKubernetesApi mockDynApi = mock(DynamicKubernetesApi.class); when(operator.apiFor(any(DynamicKubernetesObject.class))).thenReturn(mockDynApi); - KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); - when(mockDynApi.get(anyString(), anyString())).thenReturn(mockResp); - when(mockResp.onFailure(any())).thenReturn(mockResp); + KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); + doReturn(mockResp).when(mockDynApi).get(anyString(), anyString()); + doReturn(mockResp).when(mockResp).onFailure(any()); when(mockResp.isSuccess()).thenReturn(true); DynamicKubernetesObject dynObj = new DynamicKubernetesObject(raw); dynObj.setMetadata(new V1ObjectMeta().name("topic1").namespace("ns")); - when(mockResp.getObject()).thenReturn(dynObj); + doReturn(dynObj).when(mockResp).getObject(); stubUpdateStatus(); @@ -815,7 +809,6 @@ void notDivergedWhenSqlMatchesAndHintsMatch() throws Exception { // guessAttributes() — non-primitive JSON value is NOT included @Test - @SuppressWarnings("unchecked") void guessAttributesExcludesNonPrimitiveValues() throws Exception { V1alpha1Subscription sub = buildSubscription("ns", "my-sub", "SELECT 1"); V1alpha1SubscriptionStatus status = new V1alpha1SubscriptionStatus(); @@ -854,13 +847,13 @@ void guessAttributesExcludesNonPrimitiveValues() throws Exception { DynamicKubernetesApi mockDynApi = mock(DynamicKubernetesApi.class); when(operator.apiFor(any(DynamicKubernetesObject.class))).thenReturn(mockDynApi); - KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); - when(mockDynApi.get(anyString(), anyString())).thenReturn(mockResp); - when(mockResp.onFailure(any())).thenReturn(mockResp); + KubernetesApiResponse mockResp = mock(KubernetesApiResponse.class); + doReturn(mockResp).when(mockDynApi).get(anyString(), anyString()); + doReturn(mockResp).when(mockResp).onFailure(any()); when(mockResp.isSuccess()).thenReturn(true); DynamicKubernetesObject dynObj = new DynamicKubernetesObject(raw); dynObj.setMetadata(new V1ObjectMeta().name("cm1").namespace("ns")); - when(mockResp.getObject()).thenReturn(dynObj); + doReturn(dynObj).when(mockResp).getObject(); stubUpdateStatus(); diff --git a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/TableTriggerReconcilerTest.java b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/TableTriggerReconcilerTest.java index 09594080..70277390 100644 --- a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/TableTriggerReconcilerTest.java +++ b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/TableTriggerReconcilerTest.java @@ -46,6 +46,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -412,11 +413,10 @@ void pausedTriggerWithNullStatusAndExistingJobDoesNotCrash() { } @Test - @SuppressWarnings("unchecked") void controllerCreatesControllerFromContext() { SharedInformerFactory mockInformerFactory = mock(SharedInformerFactory.class); - SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); - when(mockInformerFactory.getExistingSharedIndexInformer(V1alpha1TableTrigger.class)).thenReturn(mockInformer); + SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); + doReturn(mockInformer).when(mockInformerFactory).getExistingSharedIndexInformer(V1alpha1TableTrigger.class); K8sContext mockContext = mock(K8sContext.class); when(mockContext.informerFactory()).thenReturn(mockInformerFactory); diff --git a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/ViewReconcilerTest.java b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/ViewReconcilerTest.java index f3933204..6d3d8e11 100644 --- a/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/ViewReconcilerTest.java +++ b/hoptimator-operator/src/test/java/com/linkedin/hoptimator/operator/trigger/ViewReconcilerTest.java @@ -35,6 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -192,11 +193,10 @@ void reconcileWithNon404SqlExceptionRequeues() throws SQLException { } @Test - @SuppressWarnings("unchecked") void controllerCreatesControllerFromContext() { SharedInformerFactory mockInformerFactory = mock(SharedInformerFactory.class); - SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); - when(mockInformerFactory.getExistingSharedIndexInformer(V1alpha1View.class)).thenReturn(mockInformer); + SharedIndexInformer mockInformer = mock(SharedIndexInformer.class); + doReturn(mockInformer).when(mockInformerFactory).getExistingSharedIndexInformer(V1alpha1View.class); K8sContext mockContext = mock(K8sContext.class); when(mockContext.informerFactory()).thenReturn(mockInformerFactory); diff --git a/hoptimator-util/src/test/java/com/linkedin/hoptimator/util/planner/HoptimatorJdbcTableTest.java b/hoptimator-util/src/test/java/com/linkedin/hoptimator/util/planner/HoptimatorJdbcTableTest.java index 87065624..8d11a59d 100644 --- a/hoptimator-util/src/test/java/com/linkedin/hoptimator/util/planner/HoptimatorJdbcTableTest.java +++ b/hoptimator-util/src/test/java/com/linkedin/hoptimator/util/planner/HoptimatorJdbcTableTest.java @@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -198,13 +199,12 @@ public RelDataType getRowType(RelDataTypeFactory factory) { } @Test - @SuppressWarnings("unchecked") void testAsQueryableDelegatesToJdbcTable() { QueryProvider mockProvider = mock(QueryProvider.class); SchemaPlus mockSchema = mock(SchemaPlus.class); Queryable mockQueryable = mock(Queryable.class); - when(mockJdbcTable.asQueryable(any(), any(), any())).thenReturn((Queryable) mockQueryable); + doReturn(mockQueryable).when(mockJdbcTable).asQueryable(any(), any(), any()); Queryable result = table.asQueryable(mockProvider, mockSchema, "tableName"); diff --git a/hoptimator-venice/src/test/java/com/linkedin/hoptimator/venice/VeniceStoreTest.java b/hoptimator-venice/src/test/java/com/linkedin/hoptimator/venice/VeniceStoreTest.java index acd29ec2..32fe4688 100644 --- a/hoptimator-venice/src/test/java/com/linkedin/hoptimator/venice/VeniceStoreTest.java +++ b/hoptimator-venice/src/test/java/com/linkedin/hoptimator/venice/VeniceStoreTest.java @@ -1,5 +1,6 @@ package com.linkedin.hoptimator.venice; +import com.linkedin.hoptimator.avro.AvroSchemas; import com.linkedin.venice.client.schema.StoreSchemaFetcher; import org.apache.avro.Schema; import org.apache.avro.SchemaBuilder; @@ -208,7 +209,7 @@ void mergedAvroSchemaHelperCombinesKeyAndValue() { VeniceStore store = new VeniceStore(mockSchemaFetcher, new VeniceStoreConfig(Collections.emptyMap())); - Schema merged = com.linkedin.hoptimator.avro.AvroSchemas.mergedAvroSchemaFor(store); + Schema merged = AvroSchemas.mergedAvroSchemaFor(store); assertEquals("com.linkedin.foo", merged.getNamespace()); assertEquals("User", merged.getName());