Skip to content

Fixed wrong Mimetype result for null fileName and deleted wrongly pasted javadocs #1901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ public static Mimetype getInstance() {
* to find the corresponding mime type. If the file has no extension, or the extension is not
* available in the listing contained in this class, the default mimetype
* <code>application/octet-stream</code> is returned.
* <p>
* A file extension is one or more characters that occur after the last period (.) in the file's name.
* If a file has no extension,
* Guesses the mimetype of file data based on the file's extension.
*
* @param path the file whose extension may match a known mimetype.
* @return the file's mimetype based on its extension, or a default value of
Expand All @@ -132,18 +128,14 @@ public String getMimetype(Path path) {
if (file != null) {
return getMimetype(file.toString());
}
return null;
return MIMETYPE_OCTET_STREAM;
}

/**
* Determines the mimetype of a file by looking up the file's extension in an internal listing
* to find the corresponding mime type. If the file has no extension, or the extension is not
* available in the listing contained in this class, the default mimetype
* <code>application/octet-stream</code> is returned.
* <p>
* A file extension is one or more characters that occur after the last period (.) in the file's name.
* If a file has no extension,
* Guesses the mimetype of file data based on the file's extension.
*
* @param file the file whose extension may match a known mimetype.
* @return the file's mimetype based on its extension, or a default value of
Expand All @@ -159,10 +151,6 @@ public String getMimetype(File file) {
* no extension, or the extension is not available in the listing contained
* in this class, the default mimetype <code>application/octet-stream</code>
* is returned.
* <p>
* A file extension is one or more characters that occur after the last
* period (.) in the file's name. If a file has no extension, Guesses the
* mimetype of file data based on the file's extension.
*
* @param fileName The name of the file whose extension may match a known
* mimetype.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package software.amazon.awssdk.core.internal.util;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.nio.file.Path;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -48,4 +51,11 @@ public void unknownExtensions_defaulttoBeStream() throws Exception {
public void noExtensions_defaulttoBeStream() throws Exception {
assertThat(mimetype.getMimetype("test")).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM);
}

@Test
public void pathWithoutFileName_defaulttoBeStream() throws Exception {
Path mockPath = mock(Path.class);
when(mockPath.getFileName()).thenReturn(null);
assertThat(mimetype.getMimetype(mockPath)).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM);
}
}