ListDuplicate tests added

This commit is contained in:
Adam Ding 2020-12-01 20:09:08 -05:00
parent a60e26dc3a
commit 4b1f06cdcd
3 changed files with 55 additions and 12 deletions

View File

@ -83,15 +83,15 @@ public class List {
return uiPosition;
}
public void setUiPosition(Integer uiPosition) {
this.uiPosition = uiPosition;
}
public ItemEntry[] getEntries() {
return entries.toArray(new ItemEntry[entries.size()]);
}
public void addItemEntry(ItemEntry entry) {
entries.add(entry);
}
// public void setUiPosition(Integer uiPosition) {
// this.uiPosition = uiPosition;
// }
//
// public ItemEntry[] getEntries() {
// return entries.toArray(new ItemEntry[entries.size()]);
// }
//
// public void addItemEntry(ItemEntry entry) {
// entries.add(entry);
// }
}

View File

@ -78,7 +78,7 @@ public class ListGetter implements CallHandler{
getListEntries.setInt(1, id);
ResultSet getEntryResults = getListEntries.executeQuery();
while (getEntryResults.next()) {
retrievedList.addItemEntry(new ItemEntry(id, getEntryResults));
//retrievedList.addItemEntry(new ItemEntry(id, getEntryResults));
}
System.out.println(retrievedList);
return retrievedList;

View File

@ -0,0 +1,43 @@
import org.junit.Test;
import org.mockito.Mockito;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class TestListDuplicate {
@Test
public void testListEntryAdderValid() {
testListEntryAdderCoreMock(false);
}
@Test
public void testListEntryAdderError() {
testListEntryAdderCoreMock(true);
}
public void testListEntryAdderCoreMock(boolean shouldThrow) {
StatementInjector injector;
try {
injector = new StatementInjector(null, null, shouldThrow);
} catch (SQLException throwables) {
throwables.printStackTrace();
assert false; //Error in test infrastructure
return;
}
ListDuplicater listDuplicater = Mockito.spy(new ListDuplicater(injector, "cognitoID"));
Map<String, Object> ignore = new HashMap<>();
Map<String, Object> body = TestInputUtils.addBody(ignore);
body.put("name", "list1");
body.put("listID", 1);
try {
Object rawIDReturn = listDuplicater.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
assert (rawIDReturn != null);
} catch (SQLException throwables) {
assert shouldThrow;
throwables.printStackTrace();
}
}
}