From e3d4e931b093cf92de0db8be0ab128522c39b5a5 Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 20:53:32 -0500 Subject: [PATCH] TestSearchHistory tests added --- .../test/TestSearchHistoryGetter.java | 42 +++++++++++++++++++ .../test/TestSearchHistoryUpdater.java | 41 ++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java create mode 100644 Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java diff --git a/Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java new file mode 100644 index 0000000..20e0cea --- /dev/null +++ b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java @@ -0,0 +1,42 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + + +public class TestSearchHistoryGetter { + + @Test + public void testSearchHistoryValid() { + testSearchHistoryGetterMock(false); + } + + @Test + public void testSearchHistoryError() { + testSearchHistoryGetterMock(true); + } + + public void testSearchHistoryGetterMock(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + SearchHistoryGetter searchHistoryGetter = Mockito.spy(new SearchHistoryGetter(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + + try { + Object rawIDReturn = searchHistoryGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn != null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java new file mode 100644 index 0000000..99e9d8c --- /dev/null +++ b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java @@ -0,0 +1,41 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestSearchHistoryUpdater { + + @Test + public void testSearchHistoryUpdaterValid() { + testSearchHistoryUpdater(false); + } + + @Test + public void testSearchHistoryUpdaterError() { + testSearchHistoryUpdater(true); + } + + public void testSearchHistoryUpdater(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + SearchHistoryUpdater testSearchHistoryUpdater = Mockito.spy(new SearchHistoryUpdater(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + + try { + Object rawIDReturn = testSearchHistoryUpdater.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn == null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +}