From 5ec83b6b244ee38a43088a68d5f545ece67a4cda Mon Sep 17 00:00:00 2001 From: Johan Grundberg Date: Thu, 4 Mar 2021 16:24:28 +0100 Subject: [PATCH] Clean up code style (#7452) Clean up code styling according to JabRef style guidelines. --- .../externalfiletype/ExternalFileTypes.java | 4 +- .../fieldeditors/LinkedFileViewModelTest.java | 44 ++++++++++++------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java index 10234d02f15..fec93600501 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java @@ -10,7 +10,6 @@ import java.util.Set; import java.util.TreeSet; -import org.apache.commons.lang3.StringUtils; import org.jabref.gui.Globals; import org.jabref.logic.bibtex.FileFieldWriter; import org.jabref.model.entry.LinkedFile; @@ -113,8 +112,9 @@ public Optional getExternalFileTypeForName(String filename) { */ public Optional getExternalFileTypeByMimeType(String mimeType) { // Ignores parameters according to link: (https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) - if(mimeType.indexOf(';') != -1) + if (mimeType.indexOf(';') != -1) { mimeType = mimeType.substring(0, mimeType.indexOf(';')).trim(); + } for (ExternalFileType type : externalFileTypes) { if (type.getMimeType().equalsIgnoreCase(mimeType)) { return Optional.of(type); diff --git a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java index 5d68465d279..4d7fd1fde84 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java @@ -7,7 +7,10 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.TreeSet; import java.util.regex.Pattern; import javafx.scene.control.Alert.AlertType; @@ -27,20 +30,29 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; import org.jabref.preferences.FilePreferences; - import org.jabref.preferences.JabRefPreferences; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.ArgumentMatchers.matches; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; class LinkedFileViewModelTest { @@ -183,7 +195,7 @@ void downloadHtmlFileCausesWarningDisplay() throws MalformedURLException { databaseContext.setDatabasePath(tempFile); - URL url = new URL( "https://www.google.com/"); + URL url = new URL("https://www.google.com/"); String fileType = StandardExternalFileType.URL.getName(); linkedFile = new LinkedFile(url, fileType); @@ -214,7 +226,7 @@ void downloadDoesNotOverwriteFileTypeExtension() throws MalformedURLException { } @Test - void downloadHtmlWhenLinkedFilePointsToHtml() throws MalformedURLException{ + void downloadHtmlWhenLinkedFilePointsToHtml() throws MalformedURLException { // the link mentioned in issue #7452 String url = "https://onlinelibrary.wiley.com/doi/abs/10.1002/0470862106.ia615"; String fileType = StandardExternalFileType.URL.getName(); @@ -235,7 +247,7 @@ void downloadHtmlWhenLinkedFilePointsToHtml() throws MalformedURLException{ List linkedFiles = entry.getFiles(); - for(LinkedFile file: linkedFiles) { + for (LinkedFile file: linkedFiles) { if (file.getLink().equalsIgnoreCase("Misc/asdf.html")) { assertEquals("URL", file.getFileType()); return; @@ -273,9 +285,9 @@ void isSamePath() { void mimeTypeStringWithParameterIsReturnedAsWithoutParameter() { Globals.prefs = JabRefPreferences.getInstance(); // required for task execution ExternalFileTypes externalFileTypes = ExternalFileTypes.getInstance(); - Optional test = externalFileTypes.getExternalFileTypeByMimeType("text/html; charset=UTF-8"); + Optional test = externalFileTypes.getExternalFileTypeByMimeType("text/html; charset=UTF-8"); String actual = test.get().toString(); - assertEquals("URL",actual); + assertEquals("URL", actual); } @Test @@ -283,7 +295,7 @@ void downloadPdfFileWhenLinkedFilePointsToPdfUrl() throws MalformedURLException Globals.prefs = JabRefPreferences.getInstance(); linkedFile = new LinkedFile(new URL("http://arxiv.org/pdf/1207.0408v1"), "pdf"); - //Needed Mockito stubbing methods to run test + // Needed Mockito stubbing methods to run test when(filePreferences.shouldStoreFilesRelativeToBib()).thenReturn(true); when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); @@ -293,15 +305,15 @@ void downloadPdfFileWhenLinkedFilePointsToPdfUrl() throws MalformedURLException LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, new CurrentThreadTaskExecutor(), dialogService, xmpPreferences, filePreferences, externalFileType); viewModel.download(); - //Loop through downloaded files to check for filetype='pdf' + // Loop through downloaded files to check for filetype='pdf' List linkedFiles = entry.getFiles(); - for(LinkedFile files : linkedFiles){ - if(files.getLink().equalsIgnoreCase("Misc/asdf.pdf")){ - assertEquals("pdf" , files.getFileType().toLowerCase()); + for (LinkedFile files : linkedFiles) { + if (files.getLink().equalsIgnoreCase("Misc/asdf.pdf")) { + assertEquals("pdf", files.getFileType().toLowerCase()); return; } } - //Assert fail if no PDF type was found + // Assert fail if no PDF type was found fail(); }