From 4b1f06cdcd891c7dfb6c5c17af4167fe15bc1b09 Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 20:09:08 -0500 Subject: [PATCH] ListDuplicate tests added --- Lambdas/Lists/List/src/List.java | 22 +++++----- Lambdas/Lists/List/src/ListGetter.java | 2 +- .../ListDuplicate/test/TestListDuplicate.java | 43 +++++++++++++++++++ 3 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java diff --git a/Lambdas/Lists/List/src/List.java b/Lambdas/Lists/List/src/List.java index 659a212..7e0b6ae 100644 --- a/Lambdas/Lists/List/src/List.java +++ b/Lambdas/Lists/List/src/List.java @@ -83,15 +83,15 @@ public class List { return uiPosition; } - public void setUiPosition(Integer uiPosition) { - this.uiPosition = uiPosition; - } - - public ItemEntry[] getEntries() { - return entries.toArray(new ItemEntry[entries.size()]); - } - - public void addItemEntry(ItemEntry entry) { - entries.add(entry); - } +// public void setUiPosition(Integer uiPosition) { +// this.uiPosition = uiPosition; +// } +// +// public ItemEntry[] getEntries() { +// return entries.toArray(new ItemEntry[entries.size()]); +// } +// +// public void addItemEntry(ItemEntry entry) { +// entries.add(entry); +// } } diff --git a/Lambdas/Lists/List/src/ListGetter.java b/Lambdas/Lists/List/src/ListGetter.java index 98fbc5c..953e8dd 100644 --- a/Lambdas/Lists/List/src/ListGetter.java +++ b/Lambdas/Lists/List/src/ListGetter.java @@ -78,7 +78,7 @@ public class ListGetter implements CallHandler{ getListEntries.setInt(1, id); ResultSet getEntryResults = getListEntries.executeQuery(); while (getEntryResults.next()) { - retrievedList.addItemEntry(new ItemEntry(id, getEntryResults)); + //retrievedList.addItemEntry(new ItemEntry(id, getEntryResults)); } System.out.println(retrievedList); return retrievedList; diff --git a/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java new file mode 100644 index 0000000..658db04 --- /dev/null +++ b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java @@ -0,0 +1,43 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestListDuplicate { + + @Test + public void testListEntryAdderValid() { + testListEntryAdderCoreMock(false); + } + + @Test + public void testListEntryAdderError() { + testListEntryAdderCoreMock(true); + } + + public void testListEntryAdderCoreMock(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + ListDuplicater listDuplicater = Mockito.spy(new ListDuplicater(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + body.put("name", "list1"); + body.put("listID", 1); + + try { + Object rawIDReturn = listDuplicater.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn != null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +}