Mocked List Adder

This commit is contained in:
Adam Ding
2020-11-30 16:42:50 -05:00
parent f5d71a0fff
commit bf1b0e0a98
10 changed files with 85 additions and 15 deletions

View File

@@ -1,4 +1,7 @@
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.configuration.IMockitoConfiguration;
import static org.mockito.Mockito.*;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -13,8 +16,8 @@ public class TestListAdder {
}
@Test
public void testListAdderError() {
testListAdderCore(true);
public void testListAdderError() throws SQLException {
testListAdderCoreMock(true);
}
public void testListAdderCore(boolean shouldThrow) {
@@ -46,4 +49,25 @@ public class TestListAdder {
throwables.printStackTrace();
}
}
public void testListAdderCoreMock(boolean shouldThrow) throws SQLException {
StatementInjector injector;
ArrayList<Object> rsReturns = new ArrayList<>();
rsReturns.add(1); //new listID
injector = mock(StatementInjector.class);
injector.returnedStatement = null;
injector.rsReturns = new ArrayList(rsReturns);
injector.shouldThrow = shouldThrow;
ListAdder listAdder = new ListAdder(injector, "cognitoID");
Map<String, Object> ignore = new HashMap<>();
Map<String, Object> body = TestInputUtils.addBody(ignore);
body.put("name", "aname");
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]"));
}
}