File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes about MultipartFile with Junit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "about MultipartFile with Junit" Watch "about MultipartFile with Junit" New topic
Author

about MultipartFile with Junit

karas huang
Greenhorn

Joined: Dec 22, 2013
Posts: 2
Sorry about my pool english, i'm come from taiwan,
I can use google translate to express my problem, I hope seniors understanding.
JAVA has just entered less than six months,
I recently encountered this problem ... no clue
Architecture is Spring + hibernate

The main problem is actually very short,
I used several methods are unable to successfully simulate a file allows itself controller to eat,
Cause is a program that has been unable to pass the test, relative to the coverage itself has been unable to meet the requirements.

controller


Use of the following two results,
PropertyUtils.getProperty went here are signs (green background),
But continued to go down to determine the file size, not passed.

Junit part1.


Junit part2.


Thanks for watch, i really need your help with this....
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
It is easy to read the code and test it if you collect conditions into meaningful methods.
So replace
with

Now you have two conditions to test instead of four conditions. You can then write and test the notEmpty method separately which will be easy to do.

Also, don't use in unit tests. Load the file from the classpath using
karas huang
Greenhorn

Joined: Dec 22, 2013
Posts: 2
Thanks you so much,
i used your way,
then i fix the fileinput problem,
at the last,
i have other problem with MockMultipartHttpServletRequest,
but i still fix that.

Thanks you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about MultipartFile with Junit
 
Similar Threads
Problem with @RequestPart with mixed multipart request, Spring MVC 3.2
How to develop doPut() Servlet
Request sent by the client is syntactically incorrect.
Extended characters encoding in java
Japanese character not read or written correctly