Array2D { public void set(int x, int y, T val) { if (x >= width || y >= height || x < 0 || y < 0) { throw new IndexOutOfBoundsException(); } arr.set(y * width + x, val); } Array2D(int width, int height); void initialise(int x, int y, T val); T get(int x, int y); void set(int x, int y, T val); int getWidth(); int getHeight(); @SuppressWarnings("unchecked") void setDimensions(int width, int height);  }
@Test public void testSet() { arr.set(3, 5, 12345); assertEquals((Integer) 12345, arr.get(3, 5)); }
@Test(expected = IndexOutOfBoundsException.class) public void testSetFail() { arr.set(40, 50, new Integer(123)); }