Test id retrieval

This commit is contained in:
NMerz 2020-10-08 19:07:02 -04:00
parent b07fead480
commit d14383ff2e

View File

@ -14,6 +14,16 @@ public class TestListGetter {
conductListGetterTest(false); conductListGetterTest(false);
} }
@Test
public void testListIDGetterValid() {
conductListIDGetterTest(false);
}
@Test
public void testListIDGetterError() {
conductListIDGetterTest(false);
}
@Test @Test
public void testListGetterError() { public void testListGetterError() {
conductListGetterTest(true); conductListGetterTest(true);
@ -60,4 +70,36 @@ public class TestListGetter {
assert shouldThrow; assert shouldThrow;
} }
} }
public void conductListIDGetterTest(boolean shouldThrow) {
ArrayList<Object> rsReturns = new ArrayList<>();
rsReturns.add(1);
rsReturns.add(2);
rsReturns.add(3);
rsReturns.add(4);
StatementInjector injector = null;
try {
injector = new StatementInjector(null, rsReturns, shouldThrow);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
ListGetter getter = new ListGetter(injector, "id");
Map<String, Object> ignore = new HashMap<>();
HashMap<String, String> queryParams = TestInputUtils.addQueryParams(ignore);
queryParams.put("id", "-1");
try {
Object conductReturn = getter.conductAction(TestInputUtils.addBody(ignore), queryParams, "cognitoID");
assert !shouldThrow;
assert (conductReturn.getClass() == ArrayList.class);
ArrayList<Integer> listIDsReturn = (ArrayList<Integer>) conductReturn;
System.out.println(listIDsReturn.toString());
assert (listIDsReturn.toString().equals("[1, 2, 3, 4]"));
} catch (SQLException throwables) {
throwables.printStackTrace();
assert shouldThrow;
}
}
} }