类org.springframework.beans.propertyeditors.StringTrimmerEditor源码实例Demo

下面列出了怎么用org.springframework.beans.propertyeditors.StringTrimmerEditor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: spring-analysis-note   文件: CheckboxTagTests.java
@Test
public void withSingleValueAndEditor() throws Exception {
	this.bean.setName("Rob Harrop");
	this.tag.setPath("name");
	this.tag.setValue("   Rob Harrop");
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
	bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, new StringTrimmerEditor(false));
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("name", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
	assertEquals("   Rob Harrop", checkboxElement.attribute("value").getValue());
}
 
@Test
public void setCollectionPropertyWithStringValueAndCustomEditor() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
	accessor.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));

	accessor.setPropertyValue("set", "set1 ");
	accessor.setPropertyValue("sortedSet", "sortedSet1");
	accessor.setPropertyValue("list", "list1 ");
	assertEquals(1, target.getSet().size());
	assertTrue(target.getSet().contains("set1"));
	assertEquals(1, target.getSortedSet().size());
	assertTrue(target.getSortedSet().contains("sortedSet1"));
	assertEquals(1, target.getList().size());
	assertTrue(target.getList().contains("list1"));

	accessor.setPropertyValue("list", Collections.singletonList("list1 "));
	assertTrue(target.getList().contains("list1"));
}
 
源代码3 项目: java-technology-stack   文件: CheckboxTagTests.java
@Test
public void withSingleValueAndEditor() throws Exception {
	this.bean.setName("Rob Harrop");
	this.tag.setPath("name");
	this.tag.setValue("   Rob Harrop");
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
	bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, new StringTrimmerEditor(false));
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("name", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
	assertEquals("   Rob Harrop", checkboxElement.attribute("value").getValue());
}
 
@Test
public void setCollectionPropertyWithStringValueAndCustomEditor() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
	accessor.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));

	accessor.setPropertyValue("set", "set1 ");
	accessor.setPropertyValue("sortedSet", "sortedSet1");
	accessor.setPropertyValue("list", "list1 ");
	assertEquals(1, target.getSet().size());
	assertTrue(target.getSet().contains("set1"));
	assertEquals(1, target.getSortedSet().size());
	assertTrue(target.getSortedSet().contains("sortedSet1"));
	assertEquals(1, target.getList().size());
	assertTrue(target.getList().contains("list1"));

	accessor.setPropertyValue("list", Collections.singletonList("list1 "));
	assertTrue(target.getList().contains("list1"));
}
 
源代码5 项目: spring4-understanding   文件: CheckboxTagTests.java
@Test
public void withSingleValueAndEditor() throws Exception {
	this.bean.setName("Rob Harrop");
	this.tag.setPath("name");
	this.tag.setValue("   Rob Harrop");
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
	bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, new StringTrimmerEditor(false));
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("name", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
	assertEquals("   Rob Harrop", checkboxElement.attribute("value").getValue());
}
 
@Test
public void setCollectionPropertyWithStringValueAndCustomEditor() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
	accessor.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));

	accessor.setPropertyValue("set", "set1 ");
	accessor.setPropertyValue("sortedSet", "sortedSet1");
	accessor.setPropertyValue("list", "list1 ");
	assertEquals(1, target.getSet().size());
	assertTrue(target.getSet().contains("set1"));
	assertEquals(1, target.getSortedSet().size());
	assertTrue(target.getSortedSet().contains("sortedSet1"));
	assertEquals(1, target.getList().size());
	assertTrue(target.getList().contains("list1"));

	accessor.setPropertyValue("list", Collections.singletonList("list1 "));
	assertTrue(target.getList().contains("list1"));
}
 
源代码7 项目: dubbo-2.6.5   文件: ReferenceBeanBuilder.java
@Override
protected void preConfigureBean(Reference reference, ReferenceBean referenceBean) {
    Assert.notNull(interfaceClass, "The interface class must set first!");
    DataBinder dataBinder = new DataBinder(referenceBean);
    // Register CustomEditors for special fields
    dataBinder.registerCustomEditor(String.class, "filter", new StringTrimmerEditor(true));
    dataBinder.registerCustomEditor(String.class, "listener", new StringTrimmerEditor(true));
    dataBinder.registerCustomEditor(Map.class, "parameters", new PropertyEditorSupport() {

        public void setAsText(String text) throws java.lang.IllegalArgumentException {
            // Trim all whitespace
            String content = StringUtils.trimAllWhitespace(text);
            if (!StringUtils.hasText(content)) { // No content , ignore directly
                return;
            }
            // replace "=" to ","
            content = StringUtils.replace(content, "=", ",");
            // replace ":" to ","
            content = StringUtils.replace(content, ":", ",");
            // String[] to Map
            Map<String, String> parameters = CollectionUtils.toStringMap(commaDelimitedListToStringArray(content));
            setValue(parameters);
        }
    });

    // Bind annotation attributes
    dataBinder.bind(new AnnotationPropertyValuesAdapter(reference, applicationContext.getEnvironment(), IGNORE_FIELD_NAMES));

}
 
源代码8 项目: spring-analysis-note   文件: DataBinderTests.java
@Test
public void testConversionWithInappropriateStringEditor() {
	DataBinder dataBinder = new DataBinder(null);
	DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
	dataBinder.setConversionService(conversionService);
	dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

	NameBean bean = new NameBean("Fred");
	assertEquals("ConversionService should have invoked toString()", "Fred", dataBinder.convertIfNecessary(bean, String.class));
	conversionService.addConverter(new NameBeanConverter());
	assertEquals("Type converter should have been used", "[Fred]", dataBinder.convertIfNecessary(bean, String.class));
}
 
源代码9 项目: spring-analysis-note   文件: DataBinderTests.java
@Test  // SPR-14888
public void testSetAutoGrowCollectionLimitAfterInitialization() {
	DataBinder binder = new DataBinder(new BeanWithIntegerList());
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
	assertThatIllegalStateException().isThrownBy(() ->
			binder.setAutoGrowCollectionLimit(257))
		.withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
}
 
@Test
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
	GenericBean<String> gb = new GenericBean<>();
	ArrayList<String[]> list = new ArrayList<>();
	list.add(new String[] {"str1", "str2"});
	gb.setListOfArrays(list);
	BeanWrapper bw = new BeanWrapperImpl(gb);
	bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
	assertEquals("str3", bw.getPropertyValue("listOfArrays[0][1]"));
	assertEquals("str3", gb.getListOfArrays().get(0)[1]);
}
 
@Test
public void propertyTypeIndexedProperty() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	assertEquals(null, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.setPropertyValue("map[key0]", "my String");
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "map[key0]", new StringTrimmerEditor(false));
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));
}
 
源代码12 项目: java-technology-stack   文件: DataBinderTests.java
@Test
public void testConversionWithInappropriateStringEditor() {
	DataBinder dataBinder = new DataBinder(null);
	DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
	dataBinder.setConversionService(conversionService);
	dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

	NameBean bean = new NameBean("Fred");
	assertEquals("ConversionService should have invoked toString()", "Fred", dataBinder.convertIfNecessary(bean, String.class));
	conversionService.addConverter(new NameBeanConverter());
	assertEquals("Type converter should have been used", "[Fred]", dataBinder.convertIfNecessary(bean, String.class));
}
 
源代码13 项目: java-technology-stack   文件: DataBinderTests.java
@Test  // SPR-14888
public void testSetAutoGrowCollectionLimitAfterInitialization() {
	expectedException.expect(IllegalStateException.class);
	expectedException.expectMessage("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");

	DataBinder binder = new DataBinder(new BeanWithIntegerList());
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
	binder.setAutoGrowCollectionLimit(257);
}
 
@Test
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
	GenericBean<String> gb = new GenericBean<>();
	ArrayList<String[]> list = new ArrayList<>();
	list.add(new String[] {"str1", "str2"});
	gb.setListOfArrays(list);
	BeanWrapper bw = new BeanWrapperImpl(gb);
	bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
	assertEquals("str3", bw.getPropertyValue("listOfArrays[0][1]"));
	assertEquals("str3", gb.getListOfArrays().get(0)[1]);
}
 
@Test
public void propertyTypeIndexedProperty() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	assertEquals(null, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.setPropertyValue("map[key0]", "my String");
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "map[key0]", new StringTrimmerEditor(false));
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));
}
 
源代码16 项目: SpringBoot-Base-System   文件: BaseController.java
/**
 * 由InitBinder表示的方法,可以对WebDataBinder对象进行初始化。WebDataBinder是DataBinder的子类,
 * 用于完成由表单到JavaBean属性的绑定。 InitBinder方法不能有返回值,它必须名为void。
 * InitBinder方法的参数通常是WebDataBinder,@InitBinder可以对WebDataBinder进行初始化。
 * 
 * @time 2018年4月10日 下午5:12:31.</br>
 * @version V1.0</br>
 * @param webDataBinder</br>
 */
@InitBinder
protected void initBinder(WebDataBinder webDataBinder) {
	/**
	 * 一个用于trim 的 String类型的属性编辑器 如默认删除两边的空格,charsToDelete属性:可以设置为其他字符
	 * emptyAsNull属性:将一个空字符串转化为null值的选项。
	 */
	webDataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
	webDataBinder.registerCustomEditor(Date.class, new DateEditor(true));
}
 
private void bindReferenceBean(ReferenceBean<GenericService> referenceBean,
		Map<String, Object> dubboTranslatedAttributes) {
	DataBinder dataBinder = new DataBinder(referenceBean);
	// Register CustomEditors for special fields
	dataBinder.registerCustomEditor(String.class, "filter",
			new StringTrimmerEditor(true));
	dataBinder.registerCustomEditor(String.class, "listener",
			new StringTrimmerEditor(true));
	dataBinder.registerCustomEditor(Map.class, "parameters",
			new PropertyEditorSupport() {

				@Override
				public void setAsText(String text)
						throws java.lang.IllegalArgumentException {
					// Trim all whitespace
					String content = StringUtils.trimAllWhitespace(text);
					if (!StringUtils.hasText(content)) { // No content , ignore
															// directly
						return;
					}
					// replace "=" to ","
					content = StringUtils.replace(content, "=", ",");
					// replace ":" to ","
					content = StringUtils.replace(content, ":", ",");
					// String[] to Map
					Map<String, String> parameters = CollectionUtils
							.toStringMap(commaDelimitedListToStringArray(content));
					setValue(parameters);
				}
			});

	// ignore "registries" field and then use RegistryConfig beans
	dataBinder.setDisallowedFields("registries");

	dataBinder.bind(new MutablePropertyValues(dubboTranslatedAttributes));

	registryConfigs.ifAvailable(referenceBean::setRegistries);
}
 
/**
 * {@inheritDoc}
 * Sets the require fields and the disallowed fields from the
 * HttpServletRequest.
 *
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 * org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(final HttpServletRequest request,
        final ServletRequestDataBinder binder) throws Exception {
    binder.setRequiredFields(new String[] {"description", "serviceId",
            "name", "allowedToProxy", "enabled", "ssoEnabled",
            "anonymousAccess", "evaluationOrder"});
    binder.setDisallowedFields(new String[] {"id"});
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}
 
@InitBinder
public void initBinder(WebDataBinder binder, HttpServletRequest request) {
    // 文字列フィールドが未入力の場合に、空文字ではなくNULLをバインドする
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

    // 文字列をIDに変換する
    binder.registerCustomEditor(ID.class, new IDTypeEditor());

    // idカラムを入力値で上書きしない
    binder.setDisallowedFields("*.id");

    // versionカラムを入力値で上書きしない
    binder.setDisallowedFields("*.version");
}
 
源代码20 项目: spring4-understanding   文件: DataBinderTests.java
@Test
public void testConversionWithInappropriateStringEditor() {
	DataBinder dataBinder = new DataBinder(null);
	DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
	dataBinder.setConversionService(conversionService);
	dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

	NameBean bean = new NameBean("Fred");
	assertEquals("ConversionService should have invoked toString()", "Fred", dataBinder.convertIfNecessary(bean, String.class));
	conversionService.addConverter(new NameBeanConverter());
	assertEquals("Type converter should have been used", "[Fred]", dataBinder.convertIfNecessary(bean, String.class));
}
 
@Test
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
	GenericBean<String> gb = new GenericBean<String>();
	ArrayList<String[]> list = new ArrayList<String[]>();
	list.add(new String[] {"str1", "str2"});
	gb.setListOfArrays(list);
	BeanWrapper bw = new BeanWrapperImpl(gb);
	bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
	assertEquals("str3", bw.getPropertyValue("listOfArrays[0][1]"));
	assertEquals("str3", gb.getListOfArrays().get(0)[1]);
}
 
@Test
public void propertyTypeIndexedProperty() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	assertEquals(null, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.setPropertyValue("map[key0]", "my String");
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "map[key0]", new StringTrimmerEditor(false));
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));
}
 
源代码23 项目: springlets   文件: StringTrimmerAdvice.java
/**
 * Registers the {@link StringTrimmerEditor}
 *
 * @param webDataBinder
 */
@InitBinder
public void initBinder(WebDataBinder webDataBinder) {
  StringTrimmerEditor trimmer =
      new StringTrimmerEditor(this.getCharsToDelete(), this.isEmptyAsNull());
  webDataBinder.registerCustomEditor(String.class, trimmer);
}
 
源代码24 项目: cacheonix-core   文件: ClinicBindingInitializer.java
public void initBinder(WebDataBinder binder, WebRequest request) {
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	binder.registerCustomEditor(PetType.class, new PetTypeEditor(this.clinic));
}
 
源代码25 项目: podcastpedia-web   文件: StartPageController.java
@InitBinder
public void initBinder(WebDataBinder binder) {

	binder.registerCustomEditor(MediaType.class, new MediaTypeEditor(
			MediaType.class));
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));/* Converts empty strings into null when a form is submitted */
}
 
源代码26 项目: podcastpedia-web   文件: SearchController.java
@InitBinder
public void initBinder(WebDataBinder binder) {

	binder.registerCustomEditor(MediaType.class, new MediaTypeEditor(
			MediaType.class));
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));/* Converts empty strings into null when a form is submitted */		
}
 
@Test
public void testGetObjectType() throws Exception {
	TestClass1 tc1 = new TestClass1();
	MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
	mcfb = new MethodInvokingFactoryBean();
	mcfb.setTargetObject(tc1);
	mcfb.setTargetMethod("method1");
	mcfb.afterPropertiesSet();
	assertTrue(int.class.equals(mcfb.getObjectType()));

	mcfb = new MethodInvokingFactoryBean();
	mcfb.setTargetClass(TestClass1.class);
	mcfb.setTargetMethod("voidRetvalMethod");
	mcfb.afterPropertiesSet();
	Class<?> objType = mcfb.getObjectType();
	assertSame(objType, void.class);

	// verify that we can call a method with args that are subtypes of the
	// target method arg types
	TestClass1._staticField1 = 0;
	mcfb = new MethodInvokingFactoryBean();
	mcfb.setTargetClass(TestClass1.class);
	mcfb.setTargetMethod("supertypes");
	mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello");
	mcfb.afterPropertiesSet();
	mcfb.getObjectType();

	// fail on improper argument types at afterPropertiesSet
	mcfb = new MethodInvokingFactoryBean();
	mcfb.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	mcfb.setTargetClass(TestClass1.class);
	mcfb.setTargetMethod("supertypes");
	mcfb.setArguments("1", new Object());
	try {
		mcfb.afterPropertiesSet();
		fail("Should have thrown NoSuchMethodException");
	}
	catch (NoSuchMethodException ex) {
		// expected
	}
}
 
@Test
public void setPrimitiveArrayPropertyLargeMatching() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class));

	PrimitiveArrayBean target = new PrimitiveArrayBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	int[] input = new int[1024];
	StopWatch sw = new StopWatch();
	sw.start("array1");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	long time1 = sw.getLastTaskTimeMillis();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	sw.start("array2");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

	accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
	sw.start("array4");
	for (int i = 0; i < 100; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}
 
@Test
public void testGetObjectType() throws Exception {
	TestClass1 tc1 = new TestClass1();
	MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
	mcfb = new MethodInvokingFactoryBean();
	mcfb.setTargetObject(tc1);
	mcfb.setTargetMethod("method1");
	mcfb.afterPropertiesSet();
	assertTrue(int.class.equals(mcfb.getObjectType()));

	mcfb = new MethodInvokingFactoryBean();
	mcfb.setTargetClass(TestClass1.class);
	mcfb.setTargetMethod("voidRetvalMethod");
	mcfb.afterPropertiesSet();
	Class<?> objType = mcfb.getObjectType();
	assertSame(objType, void.class);

	// verify that we can call a method with args that are subtypes of the
	// target method arg types
	TestClass1._staticField1 = 0;
	mcfb = new MethodInvokingFactoryBean();
	mcfb.setTargetClass(TestClass1.class);
	mcfb.setTargetMethod("supertypes");
	mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello");
	mcfb.afterPropertiesSet();
	mcfb.getObjectType();

	// fail on improper argument types at afterPropertiesSet
	mcfb = new MethodInvokingFactoryBean();
	mcfb.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	mcfb.setTargetClass(TestClass1.class);
	mcfb.setTargetMethod("supertypes");
	mcfb.setArguments("1", new Object());
	try {
		mcfb.afterPropertiesSet();
		fail("Should have thrown NoSuchMethodException");
	}
	catch (NoSuchMethodException ex) {
		// expected
	}
}
 
@Test
public void setPrimitiveArrayPropertyLargeMatching() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class));

	PrimitiveArrayBean target = new PrimitiveArrayBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	int[] input = new int[1024];
	StopWatch sw = new StopWatch();
	sw.start("array1");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	long time1 = sw.getLastTaskTimeMillis();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	sw.start("array2");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

	accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
	sw.start("array4");
	for (int i = 0; i < 100; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}
 
 同包方法