Skip to content

Commit

Permalink
added tests for BaseMimeType.getSpecificMimeType(); refs #20082
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelhaul committed Feb 27, 2025
1 parent 4097d85 commit 1fda51e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ public static boolean isImageOrPdfDownloadAllowed(String mimeTypeName) {
return mimeType.isImageOrPdfDownloadAllowed();
}

/**
*
* @param mimeType
* @return Part of mimeType after the slash; entire value if no slash
* @should return empty string if mimeType blank
* @should return empty string if mimeType contains no slash
* @should return second part
*/
public static String getSpecificMimeType(String mimeType) {
if (StringUtils.isBlank(mimeType)) {
return "";
Expand All @@ -151,8 +159,7 @@ public static String getSpecificMimeType(String mimeType) {
String useName = mimeType;
if (useName.contains("/")) {
return useName.substring(useName.indexOf("/") + 1);
} else {
return "";
}
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BaseMimeTypeTest {
* @verifies find mime type by short name correctly
*/
@Test
void getByName_shouldFindMimeTypeByShortNameCorrectly() throws Exception {
void getByName_shouldFindMimeTypeByShortNameCorrectly() {
Assertions.assertEquals(BaseMimeType.APPLICATION, BaseMimeType.getByName("application"));
Assertions.assertEquals(BaseMimeType.AUDIO, BaseMimeType.getByName("audio"));
Assertions.assertEquals(BaseMimeType.IMAGE, BaseMimeType.getByName("image"));
Expand All @@ -44,10 +44,38 @@ void getByName_shouldFindMimeTypeByShortNameCorrectly() throws Exception {
* @verifies find mime type by full name correctly
*/
@Test
void getByName_shouldFindMimeTypeByFullNameCorrectly() throws Exception {
void getByName_shouldFindMimeTypeByFullNameCorrectly() {
Assertions.assertEquals(BaseMimeType.APPLICATION, BaseMimeType.getByName("application/pdf"));
Assertions.assertEquals(BaseMimeType.AUDIO, BaseMimeType.getByName("audio/mpeg3"));
Assertions.assertEquals(BaseMimeType.IMAGE, BaseMimeType.getByName("image/jpeg"));
Assertions.assertEquals(BaseMimeType.SANDBOXED_HTML, BaseMimeType.getByName("text/sandboxed-html"));
}

/**
* @see BaseMimeType#getSpecificMimeType(String)
* @verifies return empty string if mimeType blank
*/
@Test
void getSpecificMimeType_shouldReturnEmptyStringIfMNimeTypeBlank() {
Assertions.assertEquals("", BaseMimeType.getSpecificMimeType(" "));
}

/**
* @see BaseMimeType#getSpecificMimeType(String)
* @verifies return empty string if mimeType contains no slash
*/
@Test
void getSpecificMimeType_shouldReturnEmptyStringIfMimeTypeContainsNoSlash() {
Assertions.assertEquals("", BaseMimeType.getSpecificMimeType("foo"));
}

/**
* @see BaseMimeType#getSpecificMimeType(String)
* @verifies return second part correctly
*/
@Test
void getSpecificMimeType_shouldReturnSecondPartCorrectly() {

Assertions.assertEquals("bar", BaseMimeType.getSpecificMimeType("foo/bar"));
}
}

0 comments on commit 1fda51e

Please sign in to comment.