From 58e970699122e590c0a1413e5c1ecc67f69887c8 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 9 Aug 2018 02:26:36 +0200 Subject: [PATCH] Polishing --- .../jdbc/core/JdbcTemplateTests.java | 24 ++++++------- .../annotation/ControllerMethodResolver.java | 5 ++- ...HandlerMethodAnnotationDetectionTests.java | 36 +++++++++---------- src/docs/asciidoc/web/webmvc-view.adoc | 1 + 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java index 9673181d93d..3db0188b9ce 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java @@ -177,13 +177,15 @@ public class JdbcTemplateTests { @Test public void testStringsWithEmptyPreparedStatementArgs() throws Exception { - doTestStrings(null, null, null, null, (template, sql, rch) -> template.query(sql, (Object[]) null, rch)); + doTestStrings(null, null, null, null, + (template, sql, rch) -> template.query(sql, (Object[]) null, rch)); } @Test public void testStringsWithPreparedStatementArgs() throws Exception { final Integer argument = 99; - doTestStrings(null, null, null, argument, (template, sql, rch) -> template.query(sql, new Object[] { argument }, rch)); + doTestStrings(null, null, null, argument, + (template, sql, rch) -> template.query(sql, new Object[] {argument}, rch)); } private void doTestStrings(Integer fetchSize, Integer maxRows, Integer queryTimeout, @@ -363,7 +365,7 @@ public class JdbcTemplateTests { given(this.preparedStatement.executeUpdate()).willReturn(rowsAffected); int actualRowsAffected = this.template.update(sql, - new Object[] {4, new SqlParameterValue(Types.NUMERIC, 2, Float.valueOf(1.4142f))}); + 4, new SqlParameterValue(Types.NUMERIC, 2, Float.valueOf(1.4142f))); assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected); verify(this.preparedStatement).setObject(1, 4); verify(this.preparedStatement).setObject(2, Float.valueOf(1.4142f), Types.NUMERIC, 2); @@ -428,8 +430,7 @@ public class JdbcTemplateTests { public void testBatchUpdateWithBatchFailure() throws Exception { final String[] sql = {"A", "B", "C", "D"}; given(this.statement.executeBatch()).willThrow( - new BatchUpdateException(new int[] { 1, Statement.EXECUTE_FAILED, 1, - Statement.EXECUTE_FAILED })); + new BatchUpdateException(new int[] {1, Statement.EXECUTE_FAILED, 1, Statement.EXECUTE_FAILED})); mockDatabaseMetaData(true); given(this.connection.createStatement()).willReturn(this.statement); @@ -496,11 +497,9 @@ public class JdbcTemplateTests { given(this.preparedStatement.executeBatch()).willReturn(rowsAffected); mockDatabaseMetaData(true); - BatchPreparedStatementSetter setter = - new BatchPreparedStatementSetter() { + BatchPreparedStatementSetter setter = new BatchPreparedStatementSetter() { @Override - public void setValues(PreparedStatement ps, int i) - throws SQLException { + public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, ids[i]); } @Override @@ -1050,10 +1049,9 @@ public class JdbcTemplateTests { } try { - this.template.query(con -> con.prepareStatement("my query"), - (ResultSetExtractor) rs2 -> { - throw new InvalidDataAccessApiUsageException(""); - } ); + this.template.query(con -> con.prepareStatement("my query"), (ResultSetExtractor) rs2 -> { + throw new InvalidDataAccessApiUsageException(""); + }); fail("Should have thrown InvalidDataAccessApiUsageException"); } catch (InvalidDataAccessApiUsageException ex) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java index 39c766945a9..e3f6ef6f635 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java @@ -71,13 +71,13 @@ class ControllerMethodResolver { /** * MethodFilter that matches {@link InitBinder @InitBinder} methods. */ - public static final MethodFilter INIT_BINDER_METHODS = method -> + private static final MethodFilter INIT_BINDER_METHODS = method -> AnnotatedElementUtils.hasAnnotation(method, InitBinder.class); /** * MethodFilter that matches {@link ModelAttribute @ModelAttribute} methods. */ - public static final MethodFilter MODEL_ATTRIBUTE_METHODS = method -> + private static final MethodFilter MODEL_ATTRIBUTE_METHODS = method -> (!AnnotatedElementUtils.hasAnnotation(method, RequestMapping.class) && AnnotatedElementUtils.hasAnnotation(method, ModelAttribute.class)); @@ -217,7 +217,6 @@ class ControllerMethodResolver { } private void initControllerAdviceCaches(ApplicationContext applicationContext) { - List beans = ControllerAdviceBean.findAnnotatedBeans(applicationContext); AnnotationAwareOrderComparator.sort(beans); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java index 91ffe9753e7..64c9d9c1e9f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,31 +66,29 @@ public class HandlerMethodAnnotationDetectionTests { @Parameters(name = "controller [{0}], auto-proxy [{1}]") public static Object[][] handlerTypes() { return new Object[][] { + { SimpleController.class, true }, // CGLIB proxy + { SimpleController.class, false }, - { SimpleController.class, true }, // CGLIB proxy - { SimpleController.class, false }, + { AbstractClassController.class, true }, // CGLIB proxy + { AbstractClassController.class, false }, - { AbstractClassController.class, true }, // CGLIB proxy - { AbstractClassController.class, false }, + { ParameterizedAbstractClassController.class, true }, // CGLIB proxy + { ParameterizedAbstractClassController.class, false }, - { ParameterizedAbstractClassController.class, true }, // CGLIB proxy - { ParameterizedAbstractClassController.class, false }, + { ParameterizedSubclassOverridesDefaultMappings.class, true }, // CGLIB proxy + { ParameterizedSubclassOverridesDefaultMappings.class, false }, - { ParameterizedSubclassOverridesDefaultMappings.class, true }, // CGLIB proxy - { ParameterizedSubclassOverridesDefaultMappings.class, false }, + // TODO [SPR-9517] Enable ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass test cases + // { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true }, // CGLIB proxy + // { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false }, - // TODO [SPR-9517] Enable ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass test cases - // { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true }, // CGLIB proxy - // { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false }, + { InterfaceController.class, true }, // JDK dynamic proxy + { InterfaceController.class, false }, - { InterfaceController.class, true }, // JDK dynamic proxy - { InterfaceController.class, false }, - - { ParameterizedInterfaceController.class, false }, // no AOP - - { SupportClassController.class, true }, // CGLIB proxy - { SupportClassController.class, false } + { ParameterizedInterfaceController.class, false }, // no AOP + { SupportClassController.class, true }, // CGLIB proxy + { SupportClassController.class, false } }; } diff --git a/src/docs/asciidoc/web/webmvc-view.adoc b/src/docs/asciidoc/web/webmvc-view.adoc index 16c4c17c636..47a43b08f4d 100644 --- a/src/docs/asciidoc/web/webmvc-view.adoc +++ b/src/docs/asciidoc/web/webmvc-view.adoc @@ -2031,6 +2031,7 @@ through the `ObjectMapper` property for cases where custom JSON serializers/deserializers need to be provided for specific types. + [[mvc-view-xml-mapping]] === XML [.small]#<>#