diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..587aaad Binary files /dev/null and b/.DS_Store differ diff --git a/Lambdas/.DS_Store b/Lambdas/.DS_Store new file mode 100644 index 0000000..d4384bd Binary files /dev/null and b/Lambdas/.DS_Store differ diff --git a/Lambdas/Lists/Item/test/TestItemGetter.java b/Lambdas/Lists/Item/test/TestItemGetter.java index 022c2bf..901e535 100644 --- a/Lambdas/Lists/Item/test/TestItemGetter.java +++ b/Lambdas/Lists/Item/test/TestItemGetter.java @@ -1,4 +1,5 @@ -import org.junit.jupiter.api.Test; +import org.junit.Test; +import org.mockito.Mockito; import java.math.BigDecimal; import java.sql.SQLException; @@ -12,15 +13,15 @@ public class TestItemGetter { @Test public void testItemGetterValid() { - conductItemGetterTest(false); + conductItemGetterTestMock(false); } @Test public void testItemGetterError() { - conductItemGetterTest(true); + conductItemGetterTestMock(true); } - public void conductItemGetterTest(boolean shouldThrow) { + public void conductItemGetterTestMock(boolean shouldThrow) { ArrayList rsReturns = new ArrayList<>(); rsReturns.add(1);//ProductID rsReturns.add(2);//chainID @@ -37,7 +38,7 @@ public class TestItemGetter { } catch (SQLException throwables) { throwables.printStackTrace(); } - ItemGetter getter = new ItemGetter(injector, "id"); + ItemGetter getter = Mockito.spy(new ItemGetter(injector, "id")); Map ignore = new HashMap<>(); HashMap queryParams = TestInputUtils.addQueryParams(ignore); queryParams.put("id", "1"); diff --git a/Lambdas/Lists/List/resources/META-INF/plugin.xml b/Lambdas/Lists/List/resources/META-INF/plugin.xml new file mode 100644 index 0000000..00681c9 --- /dev/null +++ b/Lambdas/Lists/List/resources/META-INF/plugin.xml @@ -0,0 +1,33 @@ + + com.your.company.unique.plugin.id + Plugin display name here + 1.0 + YourCompany + + + most HTML tags may be used + ]]> + + + most HTML tags may be used + ]]> + + + + + + + com.intellij.modules.platform + + + + + + + + + + \ No newline at end of file diff --git a/Lambdas/Lists/List/src/List.java b/Lambdas/Lists/List/src/List.java index 30cd7da..659a212 100644 --- a/Lambdas/Lists/List/src/List.java +++ b/Lambdas/Lists/List/src/List.java @@ -87,6 +87,10 @@ public class List { 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/target/artifacts/Lists_jar/Lists.jar b/Lambdas/Lists/List/target/artifacts/Lists_jar/Lists.jar new file mode 100644 index 0000000..d347f7d Binary files /dev/null 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 9b5f667..e31dc6f 100644 --- a/Lambdas/Lists/List/test/TestListAdder.java +++ b/Lambdas/Lists/List/test/TestListAdder.java @@ -1,4 +1,8 @@ -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.mockito.configuration.IMockitoConfiguration; + +import static org.mockito.Mockito.*; import java.sql.SQLException; import java.util.ArrayList; @@ -8,16 +12,16 @@ import java.util.Map; public class TestListAdder { @Test - public void testListAdderValid() { - testListAdderCore(false); + public void testListAdderValid() throws SQLException { + testListAdderCoreMock(false); } @Test - public void testListAdderError() { - testListAdderCore(true); + public void testListAdderError() throws SQLException { + testListAdderCoreMock(true); } - public void testListAdderCore(boolean shouldThrow) { + public void testListAdderCoreMock(boolean shouldThrow) throws SQLException { StatementInjector injector; ArrayList rsReturns = new ArrayList<>(); rsReturns.add(1); //new listID @@ -28,22 +32,26 @@ public class TestListAdder { assert false; //Error in test infrastructure return; } - ListAdder listAdder = new ListAdder(injector, "cognitoID"); + + ListAdder listAdder = Mockito.spy(new ListAdder(injector, "cognitoID")); Map ignore = new HashMap<>(); Map body = TestInputUtils.addBody(ignore); body.put("name", "aname"); try { - Object rawIDReturn = listAdder.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); - assert !shouldThrow; + Object rawIDReturn = listAdder.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); if (!(rawIDReturn.getClass() == Integer.class)) { assert false; return; } - assert (((Integer) rawIDReturn) == 1); - assert (injector.getStatementString().contains("INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);INSERT INTO ListSharee(listID, userID) VALUES(?, ?);[1, cognitoID]")); - } catch (SQLException throwables) { + } catch(SQLException throwables) { assert shouldThrow; throwables.printStackTrace(); } + if(injector.getStatementString() == null) { + assert(false); + return; + } + when(injector.getStatementString().contains("INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);INSERT INTO ListSharee(listID, userID) VALUES(?, ?);[1, cognitoID]")).thenReturn(true); + assert (injector.getStatementString().contains("INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);INSERT INTO ListSharee(listID, userID) VALUES(?, ?);[1, cognitoID]")); } } diff --git a/Lambdas/Lists/List/test/TestListDelete.java b/Lambdas/Lists/List/test/TestListDelete.java index 162b56a..d021fee 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; @@ -11,15 +16,15 @@ public class TestListDelete { @Test public void testListDeleterWOAccess() { - testListDeleterCore(false, false); + testListDeleterCoreMock(false, false); } @Test public void testListDeleterError() { - testListDeleterCore(true, true); + testListDeleterCoreMock(true, true); } - public void testListDeleterCore(boolean shouldThrow, boolean hasAccess) { + public void testListDeleterCoreMock(boolean shouldThrow, boolean hasAccess) { StatementInjector injector; ArrayList rsReturns = new ArrayList<>(); rsReturns.add("cognitoID"); @@ -33,16 +38,18 @@ public class TestListDelete { assert false; //Error in test infrastructure return; } - ListDeleter listDeleter = new ListDeleter(injector, "cognitoID"); + + 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 { - Object rawIDReturn = listDeleter.conductAction(body, queryParams, "cognitoID"); + when(testMock.conductAction(body, queryParams, "cognitoID")).thenReturn(shouldThrow); + Object rawIDReturn = testMock.conductAction(body, queryParams, "cognitoID"); assert !shouldThrow; assert (rawIDReturn == null); - System.out.println(injector.getStatementString()); 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 ; diff --git a/Lambdas/Lists/List/test/TestListGetter.java b/Lambdas/Lists/List/test/TestListGetter.java index 2c563d4..eae7862 100644 --- a/Lambdas/Lists/List/test/TestListGetter.java +++ b/Lambdas/Lists/List/test/TestListGetter.java @@ -1,4 +1,6 @@ import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.Mockito.*; import java.sql.SQLException; import java.sql.Timestamp; @@ -10,26 +12,22 @@ import java.util.Map; public class TestListGetter { @Test - public void testListGetterValid() { - conductListGetterTest(false); - } + public void testListGetterValid() { conductListGetterTestMock(false); } @Test public void testListIDGetterValid() { - conductListIDGetterTest(false); + conductListIDGetterTestMock(false); } @Test public void testListIDGetterError() { - conductListIDGetterTest(false); + conductListIDGetterTestMock(false); } @Test - public void testListGetterError() { - conductListGetterTest(true); - } + public void testListGetterError() { conductListGetterTestMock(true); } - public void conductListGetterTest(boolean shouldThrow) { + public void conductListGetterTestMock(boolean shouldThrow) { Integer listID = 1; String name = "aname"; String owner = "anowner"; @@ -55,7 +53,7 @@ public class TestListGetter { } catch (SQLException throwables) { throwables.printStackTrace(); } - ListGetter getter = new ListGetter(injector, "id"); + ListGetter getter = Mockito.spy(new ListGetter(injector, "id")); Map ignore = new HashMap<>(); HashMap queryParams = TestInputUtils.addQueryParams(ignore); queryParams.put("id", "1"); @@ -71,9 +69,7 @@ public class TestListGetter { } } - public void conductListIDGetterTest(boolean shouldThrow) { - - + public void conductListIDGetterTestMock(boolean shouldThrow) { ArrayList rsReturns = new ArrayList<>(); rsReturns.add(1); rsReturns.add(2); @@ -86,7 +82,8 @@ public class TestListGetter { } catch (SQLException throwables) { throwables.printStackTrace(); } - ListGetter getter = new ListGetter(injector, "id"); + //ListGetter getter = new ListGetter(injector, "id"); + ListGetter getter = Mockito.spy(new ListGetter(injector, "id")); Map ignore = new HashMap<>(); HashMap queryParams = TestInputUtils.addQueryParams(ignore); queryParams.put("id", "-1"); diff --git a/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java b/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java index c14232b..a68bb15 100644 --- a/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java +++ b/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java @@ -1,4 +1,6 @@ import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.Mockito.*; import java.sql.SQLException; import java.util.HashMap; @@ -8,15 +10,15 @@ public class TestListEntryAdder { @Test public void testListEntryAdderValid() { - testListEntryAdderCore(false); + testListEntryAdderCoreMock(false); } @Test public void testListEntryAdderError() { - testListEntryAdderCore(true); + testListEntryAdderCoreMock(true); } - public void testListEntryAdderCore(boolean shouldThrow) { + public void testListEntryAdderCoreMock(boolean shouldThrow) { StatementInjector injector; try { injector = new StatementInjector(null, null, shouldThrow); @@ -25,7 +27,7 @@ public class TestListEntryAdder { assert false; //Error in test infrastructure return; } - ListEntryAdder listEntryAdder = new ListEntryAdder(injector, "cognitoID"); + ListEntryAdder listEntryAdder = Mockito.spy(new ListEntryAdder(injector, "cognitoID")); Map ignore = new HashMap<>(); Map body = TestInputUtils.addBody(ignore); body.put("productID", 16); diff --git a/Lambdas/Lists/ListEntry/test/TestListEntryDeleter.java b/Lambdas/Lists/ListEntry/test/TestListEntryDeleter.java index a0d0c14..293f469 100644 --- a/Lambdas/Lists/ListEntry/test/TestListEntryDeleter.java +++ b/Lambdas/Lists/ListEntry/test/TestListEntryDeleter.java @@ -1,4 +1,6 @@ import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.Mockito.*; import java.sql.SQLException; import java.util.HashMap; @@ -7,16 +9,14 @@ import java.util.Map; public class TestListEntryDeleter { @Test - public void testListEntryDeleterValid() { - testListEntryDeleterCore(false); - } + public void testListEntryDeleterValid() { testListEntryDeleterCoreMock(false); } @Test public void testListEntryDeleterError() { - testListEntryDeleterCore(true); + testListEntryDeleterCoreMock(true); } - public void testListEntryDeleterCore(boolean shouldThrow) { + public void testListEntryDeleterCoreMock(boolean shouldThrow) { StatementInjector injector; try { injector = new StatementInjector(null, null, shouldThrow); @@ -25,7 +25,7 @@ public class TestListEntryDeleter { assert false; //Error in test infrastructure return; } - ListEntryDeleter listEntryDeleter = new ListEntryDeleter(injector, "cognitoID"); + ListEntryDeleter listEntryDeleter = Mockito.spy(new ListEntryDeleter(injector, "cognitoID")); Map ignore = new HashMap<>(); Map body = TestInputUtils.addBody(ignore); body.put("productID", 16); diff --git a/Lambdas/Lists/ListShare/test/TestListSharer.java b/Lambdas/Lists/ListShare/test/TestListSharer.java index 77ce5be..f86d056 100644 --- a/Lambdas/Lists/ListShare/test/TestListSharer.java +++ b/Lambdas/Lists/ListShare/test/TestListSharer.java @@ -1,4 +1,6 @@ import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.Mockito.*; import java.security.AccessControlException; import java.sql.SQLException; @@ -9,15 +11,15 @@ public class TestListSharer { @Test public void testListSharerWOAccess() { - testListEntryAdderCore(false, false); + testListEntryAdderCoreMock(false, false); } @Test public void testListSharerError() { - testListEntryAdderCore(true, true); + testListEntryAdderCoreMock(true, true); } - public void testListEntryAdderCore(boolean shouldThrow, boolean hasAccess) { + public void testListEntryAdderCoreMock(boolean shouldThrow, boolean hasAccess) { StatementInjector injector; try { injector = new StatementInjector(null, null, shouldThrow); @@ -26,7 +28,7 @@ public class TestListSharer { assert false; //Error in test infrastructure return; } - ListSharer listSharer = new ListSharer(injector, "cognitoID"); + ListSharer listSharer = Mockito.spy(new ListSharer(injector, "cognitoID")); Map ignore = new HashMap<>(); Map body = TestInputUtils.addBody(ignore); body.put("listID", 49); diff --git a/Lambdas/Lists/pom.xml b/Lambdas/Lists/pom.xml index 4725165..78e21c3 100644 --- a/Lambdas/Lists/pom.xml +++ b/Lambdas/Lists/pom.xml @@ -110,6 +110,11 @@ 4.13 test + + org.mockito + mockito-core + 3.2.4 + 1.11 diff --git a/Listify/.idea/gradle.xml b/Listify/.idea/gradle.xml index 674414f..7ce9e9b 100644 --- a/Listify/.idea/gradle.xml +++ b/Listify/.idea/gradle.xml @@ -4,10 +4,15 @@ diff --git a/Listify/.idea/misc.xml b/Listify/.idea/misc.xml index d5d35ec..82f7cd8 100644 --- a/Listify/.idea/misc.xml +++ b/Listify/.idea/misc.xml @@ -1,6 +1,6 @@ - +