### Question:
CategoryToPieDataset extends AbstractDataset implements PieDataset, DatasetChangeListener { @Override public int getIndex(Comparable key) { int result = -1; if (this.source != null) { if (this.extract == TableOrder.BY_ROW) { result = this.source.getColumnIndex(key); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getRowIndex(key); } } 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 testGetIndex() { 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(0, d1.getIndex("C1")); assertEquals(1, d1.getIndex("C2")); assertEquals(-1, d1.getIndex("XX")); try { d1.getIndex(null); fail("IllegalArgumentException should have been thrown on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } }