Record implements Iterable<Comparable<?>>, Serializable { public Record insert(Comparable<?> value, int position) { List<Comparable<?>> recordCopyAsList = new ArrayList<>(values.length + 1); for (Comparable<?> v : values) { recordCopyAsList.add(v); } recordCopyAsList.add(position, value); return new Record(recordCopyAsList); } Record(List<? extends Comparable<?>> values);  Record(Comparable<?>... values); T get(int index); int size(); @Override Iterator<Comparable<?>> iterator(); boolean isNumeric(int index); @Override boolean equals(Object obj); @Override String toString(); Record insert(Comparable<?> value, int position);  }
@Test public void testInsertDoesNotModifyRecord() { Record record = new Record(-3.0, 1, "SomeString", null); Record identicalRecord = new Record(-3.0, 1, "SomeString", null); Comparable<?> someComparable = 5; int somePosition = 2; record.insert(someComparable, somePosition); assertThat(record, is(identicalRecord)); }
@Test public void testInsertAddsElementAtTheSpecifiedPosition() { Record record = new Record(-3.0, 1, "SomeString", null); Comparable<?> someComparable = 5; int somePosition = 2; Record newRecord = record.insert(someComparable, somePosition); assertThat(newRecord, hasItems(-3.0, 1, someComparable, "SomeString", null)); }