mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-08 17:51:20 +02:00
Replace uses of Arrays.asList()
with either List.of() or Collections.singletonList() (#4219)
This commit is contained in:
parent
02d096d622
commit
74870615df
@ -7,7 +7,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -106,7 +105,7 @@ public class PipelineProcessor {
|
|||||||
Map<String, Object> parameters = pipelineOperation.getParameters();
|
Map<String, Object> parameters = pipelineOperation.getParameters();
|
||||||
List<String> inputFileTypes = apiDocService.getExtensionTypes(false, operation);
|
List<String> inputFileTypes = apiDocService.getExtensionTypes(false, operation);
|
||||||
if (inputFileTypes == null) {
|
if (inputFileTypes == null) {
|
||||||
inputFileTypes = new ArrayList<String>(Arrays.asList("ALL"));
|
inputFileTypes = new ArrayList<>(List.of("ALL"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!apiDocService.isValidOperation(operation, parameters)) {
|
if (!apiDocService.isValidOperation(operation, parameters)) {
|
||||||
|
@ -53,7 +53,7 @@ public class ApiDocService {
|
|||||||
|
|
||||||
public List<String> getExtensionTypes(boolean output, String operationName) {
|
public List<String> getExtensionTypes(boolean output, String operationName) {
|
||||||
if (outputToFileTypes.size() == 0) {
|
if (outputToFileTypes.size() == 0) {
|
||||||
outputToFileTypes.put("PDF", Arrays.asList("pdf"));
|
outputToFileTypes.put("PDF", List.of("pdf"));
|
||||||
outputToFileTypes.put(
|
outputToFileTypes.put(
|
||||||
"IMAGE",
|
"IMAGE",
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
@ -63,10 +63,10 @@ public class ApiDocService {
|
|||||||
"ZIP",
|
"ZIP",
|
||||||
Arrays.asList("zip", "rar", "7z", "tar", "gz", "bz2", "xz", "lz", "lzma", "z"));
|
Arrays.asList("zip", "rar", "7z", "tar", "gz", "bz2", "xz", "lz", "lzma", "z"));
|
||||||
outputToFileTypes.put("WORD", Arrays.asList("doc", "docx", "odt", "rtf"));
|
outputToFileTypes.put("WORD", Arrays.asList("doc", "docx", "odt", "rtf"));
|
||||||
outputToFileTypes.put("CSV", Arrays.asList("csv"));
|
outputToFileTypes.put("CSV", List.of("csv"));
|
||||||
outputToFileTypes.put("JS", Arrays.asList("js", "jsx"));
|
outputToFileTypes.put("JS", Arrays.asList("js", "jsx"));
|
||||||
outputToFileTypes.put("HTML", Arrays.asList("html", "htm", "xhtml"));
|
outputToFileTypes.put("HTML", Arrays.asList("html", "htm", "xhtml"));
|
||||||
outputToFileTypes.put("JSON", Arrays.asList("json"));
|
outputToFileTypes.put("JSON", List.of("json"));
|
||||||
outputToFileTypes.put("TXT", Arrays.asList("txt", "text", "md", "markdown"));
|
outputToFileTypes.put("TXT", Arrays.asList("txt", "text", "md", "markdown"));
|
||||||
outputToFileTypes.put("PPT", Arrays.asList("ppt", "pptx", "odp"));
|
outputToFileTypes.put("PPT", Arrays.asList("ppt", "pptx", "odp"));
|
||||||
outputToFileTypes.put("XML", Arrays.asList("xml", "xsd", "xsl"));
|
outputToFileTypes.put("XML", Arrays.asList("xml", "xsd", "xsl"));
|
||||||
|
@ -77,7 +77,7 @@ public class CertificateValidationService {
|
|||||||
try {
|
try {
|
||||||
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
|
||||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||||
List<X509Certificate> certList = Arrays.asList(cert);
|
List<X509Certificate> certList = Collections.singletonList(cert);
|
||||||
CertPath certPath = cf.generateCertPath(certList);
|
CertPath certPath = cf.generateCertPath(certList);
|
||||||
|
|
||||||
Set<TrustAnchor> anchors = new HashSet<>();
|
Set<TrustAnchor> anchors = new HashSet<>();
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package stirling.software.SPDF.controller.api;
|
package stirling.software.SPDF.controller.api;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.ArgumentMatchers.*;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
@ -266,8 +268,8 @@ class MergeControllerTest {
|
|||||||
when(pdfDocumentFactory.createNewDocument()).thenReturn(mockMergedDocument);
|
when(pdfDocumentFactory.createNewDocument()).thenReturn(mockMergedDocument);
|
||||||
when(doc1.getPages()).thenReturn(pages1);
|
when(doc1.getPages()).thenReturn(pages1);
|
||||||
when(doc2.getPages()).thenReturn(pages2);
|
when(doc2.getPages()).thenReturn(pages2);
|
||||||
when(pages1.iterator()).thenReturn(Arrays.asList(page1).iterator());
|
when(pages1.iterator()).thenReturn(Collections.singletonList(page1).iterator());
|
||||||
when(pages2.iterator()).thenReturn(Arrays.asList(page2).iterator());
|
when(pages2.iterator()).thenReturn(Collections.singletonList(page2).iterator());
|
||||||
|
|
||||||
// When
|
// When
|
||||||
PDDocument result = mergeController.mergeDocuments(documents);
|
PDDocument result = mergeController.mergeDocuments(documents);
|
||||||
@ -282,7 +284,7 @@ class MergeControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
void testMergeDocuments_EmptyList_ReturnsEmptyDocument() throws IOException {
|
void testMergeDocuments_EmptyList_ReturnsEmptyDocument() throws IOException {
|
||||||
// Given
|
// Given
|
||||||
List<PDDocument> documents = Arrays.asList();
|
List<PDDocument> documents = List.of();
|
||||||
|
|
||||||
when(pdfDocumentFactory.createNewDocument()).thenReturn(mockMergedDocument);
|
when(pdfDocumentFactory.createNewDocument()).thenReturn(mockMergedDocument);
|
||||||
|
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
package stirling.software.SPDF.service;
|
package stirling.software.SPDF.service;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.pdfbox.cos.COSName;
|
import org.apache.pdfbox.cos.COSName;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
@ -42,7 +35,7 @@ class PdfImageRemovalServiceTest {
|
|||||||
|
|
||||||
// Configure page tree to iterate over our single page
|
// Configure page tree to iterate over our single page
|
||||||
when(document.getPages()).thenReturn(pageTree);
|
when(document.getPages()).thenReturn(pageTree);
|
||||||
Iterator<PDPage> pageIterator = Arrays.asList(page).iterator();
|
Iterator<PDPage> pageIterator = Collections.singletonList(page).iterator();
|
||||||
when(pageTree.iterator()).thenReturn(pageIterator);
|
when(pageTree.iterator()).thenReturn(pageIterator);
|
||||||
|
|
||||||
// Set up page resources
|
// Set up page resources
|
||||||
@ -80,7 +73,7 @@ class PdfImageRemovalServiceTest {
|
|||||||
|
|
||||||
// Configure page tree to iterate over our single page
|
// Configure page tree to iterate over our single page
|
||||||
when(document.getPages()).thenReturn(pageTree);
|
when(document.getPages()).thenReturn(pageTree);
|
||||||
Iterator<PDPage> pageIterator = Arrays.asList(page).iterator();
|
Iterator<PDPage> pageIterator = Collections.singletonList(page).iterator();
|
||||||
when(pageTree.iterator()).thenReturn(pageIterator);
|
when(pageTree.iterator()).thenReturn(pageIterator);
|
||||||
|
|
||||||
// Set up page resources
|
// Set up page resources
|
||||||
@ -118,12 +111,12 @@ class PdfImageRemovalServiceTest {
|
|||||||
|
|
||||||
// Set up image XObjects for page 1
|
// Set up image XObjects for page 1
|
||||||
COSName img1 = COSName.getPDFName("Im1");
|
COSName img1 = COSName.getPDFName("Im1");
|
||||||
when(resources1.getXObjectNames()).thenReturn(Arrays.asList(img1));
|
when(resources1.getXObjectNames()).thenReturn(Collections.singletonList(img1));
|
||||||
when(resources1.isImageXObject(img1)).thenReturn(true);
|
when(resources1.isImageXObject(img1)).thenReturn(true);
|
||||||
|
|
||||||
// Set up image XObjects for page 2
|
// Set up image XObjects for page 2
|
||||||
COSName img2 = COSName.getPDFName("Im2");
|
COSName img2 = COSName.getPDFName("Im2");
|
||||||
when(resources2.getXObjectNames()).thenReturn(Arrays.asList(img2));
|
when(resources2.getXObjectNames()).thenReturn(Collections.singletonList(img2));
|
||||||
when(resources2.isImageXObject(img2)).thenReturn(true);
|
when(resources2.isImageXObject(img2)).thenReturn(true);
|
||||||
|
|
||||||
// Execute the method
|
// Execute the method
|
||||||
|
Loading…
Reference in New Issue
Block a user