### Question:
CategoryToPieDataset extends AbstractDataset implements PieDataset, DatasetChangeListener { @Override public Comparable getKey(int index) { Comparable result = null; if (index < 0 || index >= getItemCount()) { throw new IndexOutOfBoundsException("Invalid 'index': " + index); } if (this.extract == TableOrder.BY_ROW) { result = this.source.getColumnKey(index); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getRowKey(index); } return result; } CategoryToPieDataset(CategoryDataset source,
                                TableOrder extract,
                                int index); CategoryDataset getUnderlyingDataset(); TableOrder getExtractType(); int getExtractIndex(); @Override int getItemCount(); @Override Number getValue(int item); @Override Comparable getKey(int index); @Override int getIndex(Comparable key); @Override List<Comparable> getKeys(); @Override Number getValue(Comparable key); @Override void datasetChanged(DatasetChangeEvent event); @Override boolean equals(Object obj);  }### Answer:
@Test public void testGetKey() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.1, "R1", "C1"); underlying.addValue(2.2, "R1", "C2"); CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0); assertEquals(d1.getKey(0), "C1"); assertEquals(d1.getKey(1), "C2"); try { d1.getKey(-1); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { } try { d1.getKey(d1.getItemCount()); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { } CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0); try { p1.getKey(0); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { } }