ComponentDefaultProviderImpl implements ComponentDefaultProvider { public String defaultLabel(ComponentResources resources) { assert resources != null; String componentId = resources.getId(); String key = componentId + "-label"; Messages containerMessages = resources.getContainerResources().getMessages(); if (containerMessages.contains(key)) return containerMessages.get(key); return TapestryInternalUtils.toUserPresentable(componentId); } ComponentDefaultProviderImpl(PropertyAccess propertyAccess, BindingSource bindingSource,
                                        ValueEncoderSource valueEncoderSource,
                                        FieldTranslatorSource fieldTranslatorSource,
                                        FieldValidatorDefaultSource fieldValidatorDefaultSource); String defaultLabel(ComponentResources resources); Binding defaultBinding(String parameterName, ComponentResources resources); @SuppressWarnings({ "unchecked" }) ValueEncoder defaultValueEncoder(String parameterName, ComponentResources resources); FieldTranslator defaultTranslator(String parameterName, ComponentResources resources); Binding defaultTranslatorBinding(final String parameterName, final ComponentResources resources); FieldValidator defaultValidator(String parameterName, ComponentResources resources); Binding defaultValidatorBinding(final String parameterName, final ComponentResources resources);  }
@Test public void default_label_key_exists() { ComponentResources resources = mockComponentResources(); ComponentResources container = mockComponentResources(); Messages messages = mockMessages(); String componentId = "myfield"; String key = componentId + "-label"; String message = "My Lovely Field"; train_getId(resources, componentId); train_getContainerResources(resources, container); train_getMessages(container, messages); train_contains(messages, key, true); train_get(messages, key, message); replay(); ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, null, null); assertSame(provider.defaultLabel(resources), message); verify(); }
@Test public void default_label_key_missing() { ComponentResources resources = mockComponentResources(); ComponentResources container = mockComponentResources(); Messages messages = mockMessages(); String componentId = "myField"; String key = componentId + "-label"; train_getId(resources, componentId); train_getContainerResources(resources, container); train_getMessages(container, messages); train_contains(messages, key, false); replay(); ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, null, null); assertEquals(provider.defaultLabel(resources), "My Field"); verify(); }