KeySet implements Set<String> { @Override public Object[] toArray() { return toList().toArray(); } KeySet(HasKeys<?> request); @Override boolean add(String e); @Override boolean addAll(Collection<? extends String> c); @Override void clear(); @Override boolean contains(Object o); @SuppressWarnings("unchecked") @Override boolean containsAll(Collection<?> c); @Override boolean isEmpty(); @Override Iterator<String> iterator(); @Override boolean remove(Object o); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a);  }
@SuppressWarnings("unchecked") @Test public void testToArray() { Enumeration<String> keys = createMock(Enumeration.class); Enumeration<String> values1 = createMock(Enumeration.class); Enumeration<String> values2 = createMock(Enumeration.class); expect(extractor.getKeys()).andReturn(keys); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("one"); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("two"); expect(keys.hasMoreElements()).andReturn(false); replay(extractor, keys, values1, values2); assertArrayEquals(new String[] {"one", "two"}, entrySet.toArray()); verify(extractor, keys, values1, values2); }
@SuppressWarnings("unchecked") @Test public void testToArrayTArray() { Enumeration<String> keys = createMock(Enumeration.class); Enumeration<String> values1 = createMock(Enumeration.class); Enumeration<String> values2 = createMock(Enumeration.class); expect(extractor.getKeys()).andReturn(keys); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("one"); expect(keys.hasMoreElements()).andReturn(true); expect(keys.nextElement()).andReturn("two"); expect(keys.hasMoreElements()).andReturn(false); replay(extractor, keys, values1, values2); String[] realArray = new String[2]; assertArrayEquals(new String[] {"one", "two"}, entrySet.toArray(realArray)); verify(extractor, keys, values1, values2); }