ParamProcessors { public static Iterator<EncodedPair> iterate(List<Param> params, Charset charset){ return iterate(params, charset, true); } private  ParamProcessors(); static ParamProcessor newInstance(ParamType type, String listSeparator); static Iterator<EncodedPair> iterate(List<Param> params, Charset charset); static Iterator<EncodedPair> iterate(List<Param> params, Charset charset, boolean encodeIfNeeded);  }
@Test public void shouldIterateOverPreProccessedParamValues() throws Exception { List<EncodedPair> expected1 = asList(mock(EncodedPair.class), mock(EncodedPair.class)); List<EncodedPair> expected2 = asList(); List<EncodedPair> expected3 = asList(mock(EncodedPair.class)); Param mockParam1 = mockParam(true, expected1); Param mockParam2 = mockParam(true, expected2); Param mockParam3 = mockParam(true, expected3); Iterator<EncodedPair> actual = ParamProcessors.iterate(asList(mockParam1, mockParam2, mockParam3), UTF8); assertTrue(actual.hasNext()); assertEquals(expected1.get(0), actual.next()); assertTrue(actual.hasNext()); assertEquals(expected1.get(1), actual.next()); assertTrue(actual.hasNext()); assertEquals(expected3.get(0), actual.next()); assertFalse(actual.hasNext()); }
@Test public void shouldIterateOverPreProccessedParamValuesNonEncoding() throws Exception { List<EncodedPair> expected1 = asList(mock(EncodedPair.class), mock(EncodedPair.class)); List<EncodedPair> expected2 = asList(); List<EncodedPair> expected3 = asList(mock(EncodedPair.class)); Param mockParam1 = mockParam(false, expected1); Param mockParam2 = mockParam(false, expected2); Param mockParam3 = mockParam(false, expected3); Iterator<EncodedPair> actual = ParamProcessors.iterate(asList(mockParam1, mockParam2, mockParam3), UTF8, false); assertTrue(actual.hasNext()); assertEquals(expected1.get(0), actual.next()); assertTrue(actual.hasNext()); assertEquals(expected1.get(1), actual.next()); assertTrue(actual.hasNext()); assertEquals(expected3.get(0), actual.next()); assertFalse(actual.hasNext()); }
@Test(expected = CRestException.class) public void shouldThrowExceptionWhenParamProcessingFail() throws Exception { Param mockParam = mock(Param.class); Exception exception = new Exception(); ParamProcessor paramProcessor = mock(ParamProcessor.class); when(paramProcessor.process(mockParam, UTF8, true)).thenThrow(exception); ParamConfig paramConfig = mock(ParamConfig.class); when(paramConfig.getParamProcessor()).thenReturn(paramProcessor); when(mockParam.getParamConfig()).thenReturn(paramConfig); try { ParamProcessors.iterate(asList(mockParam), UTF8).hasNext(); } catch (Exception e) { assertSame(exception, e.getCause()); throw e; } }
@Test(expected = UnsupportedOperationException.class) public void shouldFailWhenTryingToRemoveFromIterator() throws Exception { Param mockParam = mock(Param.class); ParamProcessors.iterate(asList(mockParam), UTF8).remove(); }