From cd1d847e9e081ea19d21c77254951bc74ded93e5 Mon Sep 17 00:00:00 2001 From: Rob Rudin Date: Tue, 14 Nov 2023 11:55:51 -0500 Subject: [PATCH] Fixing compiler warnings Prepping for 6.4.0 release. --- .../functionaltests/WBFailover.java | 25 ++++------ .../functionaltests/WriteHostBatcherTest.java | 49 +++++++++---------- .../client/test/dbfunction/fntestgen.kt | 36 +++++++------- 3 files changed, 49 insertions(+), 61 deletions(-) diff --git a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WBFailover.java b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WBFailover.java index 1c00fa7ea..26054efa5 100644 --- a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WBFailover.java +++ b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WBFailover.java @@ -742,25 +742,18 @@ public void testMinHosts() throws Exception { } @Test - public void testWhiteBlackListNPE() throws Exception { + public void testWhiteBlackListNPE() { Assumptions.assumeTrue(hostNames.length > 1); - System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName()); - try { - FilteredForestConfiguration forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()) - .withBlackList(null); - assertTrue(1 > 2); - } catch (Exception e) { - assertTrue(e instanceof java.lang.IllegalArgumentException); - } + assertThrows(IllegalArgumentException.class, () -> { + String[] hostNames = null; + new FilteredForestConfiguration(dmManager.readForestConfig()).withBlackList(hostNames); + }); - try { - FilteredForestConfiguration forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()) - .withWhiteList(null); - assertTrue(1 > 2); - } catch (Exception e) { - assertTrue(e instanceof java.lang.IllegalArgumentException); - } + assertThrows(IllegalArgumentException.class, () -> { + String[] hostNames = null; + new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList(hostNames); + }); } private void serverStartStop(String server, String command) throws Exception { diff --git a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WriteHostBatcherTest.java b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WriteHostBatcherTest.java index 147e9cf96..f7c0b10cb 100644 --- a/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WriteHostBatcherTest.java +++ b/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WriteHostBatcherTest.java @@ -2401,13 +2401,12 @@ public void testQBWhiteList() throws Exception { }); qb.onQueryFailure(throwable -> throwable.printStackTrace()); - try { - forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList(null); - fail("hostnames shouldn't be null"); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> { + String[] hostNames = null; + new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList(hostNames); + }); + assertEquals("hostNames must not be null", ex.getMessage()); - } catch (IllegalArgumentException e) { - assertEquals("hostNames must not be null", e.getMessage()); - } try { forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList("asdf"); qb.withBatchSize(50).withForestConfig(forestConfig); @@ -2440,13 +2439,12 @@ public void testWBWhiteList() throws Exception { assertTrue(dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0); WriteBatcher ihb2 = dmManager.newWriteBatcher(); - try { - forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList(null); - fail("hostnames shouldn't be null"); - } catch (IllegalArgumentException e) { - assertEquals("hostNames must not be null", e.getMessage()); - } + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> { + String[] hostNames = null; + new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList(hostNames); + }); + assertEquals("hostNames must not be null", ex.getMessage()); try { forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList("asdf"); @@ -2479,7 +2477,7 @@ public void testWBWhiteList() throws Exception { } @Test - public void testQBBlackList() throws Exception { + public void testQBBlackList() { Assumptions.assumeTrue(!isLBHost()); Assumptions.assumeTrue(hostNames.length > 1); System.out.println("In testQBBlackList method"); @@ -2517,13 +2515,11 @@ public void testQBBlackList() throws Exception { }); qb.onQueryFailure(throwable -> throwable.printStackTrace()); - try { - forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withBlackList(null); - fail("hostnames shouldn't be null"); - - } catch (IllegalArgumentException e) { - assertEquals("hostNames must not be null", e.getMessage()); - } + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> { + String[] hostNames = null; + new FilteredForestConfiguration(dmManager.readForestConfig()).withBlackList(hostNames); + }); + assertEquals("hostNames must not be null", ex.getMessage()); try { forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withBlackList(hostNames) @@ -2545,7 +2541,7 @@ public void testQBBlackList() throws Exception { } @Test - public void testWBBlackList() throws Exception { + public void testWBBlackList() { Assumptions.assumeTrue(!isLBHost()); Assumptions.assumeTrue(hostNames.length > 1); System.out.println("In testWBBlackList method"); @@ -2558,13 +2554,12 @@ public void testWBBlackList() throws Exception { assertTrue(dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0); WriteBatcher ihb2 = dmManager.newWriteBatcher(); - try { - forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList(null); - fail("hostnames shouldn't be null"); - } catch (IllegalArgumentException e) { - assertEquals("hostNames must not be null", e.getMessage()); - } + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> { + String[] hostNames = null; + new FilteredForestConfiguration(dmManager.readForestConfig()).withWhiteList(hostNames); + }); + assertEquals("hostNames must not be null", ex.getMessage()); forestConfig = new FilteredForestConfiguration(dmManager.readForestConfig()).withBlackList("asdf"); ihb2.withBatchSize(50).withForestConfig(forestConfig); diff --git a/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt b/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt index e248d4dad..748a3c61d 100644 --- a/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt +++ b/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt @@ -646,12 +646,12 @@ if (true) { val responseBodyTypes = listOf("none", "text", "document", "multipart") for (responseBodyNum in responseBodyTypes.indices) { val responseBodyType = responseBodyTypes[responseBodyNum] - val responseBody = responseBodyType.capitalize() + val responseBody = responseBodyType.replaceFirstChar {it.uppercase()} val requestBodyTypes = listOf("none", "urlencoded", "multipart") for (requestBodyNum in requestBodyTypes.indices) { val requestBodyType = requestBodyTypes[requestBodyNum] - val requestBody = requestBodyType.capitalize() + val requestBody = requestBodyType.replaceFirstChar {it.uppercase()} val modExtension = modExtensions[(responseBodyNum + requestBodyNum) % modExtensions.size] val requestParams = @@ -697,7 +697,7 @@ if (true) { val testBaseEnd = "For$responseBody" val testBundle = testBaseStart+testBaseEnd - val bundleTested = testBundle.capitalize()+"Bundle" + val bundleTested = testBundle.replaceFirstChar {it.uppercase()}+"Bundle" val bundleTester = bundleTested+"Test" val bundleJSONPath = "$jsonPath$testBundle/" val bundleFilename = bundleJSONPath+"service.json" @@ -775,7 +775,7 @@ if (true) { "name" to "param1", "datatype" to atomicCurr, "multiple" to testMultiple, "nullable" to testNullable )) - val testName = testBaseStart+atomicCurr.capitalize()+testBaseEnd+testNum + val testName = testBaseStart+atomicCurr.replaceFirstChar {it.uppercase()}+testBaseEnd+testNum val testdef = if (responseReturnValue === null) mapOf( "functionName" to testName, "params" to funcParams @@ -939,7 +939,7 @@ if (true) { "multiple" to testMultiple, "nullable" to testNullable )) val testMax = 2 - val docTestName = testBaseStart+docCurr.capitalize()+testBaseEnd+(testNum * testMax) + val docTestName = testBaseStart+docCurr.replaceFirstChar {it.uppercase()}+testBaseEnd+(testNum * testMax) val docTestdef = if (responseReturnValue === null) mapOf( "functionName" to docTestName, "params" to docFuncParams @@ -955,7 +955,7 @@ if (true) { mapOf("name" to "param3", "datatype" to atomic2) ) - val testName = testBaseStart+docCurr.capitalize()+testBaseEnd+((testNum * testMax) + j - 1) + val testName = testBaseStart+docCurr.replaceFirstChar {it.uppercase()}+testBaseEnd+((testNum * testMax) + j - 1) val testdef1 = replaceFuncName(docTestdef, testName) val testdef2 = if (j < testMax) testdef1 @@ -1089,7 +1089,7 @@ if (true) { val funcReturn = mapOf( "datatype" to atomicCurr, "nullable" to testNullable ) - val testName = testBaseStart+testBaseEnd+atomicCurr.capitalize()+testNum + val testName = testBaseStart+testBaseEnd+atomicCurr.replaceFirstChar {it.uppercase()}+testNum val testdef = if (requestParams === null) mapOf( "functionName" to testName, "return" to funcReturn @@ -1211,7 +1211,7 @@ if (true) { "datatype" to docCurr, "multiple" to testMultiple, "nullable" to testNullable ) - val testName = testBaseStart+testBaseEnd+docCurr.capitalize()+testNum + val testName = testBaseStart+testBaseEnd+docCurr.replaceFirstChar {it.uppercase()}+testNum val testdef = if (requestParams === null) mapOf( "functionName" to testName, "return" to funcReturn @@ -1305,7 +1305,7 @@ if (true) { "datatype" to docCurr, "multiple" to testMultiple, "nullable" to testNullable ) - val testName = testBaseStart + testBaseEnd + docCurr.capitalize() + testNum + val testName = testBaseStart + testBaseEnd + docCurr.replaceFirstChar {it.uppercase()} + testNum val testdef = if (requestParams === null) mapOf( "functionName" to testName, "return" to funcReturn @@ -1421,7 +1421,7 @@ if (true) { if (true) { val atomicMappingConstructors = getAtomicMappingConstructors() val atomicMappingBundle = "mapAtomics" - val atomicMappingBundleTested = atomicMappingBundle.capitalize()+"Bundle" + val atomicMappingBundleTested = atomicMappingBundle.replaceFirstChar {it.uppercase()}+"Bundle" val atomicMappingBundleTester = atomicMappingBundleTested+"Test" val atomicMappingBundleJSONPath = "$jsonPath$atomicMappingBundle/" val atomicMappingBundleFilename = atomicMappingBundleJSONPath+"service.json" @@ -1438,12 +1438,12 @@ if (true) { val atomicMappingDatatypes = atomicMappingConstructors.keys.toTypedArray() for (datatypeNum in atomicMappingDatatypes.indices) { val datatype = atomicMappingDatatypes[datatypeNum] - val testBaseStart = atomicMappingBundle+datatype.capitalize() + val testBaseStart = atomicMappingBundle+datatype.replaceFirstChar {it.uppercase()} val datatypeConstructors = atomicMappingConstructors[datatype] as Map val modExtension = modExtensions[datatypeNum % modExtensions.size] for (mappedType in datatypeConstructors.keys) { - // mappedType.capitalize().replace('.', '_') - val testMapped = mappedType.split('.').joinToString("") { word -> word.capitalize() } + // mappedType.replaceFirstChar {it.uppercase()}.replace('.', '_') + val testMapped = mappedType.split('.').joinToString("") { word -> word.replaceFirstChar {it.uppercase()} } val mappedConstructor = datatypeConstructors[mappedType] as String val typeConstructors = mapOf(datatype to mappedConstructor) for (testNum in allTestTypes.indices) { @@ -1511,7 +1511,7 @@ if (true) { if (true) { val documentMappingConstructors = getDocumentMappingConstructors() val documentMappingBundle = "mapDocuments" - val documentMappingBundleTested = documentMappingBundle.capitalize()+"Bundle" + val documentMappingBundleTested = documentMappingBundle.replaceFirstChar {it.uppercase()}+"Bundle" val documentMappingBundleTester = documentMappingBundleTested+"Test" val documentMappingBundleJSONPath = "$jsonPath$documentMappingBundle/" val documentMappingBundleFilename = documentMappingBundleJSONPath+"service.json" @@ -1528,11 +1528,11 @@ if (true) { val documentMappedDatatypes = documentMappingConstructors.keys.toTypedArray() for (datatypeNum in documentMappedDatatypes.indices) { val datatype = documentMappedDatatypes[datatypeNum] - val testBaseStart = documentMappingBundle+datatype.capitalize() + val testBaseStart = documentMappingBundle+datatype.replaceFirstChar {it.uppercase()} val datatypeConstructors = documentMappingConstructors[datatype] as Map val modExtension = modExtensions[datatypeNum % modExtensions.size] for (mappedType in datatypeConstructors.keys) { - val testMapped = mappedType.split('.').joinToString("") { word -> word.capitalize() } + val testMapped = mappedType.split('.').joinToString("") { word -> word.replaceFirstChar {it.uppercase()} } val mappedConstructor = datatypeConstructors[mappedType] as String val typeConstructors = mapOf(datatype to mappedConstructor) for (testNum in allTestTypes.indices) { @@ -1662,8 +1662,8 @@ if (true) { ) val moduleInitTestString = serializer.writeValueAsString(moduleInitTestdef) for (modExtension in modExtensions) { - val moduleInitBundle = "moduleInit"+modExtension.capitalize() - val moduleInitBundleTested = moduleInitBundle.capitalize()+"Bundle" + val moduleInitBundle = "moduleInit"+modExtension.replaceFirstChar {it.uppercase()} + val moduleInitBundleTested = moduleInitBundle.replaceFirstChar {it.uppercase()}+"Bundle" val moduleInitBundleTester = moduleInitBundleTested+"Test" val moduleInitBundleJSONPath = "$jsonPath$moduleInitBundle/" val moduleInitBundleFilename = moduleInitBundleJSONPath+"service.json"