ListKeyIndexBuilder extends AbstractDataBuilder { private Integer getListIndexInKeys(final Class<?>[] keyMethodParamTypes, final Method targetMethod) { Integer listIndexInKeys = null; for (int i = 0; i < keyMethodParamTypes.length; i++) { if (isList(keyMethodParamTypes[i])) { if (listIndexInKeys != null) { throw new InvalidAnnotationException( "There are more than one method's parameter annotated by @ParameterValueKeyProvider that is list " + targetMethod.toString()); } listIndexInKeys = i; } } return listIndexInKeys; }    }
@Test public void shouldNotPopulateIfExpectedAnnotationNotSupportListKey() throws Exception { final Class<? extends Annotation> expected = InvalidateAssignCache.class; final Method targetMethod = null; builder.populate(data, null, expected, targetMethod); assertEquals(Integer.MIN_VALUE, data.getListIndexInKeys()); assertEquals(Integer.MIN_VALUE, data.getListIndexInMethodArgs()); }
@Test public void shouldPopulateListKeyIndex() throws Exception { final Class<? extends Annotation> expected = InvalidateMultiCache.class; final Method targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect().method("populateListKey01").withArgs(List.class); data.setKeyIndexes(Collections.singleton(0)); builder.populate(data, null, expected, targetMethod); assertEquals(0, data.getListIndexInKeys()); assertEquals(0, data.getListIndexInMethodArgs()); }
@Test public void shouldPopulateListKeyIndexIfArrayList() throws Exception { final Class<? extends Annotation> expected = UpdateMultiCache.class; final Method targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect().method("populateListKey04") .withArgs(ArrayList.class); data.setKeyIndexes(Collections.singleton(0)); builder.populate(data, null, expected, targetMethod); assertEquals(0, data.getListIndexInKeys()); assertEquals(0, data.getListIndexInMethodArgs()); }
@Test public void shouldPopulateListKeyIndexIfLinkedList() throws Exception { final Class<? extends Annotation> expected = ReadThroughMultiCache.class; final Method targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect().method("populateListKey05") .withArgs(LinkedList.class); data.setKeyIndexes(Collections.singleton(0)); builder.populate(data, null, expected, targetMethod); assertEquals(0, data.getListIndexInKeys()); assertEquals(0, data.getListIndexInMethodArgs()); }
@Test public void shouldPopulateCorrectListKeyIndex() throws Exception { final Class<? extends Annotation> expected = InvalidateMultiCache.class; final Method targetMethod = new Mirror().on(AnnotationDataDummy.class).reflect().method("populateListKey06") .withArgs(String.class, List.class); data.setKeyIndexes(Arrays.asList(1, 0)); builder.populate(data, null, expected, targetMethod); assertEquals(0, data.getListIndexInKeys()); assertEquals(1, data.getListIndexInMethodArgs()); }