@Test public void getMessagesNegativeIndexTest() { ChatState appState = new ChatState(); try { List<IMessage> messageList = appState.getMessagesFromIndex(-5); } catch (IllegalArgumentException ex) { return; } throw new AssertionError("AppState should have thrown an IllegalStateException"); }
public List<IMessage> getMessagesFromIndex(Integer index) { if (index<0) { throw new IllegalArgumentException("Index cannot be less than 0"); } if (index >= mNextIndex) { return new ArrayList<>(); } Integer numMessages = mNextIndex - index; List<IMessage> messages = new ArrayList<>(numMessages); for (int i = 0; i < numMessages; i++) { messages.add(mState.get(index + i)); } return messages; }
ChatState implements BabbleState { public List<IMessage> getMessagesFromIndex(Integer index) { if (index<0) { throw new IllegalArgumentException("Index cannot be less than 0"); } if (index >= mNextIndex) { return new ArrayList<>(); } Integer numMessages = mNextIndex - index; List<IMessage> messages = new ArrayList<>(numMessages); for (int i = 0; i < numMessages; i++) { messages.add(mState.get(index + i)); } return messages; } }
ChatState implements BabbleState { public List<IMessage> getMessagesFromIndex(Integer index) { if (index<0) { throw new IllegalArgumentException("Index cannot be less than 0"); } if (index >= mNextIndex) { return new ArrayList<>(); } Integer numMessages = mNextIndex - index; List<IMessage> messages = new ArrayList<>(numMessages); for (int i = 0; i < numMessages; i++) { messages.add(mState.get(index + i)); } return messages; }  }
ChatState implements BabbleState { public List<IMessage> getMessagesFromIndex(Integer index) { if (index<0) { throw new IllegalArgumentException("Index cannot be less than 0"); } if (index >= mNextIndex) { return new ArrayList<>(); } Integer numMessages = mNextIndex - index; List<IMessage> messages = new ArrayList<>(numMessages); for (int i = 0; i < numMessages; i++) { messages.add(mState.get(index + i)); } return messages; }  @Override Block processBlock(Block block); @Override void reset(); List<IMessage> getMessagesFromIndex(Integer index); }
ChatState implements BabbleState { public List<IMessage> getMessagesFromIndex(Integer index) { if (index<0) { throw new IllegalArgumentException("Index cannot be less than 0"); } if (index >= mNextIndex) { return new ArrayList<>(); } Integer numMessages = mNextIndex - index; List<IMessage> messages = new ArrayList<>(numMessages); for (int i = 0; i < numMessages; i++) { messages.add(mState.get(index + i)); } return messages; }  @Override Block processBlock(Block block); @Override void reset(); List<IMessage> getMessagesFromIndex(Integer index);  }