Source:
public void test_html_ResourceLink_Expect_Downloadable_Secure_Site_Port_Number() throws Exception{ final String mimeType = "text/html"; final String path = "/application/comments/angular/"; final String hostName = "localhost"; final long languageId = 1L; final boolean isSecure = false; final File file = FileUtil.createTemporalFile("comments-list", "html"); final String content = "This is a test temporal file"; try (final FileWriter fileWriter = new FileWriter(file)) { fileWriter.write(content); } final String htmlFileName = file.getName(); final User adminUser = mockAdminUser(); final Contentlet contentlet = mock(Contentlet.class); when(contentlet.getContentType()).thenReturn(mockFileAssetContentType()); when(contentlet.isFileAsset()).thenReturn(true); when(contentlet.getStringProperty(FileAssetAPI.FILE_NAME_FIELD)).thenReturn(htmlFileName); when(contentlet.getBinary(FileAssetAPI.BINARY_FIELD)).thenReturn(file); when(contentlet.getLanguageId()).thenReturn(languageId); when(contentlet.isNew()).thenReturn(false); final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getAttribute(ResourceLink.HOST_REQUEST_ATTRIBUTE)).thenReturn(HOST_ID); when(request.isSecure()).thenReturn(isSecure); when(request.getServerPort()).thenReturn(8080); final ResourceLinkBuilder resourceLinkBuilder = getResourceLinkBuilder(hostName, path, mimeType, htmlFileName); final ResourceLink link = resourceLinkBuilder.build(request, adminUser, contentlet); assertEquals("http://localhost:8080/application/comments/angular/"+htmlFileName+"?language_id=1",link.getResourceLinkAsString()); assertFalse(link.isDownloadRestricted()); }

Target:
public void test_html_ResourceLink_Expect_Downloadable_Secure_Site_Port_Number() throws Exception{ final String mimeType = "text/html"; final String path = "/application/comments/angular/"; final String hostName = "localhost"; final long languageId = 1L; final boolean isSecure = false; final File file = FileUtil.createTemporalFile("comments-list", "html", "This is a test temporal file"); final String htmlFileName = file.getName(); final User adminUser = mockAdminUser(); final Contentlet contentlet = mock(Contentlet.class); when(contentlet.getContentType()).thenReturn(mockFileAssetContentType()); when(contentlet.isFileAsset()).thenReturn(true); when(contentlet.getStringProperty(FileAssetAPI.FILE_NAME_FIELD)).thenReturn(htmlFileName); when(contentlet.getBinary(FileAssetAPI.BINARY_FIELD)).thenReturn(file); when(contentlet.getLanguageId()).thenReturn(languageId); when(contentlet.isNew()).thenReturn(false); when(contentlet.getInode()).thenReturn(UUIDGenerator.generateUuid()); final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getAttribute(ResourceLink.HOST_REQUEST_ATTRIBUTE)).thenReturn(HOST_ID); when(request.isSecure()).thenReturn(isSecure); when(request.getServerPort()).thenReturn(8080); final ResourceLinkBuilder resourceLinkBuilder = getResourceLinkBuilder(hostName, path, mimeType, htmlFileName); final ResourceLink link = resourceLinkBuilder.build(request, adminUser, contentlet); assertEquals("http://localhost:8080/application/comments/angular/"+htmlFileName+"?language_id=1",link.getResourceLinkAsString()); assertFalse(link.isDownloadRestricted()); }