1 16 17 package org.springframework.mock.web; 18 19 import java.util.Collections ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 23 import org.springframework.core.CollectionFactory; 24 import org.springframework.util.Assert; 25 import org.springframework.web.multipart.MultipartFile; 26 import org.springframework.web.multipart.MultipartHttpServletRequest; 27 28 41 public class MockMultipartHttpServletRequest extends MockHttpServletRequest implements MultipartHttpServletRequest { 42 43 private final Map multipartFiles = CollectionFactory.createLinkedMapIfPossible(4); 44 45 46 51 public void addFile(MultipartFile file) { 52 Assert.notNull(file, "MultipartFile must not be null"); 53 this.multipartFiles.put(file.getName(), file); 54 } 55 56 public Iterator getFileNames() { 57 return getFileMap().keySet().iterator(); 58 } 59 60 public MultipartFile getFile(String name) { 61 return (MultipartFile) this.multipartFiles.get(name); 62 } 63 64 public Map getFileMap() { 65 return Collections.unmodifiableMap(this.multipartFiles); 66 } 67 68 } 69 | Popular Tags |