diff --git a/Lambdas/Lists/List/target/artifacts/Lists_jar/Lists.jar b/Lambdas/Lists/List/target/artifacts/Lists_jar/Lists.jar index 10f0103..d347f7d 100644 Binary files a/Lambdas/Lists/List/target/artifacts/Lists_jar/Lists.jar and b/Lambdas/Lists/List/target/artifacts/Lists_jar/Lists.jar differ diff --git a/Lambdas/Lists/List/test/TestListAdder.java b/Lambdas/Lists/List/test/TestListAdder.java index 9ef83ad..f933421 100644 --- a/Lambdas/Lists/List/test/TestListAdder.java +++ b/Lambdas/Lists/List/test/TestListAdder.java @@ -63,6 +63,16 @@ public class TestListAdder { Map ignore = new HashMap<>(); Map body = TestInputUtils.addBody(ignore); body.put("name", "aname"); + try { + Object rawIDReturn = listAdder.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + if (!(rawIDReturn.getClass() == Integer.class)) { + assert false; + return; + } + } catch(SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } if(injector.getStatementString() == null) { assert(false); return; diff --git a/Lambdas/Lists/List/test/TestListDelete.java b/Lambdas/Lists/List/test/TestListDelete.java index 162b56a..240261b 100644 --- a/Lambdas/Lists/List/test/TestListDelete.java +++ b/Lambdas/Lists/List/test/TestListDelete.java @@ -1,4 +1,9 @@ import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; + +import static org.mockito.Mockito.*; + import java.security.AccessControlException; import java.sql.SQLException; @@ -16,7 +21,7 @@ public class TestListDelete { @Test public void testListDeleterError() { - testListDeleterCore(true, true); + testListDeleterCoreMock(true, true); } public void testListDeleterCore(boolean shouldThrow, boolean hasAccess) { @@ -50,4 +55,38 @@ public class TestListDelete { assert !hasAccess; } } + + public void testListDeleterCoreMock(boolean shouldThrow, boolean hasAccess) { + StatementInjector injector; + ArrayList rsReturns = new ArrayList<>(); + rsReturns.add("cognitoID"); + try { + if (!hasAccess) { + rsReturns = null; + } + injector = new StatementInjector(null, rsReturns, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + + ListDeleter testMock = Mockito.spy(new ListDeleter(injector, "cognitoID")); + + Map body = (Map) TestBasicHandler.buildFullSampleMap().get("body"); + HashMap queryParams = (HashMap) TestBasicHandler.buildFullSampleMap().get("body"); + queryParams.put("id", "30"); + + try { + when(testMock.conductAction(body, queryParams, "cognitoID")).thenReturn(shouldThrow); + Object rawIDReturn = testMock.conductAction(body, queryParams, "cognitoID"); + assert !shouldThrow; + assert (rawIDReturn == null); + assert (injector.getStatementString().equals("SELECT * FROM List WHERE (owner = ? AND listID = ?);DELETE FROM ListSharee where listID = ?;DELETE FROM ListProduct where listID = ?;DELETE FROM List WHERE listID = ?;[30]")); + } catch (SQLException throwables) { + assert shouldThrow ; + } catch (AccessControlException accessControlException) { + assert !hasAccess; + } + } }