mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-11 02:55:04 +00:00
Mocked List Adder
This commit is contained in:
@@ -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]"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user