TapestryInternalUtils { public static List<OptionModel> toOptionModels(String input) { assert input != null; List<OptionModel> result = CollectionFactory.newList(); for (String term : input.split(",")) result.add(toOptionModel(term.trim())); return result; }  static String toUserPresentable(String id); static Map<String, String> mapFromKeysAndValues(String... keysAndValues); static OptionModel toOptionModel(String input); static List<OptionModel> toOptionModels(String input); static SelectModel toSelectModel(String input); static OptionModel toOptionModel(Map.Entry input); static List<OptionModel> toOptionModels(Map<K, V> input); static SelectModel toSelectModel(Map<K, V> input); static OptionModel toOptionModel(Object input); static List<OptionModel> toOptionModels(List<E> input); static SelectModel toSelectModel(List<E> input); static KeyValue parseKeyValue(String input); static String extractIdFromPropertyExpression(String expression); static String defaultLabel(String id, Messages messages, String propertyExpression); static String lastTerm(String input); static String toClassAttributeValue(List<String> classes); static String getLabelForEnum(Messages messages, String prefix, Enum value); static String getLabelForEnum(Messages messages, Enum value); static boolean isEqual(T left, T right); static String[] splitPath(String path); static String[] splitAtCommas(String value); static void copy(InputStream in, OutputStream out); static boolean isEqual(EventContext left, EventContext right); static Asset2 toAsset2(final Asset asset); static InternalPropertyConduit toInternalPropertyConduit(final PropertyConduit conduit); static Orderable<String> mixinTypeAndOrder(String mixinDef); static String[] splitMixinConstraints(String s); static LinkCreationListener2 toLinkCreationListener2(final LinkCreationListener delegate); static String toFileSuffix(String fileName); static V getAndDeref(Map<K, ? extends Reference<V>> map, K key); static Thread[] getAllThreads(); static Mapper<Asset, StylesheetLink> assetToStylesheetLink; }
@Test public void string_to_option_models() { List<OptionModel> options = TapestryInternalUtils.toOptionModels("UK,USA,DE=Germany"); assertEquals(options.size(), 3); assertEquals(options.get(0).getLabel(), "UK"); assertEquals(options.get(0).getValue(), "UK"); assertEquals(options.get(1).getLabel(), "USA"); assertEquals(options.get(1).getValue(), "USA"); assertEquals(options.get(2).getLabel(), "Germany"); assertEquals(options.get(2).getValue(), "DE"); }
@Test public void map_to_option_models() { Map<Integer, String> map = new TreeMap<Integer, String>(); map.put(1, "A"); map.put(2, null); map.put(3, "C"); List<OptionModel> options = TapestryInternalUtils.toOptionModels(map); assertEquals(options.size(), 3); assertEquals(options.get(0).getLabel(), "A"); assertEquals(options.get(0).getValue(), 1); assertEquals(options.get(1).getLabel(), ""); assertEquals(options.get(1).getValue(), 2); assertEquals(options.get(2).getLabel(), "C"); assertEquals(options.get(2).getValue(), 3); }
@Test public void null_map_key_is_null_option_value() { Map<Integer, String> map = new HashMap<Integer, String>(); map.put(null, "Label"); List<OptionModel> options = TapestryInternalUtils.toOptionModels(map); assertEquals(options.size(), 1); assertEquals(options.get(0).getLabel(), "Label"); assertEquals(options.get(0).getValue(), null); }
@Test public void list_to_option_models() { List<String> list = new ArrayList<String>(); list.add("A"); list.add(null); list.add("C"); List<OptionModel> options = TapestryInternalUtils.toOptionModels(list); assertEquals(options.size(), 3); assertEquals(options.get(0).getLabel(), "A"); assertEquals(options.get(0).getValue(), "A"); assertEquals(options.get(1).getLabel(), ""); assertEquals(options.get(1).getValue(), null); assertEquals(options.get(2).getLabel(), "C"); assertEquals(options.get(2).getValue(), "C"); }
@Test public void whitespace_around_terms_is_trimmed() { List<OptionModel> options = TapestryInternalUtils.toOptionModels(" UK , USA , DE=Germany "); assertEquals(options.size(), 3); assertEquals(options.get(0).getLabel(), "UK"); assertEquals(options.get(0).getValue(), "UK"); assertEquals(options.get(1).getLabel(), "USA"); assertEquals(options.get(1).getValue(), "USA"); assertEquals(options.get(2).getLabel(), "Germany"); assertEquals(options.get(2).getValue(), "DE"); }