From 4fd884b421915771b7702ce15669a5b5330b2d8d Mon Sep 17 00:00:00 2001 From: Nate Chadwick Date: Thu, 23 Feb 2023 13:43:31 -0500 Subject: [PATCH] Fix failing test --- .../objectstore/PSWSSearchRequestTest.java | 67 ++++++++++--------- .../search/objectstore/PSWSSearchRequest.java | 23 ++----- 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/system/Testing/src/com/percussion/search/objectstore/PSWSSearchRequestTest.java b/system/Testing/src/com/percussion/search/objectstore/PSWSSearchRequestTest.java index 2742b5c5f4..d1189e0711 100644 --- a/system/Testing/src/com/percussion/search/objectstore/PSWSSearchRequestTest.java +++ b/system/Testing/src/com/percussion/search/objectstore/PSWSSearchRequestTest.java @@ -17,53 +17,49 @@ package com.percussion.search.objectstore; import com.percussion.xml.PSXmlDocumentBuilder; +import org.junit.Test; +import org.w3c.dom.Element; import java.util.HashMap; import java.util.Map; -import org.w3c.dom.Element; - -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * Unit test for PSWSSearchRequest class */ -public class PSWSSearchRequestTest extends TestCase +public class PSWSSearchRequestTest { - /** - * Default constructor. - * - * @param name the name of the test - */ - public PSWSSearchRequestTest(String name) - { - super(name); - } - +public PSWSSearchRequestTest(){} + /** * Test constructing with invalid values - * - * @throws Exception If there are any erros. + * */ - public void testCtors() throws Exception - { + @Test + public void testCtors() { // valid - PSWSSearchRequest req = null; - - // suppress eclipse warning - if (req == null); + PSWSSearchRequest req; + req = new PSWSSearchRequest("test", null); - req = new PSWSSearchRequest("test", new HashMap()); + assertNotNull(req); + req = new PSWSSearchRequest("test", new HashMap<>()); + assertNotNull(req); req = new PSWSSearchRequest(new PSWSSearchParams()); + assertNotNull(req); // invalid boolean didThrow; didThrow = false; try { - req = new PSWSSearchRequest(null, null); + req = new PSWSSearchRequest(null, null); + assertNotNull(req); } catch (Exception e) { @@ -74,7 +70,8 @@ public void testCtors() throws Exception didThrow = false; try { - req = new PSWSSearchRequest("", null); + req = new PSWSSearchRequest("", null); + assertNotNull(req); } catch (Exception e) { @@ -85,7 +82,8 @@ public void testCtors() throws Exception didThrow = false; try { - req = new PSWSSearchRequest((PSWSSearchParams)null); + req = new PSWSSearchRequest((PSWSSearchParams)null); + assertNotNull(req); } catch (Exception e) { @@ -96,7 +94,8 @@ public void testCtors() throws Exception didThrow = false; try { - req = new PSWSSearchRequest((Element)null); + req = new PSWSSearchRequest((Element)null); + assertNotNull(req); } catch (Exception e) { @@ -110,6 +109,7 @@ public void testCtors() throws Exception * * @throws Exception if there are any errors. */ + @Test public void testEquals() throws Exception { PSWSSearchRequest req1 = new PSWSSearchRequest("test", null); @@ -117,9 +117,9 @@ public void testEquals() throws Exception assertEquals(req1, req2); assertEquals(req1.hashCode(), req2.hashCode()); req2 = new PSWSSearchRequest("test2", null); - assertTrue(!req1.equals(req2)); + assertNotEquals(req1, req2); - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("foo", "bar"); params.put("a", "b"); req1 = new PSWSSearchRequest("test", params); @@ -127,10 +127,10 @@ public void testEquals() throws Exception assertEquals(req1, req2); assertEquals(req1.hashCode(), req2.hashCode()); req2 = new PSWSSearchRequest("test", null); - assertTrue(!req1.equals(req2)); + assertNotEquals(req1, req2); params.clear(); req2 = new PSWSSearchRequest("test", params); - assertTrue(!req1.equals(req2)); + assertNotEquals(req1, req2); PSWSSearchParams searchParams1 = new PSWSSearchParams(); @@ -145,7 +145,7 @@ public void testEquals() throws Exception assertEquals(req1, req2); assertEquals(req1.hashCode(), req2.hashCode()); req2 = new PSWSSearchRequest(searchParams2); - assertTrue(!req1.equals(req2)); + assertNotEquals(req1, req2); } /** @@ -153,13 +153,14 @@ public void testEquals() throws Exception * * @throws Exception if there are any errors. */ + @Test public void testXml() throws Exception { PSWSSearchRequest req1 = new PSWSSearchRequest("test", null); assertEquals(req1, new PSWSSearchRequest(req1.toXml( PSXmlDocumentBuilder.createXmlDocument()))); - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("foo", "bar"); params.put("a", "b"); req1 = new PSWSSearchRequest("test", params); diff --git a/system/src/main/java/com/percussion/search/objectstore/PSWSSearchRequest.java b/system/src/main/java/com/percussion/search/objectstore/PSWSSearchRequest.java index efc8a63061..aa24b5e293 100644 --- a/system/src/main/java/com/percussion/search/objectstore/PSWSSearchRequest.java +++ b/system/src/main/java/com/percussion/search/objectstore/PSWSSearchRequest.java @@ -64,7 +64,7 @@ public PSWSSearchRequest(PSWSSearchParams searchParams) * value is the parameter value, both as String objects. A * shallow copy of the map is stored in this object. */ - public PSWSSearchRequest(String searchName, Map params) + public PSWSSearchRequest(String searchName, Map params) { if (searchName == null || searchName.trim().length() == 0) throw new IllegalArgumentException( @@ -73,19 +73,8 @@ public PSWSSearchRequest(String searchName, Map params) m_internalSearchName = searchName; if (params != null) { - m_internalSearchParams = new HashMap(); - Iterator entries = params.entrySet().iterator(); - while (entries.hasNext()) - { - Map.Entry entry = (Map.Entry)entries.next(); - if (!(entry.getKey() instanceof String && - entry.getValue() instanceof String)) - { - throw new IllegalArgumentException("params must have" + - "only String objects for keys and values"); - } - m_internalSearchParams.put(entry.getKey(), entry.getValue()); - } + m_internalSearchParams = new HashMap<>(); + m_internalSearchParams.putAll(params); } else m_internalSearchParams = null; @@ -295,8 +284,8 @@ private void fromXml(Element src) throws PSUnknownNodeTypeException if (internalSearch) { // get params - m_internalSearchParams = new HashMap(); - NodeList params = src.getElementsByTagNameNS("*", EL_REQ_PARAM); + m_internalSearchParams = new HashMap<>(); + NodeList params = src.getElementsByTagName( EL_REQ_PARAM); int tot = params.getLength(); for (int i = 0; i < tot; i++) { @@ -412,7 +401,7 @@ else if (m_searchParams != null && !m_searchParams.equals( * may be null, possibly supplied by ctor only if * {@link #m_internalSearchName} was supplied, never modified after that. */ - private Map m_internalSearchParams; + private Map m_internalSearchParams; /** * Determines if search is to be case-insentive or if dbms defaults will be