Andrea,

On Wed, Sep 3, 2014 at 11:41 PM, <[email protected]> wrote:

> Repository: wicket
> Updated Branches:
>   refs/heads/master 3b9e1169d -> 8f2a6d2c0
>
>
> WICKET-5691 Wicket FileUploadField.getFileUploads() should never return
> null.
>
> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/8f2a6d2c
> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/8f2a6d2c
> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/8f2a6d2c
>
> Branch: refs/heads/master
> Commit: 8f2a6d2c0c03e9c2bfd3df11dfa83060c601dee9
> Parents: 3b9e116
> Author: adelbene <[email protected]>
> Authored: Wed Sep 3 22:39:38 2014 +0200
> Committer: adelbene <[email protected]>
> Committed: Wed Sep 3 22:40:32 2014 +0200
>
> ----------------------------------------------------------------------
>  .../html/form/upload/FileUploadField.java       |  9 +++---
>  .../html/form/upload/FileUploadFieldTest.java   | 32 +++++++++++++++++---
>  2 files changed, 32 insertions(+), 9 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/8f2a6d2c/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
> b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
> index 9ebe306..d5b85fd 100644
> ---
> a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
> +++
> b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
> @@ -81,7 +81,7 @@ public class FileUploadField extends
> FormComponent<List<FileUpload>>
>         }
>
>         /**
> -        * @return a list of all uploaded files. It will return more than
> one files if:
> +        * @return a list of all uploaded files. The list is empty if no
> files were selected. It will return more than one files if:
>          *         <ul>
>          *         <li>HTML5 &lt;input type="file"
> <strong>multiple</strong> /&gt; is used</li>
>          *         <li>the browser supports <em>multiple</em>
> attribute</li>
> @@ -95,6 +95,8 @@ public class FileUploadField extends
> FormComponent<List<FileUpload>>
>                         return fileUploads;
>                 }
>
> +               fileUploads = new ArrayList<FileUpload>();
>

Please don't introduce "Java 7 diamonds" warnings in new code.


> +
>                 // Get request
>                 final Request request = getRequest();
>
> @@ -112,15 +114,12 @@ public class FileUploadField extends
> FormComponent<List<FileUpload>>
>                                         // bytes)
>                                         if (item != null && item.getSize()
> > 0)
>                                         {
> -                                               if (fileUploads == null)
> -                                               {
> -                                                       fileUploads = new
> ArrayList<FileUpload>();
> -                                               }
>                                                 fileUploads.add(new
> FileUpload(item));
>                                         }
>                                 }
>                         }
>                 }
> +
>                 return fileUploads;
>         }
>
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/8f2a6d2c/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
> b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
> index 203db1e..a9f6c51 100644
> ---
> a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
> +++
> b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
> @@ -108,7 +108,7 @@ public class FileUploadFieldTest extends WicketTestCase
>                         }
>                 }
>         }
> -
> +
>         /**
>          * @throws IOException
>          */
> @@ -126,7 +126,24 @@ public class FileUploadFieldTest extends
> WicketTestCase
>                 assertFalse(page.getForm().hasError());
>         }
>
> -       /** */
> +       /**
> +        * https://issues.apache.org/jira/browse/WICKET-5691
> +        *
> +        * */
> +       @Test
> +       public void testEmptyField() throws Exception
> +       {
> +               tester.startPage(TestValidationPage.class);
> +
> +               FormTester formtester = tester.newFormTester("form");
> +               formtester.submit();
> +
> +               FileUploadField fileUploadField =
> (FileUploadField)tester.getComponentFromLastRenderedPage("form:upload");
> +
> +               assertEquals(0, fileUploadField.getFileUploads().size());
> +       }
> +
> +
>         public static class TestValidationPage extends
> MockPageWithFormAndUploadField
>         {
>                 /** */
> @@ -147,11 +164,18 @@ public class FileUploadFieldTest extends
> WicketTestCase
>                 @Override
>                 public void validate(IValidatable<List<FileUpload>>
> validatable)
>                 {
> -                       if (validatable.getValue() instanceof List ==
> false)
> +                       List<FileUpload> fieldValue =
> validatable.getValue();
> +
> +                       if (fieldValue.size() == 0)
> +                       {
> +                               return;
> +                       }
> +
> +                       if (fieldValue instanceof List == false)
>                         {
>                                 validatable.error(new
> ValidationError().addKey("validatable value type not expected"));
>                         }
> -                       FileUpload upload = validatable.getValue().get(0);
> +                       FileUpload upload = fieldValue.get(0);
>                         if
> (!upload.getClientFileName().contains(TEST_FILE_NAME))
>                         {
>                                 validatable.error(new
> ValidationError().addKey("uploaded file name not expected"));
>
>
The change is incomplete. The callers of #getFileUploads() are not updated.
Please see my forthcoming commit.

Reply via email to