Package org.springframework.mock.web

# Class MockPart

java.lang.Object
org.springframework.mock.web.MockPart

All Implemented Interfaces:
  `Part`

public class MockPart extends Object implements Part
Mock implementation of `jakarta.servlet.http.Part`.

Since:
  4.3.12
Author:
  Rossen Stoyanchev, Juergen Hoeller
See Also:
  - `MockHttpServletRequest.addPart(jakarta.servlet.http.Part)`
  - `MockMultipartFile`

## Constructor Summary

Constructors
Constructor
Description
`MockPart(String name, byte[] content)`
Constructor for a part with a name and content only.
`MockPart(String name, String filename, byte[] content)`
Constructor for a part with a name, filename, and content.
`MockPart(String name, String filename, byte[] content, org.springframework.http.MediaType contentType)`
Constructor for a part with a name, filename, content, and content type.

## Method Summary

Modifier and Type
Method
Description
`void`
`delete()`
`String`
`getContentType()`
`String`
`getHeader(String name)`
`Collection<String>`
`getHeaderNames()`
`final org.springframework.http.HttpHeaders`
`getHeaders()`
Return the `HttpHeaders` backing header related accessor methods, allowing for populating selected header entries.
`Collection<String>`
`getHeaders(String name)`
`InputStream`
`getInputStream()`
`String`
`getName()`
`long`
`getSize()`
`String`
`getSubmittedFileName()`
`void`
`write(String fileName)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MockPart

public MockPart(String name, @Nullable byte[] content)
Constructor for a part with a name and content only.

See Also:
  - `getHeaders()`

### MockPart

public MockPart(String name, @Nullable String filename, @Nullable byte[] content)
Constructor for a part with a name, filename, and content.

See Also:
  - `getHeaders()`

### MockPart

public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable org.springframework.http.MediaType contentType)
Constructor for a part with a name, filename, content, and content type.

Since:
  6.1.2
See Also:
  - `getHeaders()`

## Method Details

### getName

public String getName()

Specified by:
  `getName` in interface `Part`

### getSubmittedFileName

@Nullable public String getSubmittedFileName()

Specified by:
  `getSubmittedFileName` in interface `Part`

### getContentType

@Nullable public String getContentType()

Specified by:
  `getContentType` in interface `Part`

### getSize

public long getSize()

Specified by:
  `getSize` in interface `Part`

### getInputStream

public InputStream getInputStream() throws IOException

Specified by:
  `getInputStream` in interface `Part`
Throws:
  `IOException`

### write

public void write(String fileName) throws IOException

Specified by:
  `write` in interface `Part`
Throws:
  `IOException`

### delete

public void delete() throws IOException

Specified by:
  `delete` in interface `Part`
Throws:
  `IOException`

### getHeader

@Nullable public String getHeader(String name)

Specified by:
  `getHeader` in interface `Part`

### getHeaders

public Collection<String> getHeaders(String name)

Specified by:
  `getHeaders` in interface `Part`

### getHeaderNames

public Collection<String> getHeaderNames()

Specified by:
  `getHeaderNames` in interface `Part`

### getHeaders

public final org.springframework.http.HttpHeaders getHeaders()
Return the `HttpHeaders` backing header related accessor methods, allowing for populating selected header entries.