ConverterHelper { void setTypeConvertersInOrder(Collection<TypeConverter> typeConverters) { LockableList<TypeConverter> newList = new LockableList<>(); newList.addAll(typeConverters); newList.lock(); typeConvertersInOrder = newList; for (TypeConverter tc : newList) { String name = null; if (tc instanceof Named) { name = ((Named) tc).getName(); } if (null == name) { name = tc.getClass().getName(); } typeConverterInstances.put(name, tc); } }  ToConverter getToConverter(Class toClass, Class domainClass);  }
@Test public void testSetTypeConvertersInOrder() throws Exception { List org = (List) ReflectionTestUtils.getField(converterHelper, "typeConvertersInOrder"); TypeConverter typeConverter = mock(TypeConverter.class); assertThat(org.size()).isEqualTo(0); converterHelper.setTypeConvertersInOrder(Collections.singletonList(typeConverter)); List res = (List) ReflectionTestUtils.getField(converterHelper, "typeConvertersInOrder"); assertThat(res.size()).isEqualTo(1); assertThat((Object) res).isInstanceOf(LockableList.class); assertThat((Boolean) ReflectionTestUtils.getField(res, "readOnly")).isTrue(); }
@Test public void testSetTypeConvertersInOrderNamed() throws Exception { List org = (List) ReflectionTestUtils.getField(converterHelper, "typeConvertersInOrder"); NamedTypeConverter typeConverter = mock(NamedTypeConverter.class); assertThat(org.size()).isEqualTo(0); converterHelper.setTypeConvertersInOrder((Collection) Collections.singletonList(typeConverter)); List res = (List) ReflectionTestUtils.getField(converterHelper, "typeConvertersInOrder"); assertThat(res.size()).isEqualTo(1); assertThat((Object) res).isInstanceOf(LockableList.class); assertThat((Boolean) ReflectionTestUtils.getField(res, "readOnly")).isTrue(); verify(typeConverter).getName(); }