public void testGetNthFSList() throws Exception {
try {
Token tok1 = new Token(jcas);
Token tok2 = new Token(jcas);
NonEmptyFSList fsList1 = new NonEmptyFSList(jcas);
fsList1.setHead(tok2);
fsList1.setTail(new EmptyFSList(jcas));
NonEmptyFSList fsList = new NonEmptyFSList(jcas);
fsList.setHead(tok1);
fsList.setTail(fsList1);
EmptyFSList emptyFsList = new EmptyFSList(jcas);
try {
emptyFsList.getNthElement(0);
assertTrue(false); // error if we get here
} catch (CASRuntimeException e) {
assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_ON_EMPTY_LIST));
System.out.print("Expected Error: ");
System.out.println(e.getMessage());
}
try {
fsList.getNthElement(-1);
assertTrue(false); // error if we get here
} catch (CASRuntimeException e) {
assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_NEGATIVE_INDEX));
System.out.print("Expected Error: ");
System.out.println(e.getMessage());
}
try {
fsList.getNthElement(2);
assertTrue(false); // error if we get here
} catch (CASRuntimeException e) {
assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_PAST_END));
System.out.print("Expected Error: ");
System.out.println(e.getMessage());
}
assertTrue(tok1 == fsList.getNthElement(0));
assertTrue(tok2 == fsList.getNthElement(1));
} catch (Exception e) {
JUnitExtension.handleException(e);
}
}