mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Mocked List Delete
This commit is contained in:
parent
bf1b0e0a98
commit
c5313f5753
Binary file not shown.
@ -63,6 +63,16 @@ public class TestListAdder {
|
|||||||
Map<String, Object> ignore = new HashMap<>();
|
Map<String, Object> ignore = new HashMap<>();
|
||||||
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||||
body.put("name", "aname");
|
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) {
|
if(injector.getStatementString() == null) {
|
||||||
assert(false);
|
assert(false);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
|
||||||
import java.security.AccessControlException;
|
import java.security.AccessControlException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -16,7 +21,7 @@ public class TestListDelete {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListDeleterError() {
|
public void testListDeleterError() {
|
||||||
testListDeleterCore(true, true);
|
testListDeleterCoreMock(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListDeleterCore(boolean shouldThrow, boolean hasAccess) {
|
public void testListDeleterCore(boolean shouldThrow, boolean hasAccess) {
|
||||||
@ -50,4 +55,38 @@ public class TestListDelete {
|
|||||||
assert !hasAccess;
|
assert !hasAccess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testListDeleterCoreMock(boolean shouldThrow, boolean hasAccess) {
|
||||||
|
StatementInjector injector;
|
||||||
|
ArrayList<Object> 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<String, Object> body = (Map<String, Object>) TestBasicHandler.buildFullSampleMap().get("body");
|
||||||
|
HashMap<String, String> queryParams = (HashMap<String, String>) 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user