diff --git a/airsonic-main/src/test/java/org/airsonic/player/TestCaseUtils.java b/airsonic-main/src/test/java/org/airsonic/player/TestCaseUtils.java index 9548b0e2..70aa0d4f 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/TestCaseUtils.java +++ b/airsonic-main/src/test/java/org/airsonic/player/TestCaseUtils.java @@ -20,107 +20,101 @@ public class TestCaseUtils { private static final Logger LOG = LoggerFactory.getLogger(TestCaseUtils.class); - private static File airsonicHomeDirForTest = null; - - /** - * Returns the path of the AIRSONIC_HOME directory to use for tests. - * This will create a temporary directory. - * - * @return AIRSONIC_HOME directory path. - * @throws RuntimeException if it fails to create the temp directory. - */ - public static String airsonicHomePathForTest() { - - if (airsonicHomeDirForTest == null) { - try { - airsonicHomeDirForTest = Files.createTempDirectory("airsonic_test_").toFile(); - } catch (IOException e) { - throw new RuntimeException("Error while creating temporary AIRSONIC_HOME directory for tests"); - } - LOG.info("AIRSONIC_HOME directory will be {}", airsonicHomeDirForTest.getAbsolutePath()); + private static File airsonicHomeDirForTest = null; + + /** + * Returns the path of the AIRSONIC_HOME directory to use for tests. + * This will create a temporary directory. + * + * @return AIRSONIC_HOME directory path. + * @throws RuntimeException if it fails to create the temp directory. + */ + public static String airsonicHomePathForTest() { + + if (airsonicHomeDirForTest == null) { + try { + airsonicHomeDirForTest = Files.createTempDirectory("airsonic_test_").toFile(); + } catch (IOException e) { + throw new RuntimeException("Error while creating temporary AIRSONIC_HOME directory for tests"); + } + LOG.info("AIRSONIC_HOME directory will be {}", airsonicHomeDirForTest.getAbsolutePath()); + } + return airsonicHomeDirForTest.getAbsolutePath(); + } + + /** + * @return current REST api version. + */ + public static String restApiVersion() { + return new JAXBWriter().getRestProtocolVersion(); } - return airsonicHomeDirForTest.getAbsolutePath(); - } - - /** - * - * @return current REST api version. - */ - public static String restApiVersion() { - return new JAXBWriter().getRestProtocolVersion(); - } - - /** - * Cleans the AIRSONIC_HOME directory used for tests. - */ - public static void cleanAirsonicHomeForTest() throws IOException { - - File airsonicHomeDir = new File(airsonicHomePathForTest()); - if (airsonicHomeDir.exists() && airsonicHomeDir.isDirectory()) { - LOG.debug("Delete airsonic home (ie. {}).", airsonicHomeDir.getAbsolutePath()); - try { - FileUtils.deleteDirectory(airsonicHomeDir); - } catch (IOException e) { - LOG.warn("Error while deleting airsonic home."); - e.printStackTrace(); - throw e; - } + + /** + * Cleans the AIRSONIC_HOME directory used for tests. + */ + public static void cleanAirsonicHomeForTest() throws IOException { + + File airsonicHomeDir = new File(airsonicHomePathForTest()); + if (airsonicHomeDir.exists() && airsonicHomeDir.isDirectory()) { + LOG.debug("Delete airsonic home (ie. {}).", airsonicHomeDir.getAbsolutePath()); + try { + FileUtils.deleteDirectory(airsonicHomeDir); + } catch (IOException e) { + LOG.warn("Error while deleting airsonic home."); + e.printStackTrace(); + throw e; + } + } } - } + /** + * Constructs a map of records count per table. + * + * @param daoHelper DaoHelper object + * @return Map table name -> records count + */ + public static Map recordsInAllTables(DaoHelper daoHelper) { + List tableNames = daoHelper.getJdbcTemplate().queryForList("" + + "select table_name " + + "from information_schema.system_tables " + + "where table_name not like 'SYSTEM%'" + , String.class); + + return tableNames.stream() + .collect(Collectors.toMap(table -> table, table -> recordsInTable(table,daoHelper))); + } - /** - * Constructs a map of records count per table. - * - * @param daoHelper DaoHelper object - * @return Map table name -> records count + /** + * Counts records in a table. */ - public static Map recordsInAllTables(DaoHelper daoHelper) { - List tableNames = daoHelper.getJdbcTemplate().queryForList("" + - "select table_name " + - "from information_schema.system_tables " + - "where table_name not like 'SYSTEM%'" - , String.class); - - return tableNames.stream() - .collect(Collectors.toMap(table -> table, table -> recordsInTable(table,daoHelper))); - } - - /** - * Counts records in a table. - */ - public static Integer recordsInTable(String tableName, DaoHelper daoHelper) { - return daoHelper.getJdbcTemplate().queryForObject("select count(1) from " + tableName,Integer.class); - } - - - public static ApplicationContext loadSpringApplicationContext(String baseResources) { - String applicationContextService = baseResources + "applicationContext-service.xml"; - String applicationContextCache = baseResources + "applicationContext-cache.xml"; - - String[] configLocations = new String[]{ - TestCaseUtils.class.getClass().getResource(applicationContextCache).toString(), - TestCaseUtils.class.getClass().getResource(applicationContextService).toString() - }; - return new ClassPathXmlApplicationContext(configLocations); - } - - - /** - * Scans the music library * @param mediaScannerService - */ - public static void execScan(MediaScannerService mediaScannerService) { - // TODO create a synchronous scan - mediaScannerService.scanLibrary(); - - while (mediaScannerService.isScanning()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + public static Integer recordsInTable(String tableName, DaoHelper daoHelper) { + return daoHelper.getJdbcTemplate().queryForObject("select count(1) from " + tableName,Integer.class); } - } + public static ApplicationContext loadSpringApplicationContext(String baseResources) { + String applicationContextService = baseResources + "applicationContext-service.xml"; + String applicationContextCache = baseResources + "applicationContext-cache.xml"; + + String[] configLocations = new String[]{ + TestCaseUtils.class.getClass().getResource(applicationContextCache).toString(), + TestCaseUtils.class.getClass().getResource(applicationContextService).toString() + }; + return new ClassPathXmlApplicationContext(configLocations); + } + /** + * Scans the music library * @param mediaScannerService + */ + public static void execScan(MediaScannerService mediaScannerService) { + // TODO create a synchronous scan + mediaScannerService.scanLibrary(); + + while (mediaScannerService.isScanning()) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } } diff --git a/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AbstractAirsonicRestApiJukeboxIntTest.java b/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AbstractAirsonicRestApiJukeboxIntTest.java index f49d66a9..92180703 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AbstractAirsonicRestApiJukeboxIntTest.java +++ b/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AbstractAirsonicRestApiJukeboxIntTest.java @@ -152,9 +152,9 @@ public abstract class AbstractAirsonicRestApiJukeboxIntTest { } private String convertDateToString(Date date) { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - formatter.setTimeZone(TimeZone.getTimeZone("UTC")); - return formatter.format(date); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + formatter.setTimeZone(TimeZone.getTimeZone("UTC")); + return formatter.format(date); } private ResultMatcher playListItem1isCorrect() { diff --git a/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AirsonicRestApiJukeboxIntTest.java b/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AirsonicRestApiJukeboxIntTest.java index 59c00e5d..8206caaa 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AirsonicRestApiJukeboxIntTest.java +++ b/airsonic-main/src/test/java/org/airsonic/player/api/jukebox/AirsonicRestApiJukeboxIntTest.java @@ -20,7 +20,7 @@ public class AirsonicRestApiJukeboxIntTest extends AbstractAirsonicRestApiJukebo public void setup() throws Exception { super.setup(); JavaPlayer mockJavaPlayer = mock(JavaPlayer.class); - when(mockJavaPlayer.getPlayingInfos()).thenReturn( () -> 0 ); + when(mockJavaPlayer.getPlayingInfos()).thenReturn(() -> 0); when(mockJavaPlayer.getGain()).thenReturn(0.75f); when(javaPlayerFactory.createJavaPlayer()).thenReturn(mockJavaPlayer); } diff --git a/airsonic-main/src/test/java/org/airsonic/player/dao/DaoTestCaseBean2.java b/airsonic-main/src/test/java/org/airsonic/player/dao/DaoTestCaseBean2.java index d00f86b2..1afafd32 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/dao/DaoTestCaseBean2.java +++ b/airsonic-main/src/test/java/org/airsonic/player/dao/DaoTestCaseBean2.java @@ -1,10 +1,10 @@ package org.airsonic.player.dao; +import org.airsonic.player.util.HomeRule; import org.junit.ClassRule; import org.junit.Rule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import org.airsonic.player.util.HomeRule; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; @@ -33,7 +33,6 @@ public class DaoTestCaseBean2 { @Autowired GenericDaoHelper genericDaoHelper; - JdbcTemplate getJdbcTemplate() { return genericDaoHelper.getJdbcTemplate(); } diff --git a/airsonic-main/src/test/java/org/airsonic/player/dao/InternetRadioDaoTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/dao/InternetRadioDaoTestCase.java index 2d3ac1b9..e3a438dc 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/dao/InternetRadioDaoTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/dao/InternetRadioDaoTestCase.java @@ -1,8 +1,8 @@ package org.airsonic.player.dao; +import org.airsonic.player.domain.InternetRadio; import org.junit.Before; import org.junit.Test; -import org.airsonic.player.domain.InternetRadio; import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; diff --git a/airsonic-main/src/test/java/org/airsonic/player/dao/MusicFolderDaoTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/dao/MusicFolderDaoTestCase.java index f8f97324..8d825386 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/dao/MusicFolderDaoTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/dao/MusicFolderDaoTestCase.java @@ -18,10 +18,10 @@ Based upon Subsonic, Copyright 2009 (C) Sindre Mehus */ package org.airsonic.player.dao; +import org.airsonic.player.domain.MusicFolder; import org.junit.Before; import org.junit.Test; -import org.airsonic.player.domain.MusicFolder; import org.springframework.beans.factory.annotation.Autowired; import java.io.File; diff --git a/airsonic-main/src/test/java/org/airsonic/player/dao/PlayerDaoTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/dao/PlayerDaoTestCase.java index 8d634b11..efe8f3bb 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/dao/PlayerDaoTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/dao/PlayerDaoTestCase.java @@ -1,11 +1,11 @@ package org.airsonic.player.dao; import org.airsonic.player.domain.PlayQueue; +import org.airsonic.player.domain.Player; import org.airsonic.player.domain.PlayerTechnology; +import org.airsonic.player.domain.TranscodeScheme; import org.junit.Before; import org.junit.Test; -import org.airsonic.player.domain.Player; -import org.airsonic.player.domain.TranscodeScheme; import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; diff --git a/airsonic-main/src/test/java/org/airsonic/player/dao/PodcastDaoTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/dao/PodcastDaoTestCase.java index 98b820ca..c5681399 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/dao/PodcastDaoTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/dao/PodcastDaoTestCase.java @@ -1,10 +1,10 @@ package org.airsonic.player.dao; +import org.airsonic.player.domain.PodcastChannel; +import org.airsonic.player.domain.PodcastEpisode; import org.airsonic.player.domain.PodcastStatus; import org.junit.Before; import org.junit.Test; -import org.airsonic.player.domain.PodcastChannel; -import org.airsonic.player.domain.PodcastEpisode; import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; diff --git a/airsonic-main/src/test/java/org/airsonic/player/dao/UserDaoTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/dao/UserDaoTestCase.java index ca3a4410..e9da7e00 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/dao/UserDaoTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/dao/UserDaoTestCase.java @@ -1,11 +1,11 @@ package org.airsonic.player.dao; import org.airsonic.player.domain.AvatarScheme; +import org.airsonic.player.domain.TranscodeScheme; import org.airsonic.player.domain.User; import org.airsonic.player.domain.UserSettings; import org.junit.Before; import org.junit.Test; -import org.airsonic.player.domain.TranscodeScheme; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; @@ -51,7 +51,7 @@ public class UserDaoTestCase extends DaoTestCaseBean2 { @Test public void testCreateUserTransactionalError() { - User user = new User ("muff1nman", "secret", "noemail") { + User user = new User("muff1nman", "secret", "noemail") { @Override public boolean isPlaylistRole() { throw new RuntimeException(); diff --git a/airsonic-main/src/test/java/org/airsonic/player/domain/PlayQueueTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/domain/PlayQueueTestCase.java index 4d5ad2d7..05ec9990 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/domain/PlayQueueTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/domain/PlayQueueTestCase.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import java.io.File; import java.util.Arrays; +import java.util.Objects; /** * Unit test of {@link PlayQueue}. @@ -320,5 +321,10 @@ public class PlayQueueTestCase extends TestCase { public boolean equals(Object o) { return this == o; } + + @Override + public int hashCode() { + return Objects.hash(name, track, album, artist); + } } } \ No newline at end of file diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/JukeboxServiceUnitTest.java b/airsonic-main/src/test/java/org/airsonic/player/service/JukeboxServiceUnitTest.java index 751c4734..0a115068 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/JukeboxServiceUnitTest.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/JukeboxServiceUnitTest.java @@ -8,8 +8,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import static org.mockito.Mockito.verify; import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/LegacyDatabaseStartupTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/LegacyDatabaseStartupTestCase.java index 9fa04d33..b4141104 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/LegacyDatabaseStartupTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/LegacyDatabaseStartupTestCase.java @@ -1,13 +1,13 @@ package org.airsonic.player.service; +import org.airsonic.player.TestCaseUtils; +import org.airsonic.player.util.HomeRule; import org.apache.commons.io.FileUtils; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import org.airsonic.player.TestCaseUtils; -import org.airsonic.player.util.HomeRule; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/MediaScannerServiceTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/MediaScannerServiceTestCase.java index f7c895f6..808c286f 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/MediaScannerServiceTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/MediaScannerServiceTestCase.java @@ -3,9 +3,14 @@ package org.airsonic.player.service; import com.codahale.metrics.ConsoleReporter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; +import org.airsonic.player.TestCaseUtils; import org.airsonic.player.dao.*; +import org.airsonic.player.domain.Album; +import org.airsonic.player.domain.Artist; import org.airsonic.player.domain.MediaFile; import org.airsonic.player.domain.MusicFolder; +import org.airsonic.player.util.HomeRule; +import org.airsonic.player.util.MusicFolderTestData; import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.ClassRule; @@ -14,11 +19,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import org.airsonic.player.TestCaseUtils; -import org.airsonic.player.domain.Album; -import org.airsonic.player.domain.Artist; -import org.airsonic.player.util.HomeRule; -import org.airsonic.player.util.MusicFolderTestData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @@ -29,9 +29,9 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; import java.io.File; import java.io.FileOutputStream; +import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.ArrayList; import java.util.Map; import java.util.concurrent.TimeUnit; diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java b/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java index 6d5262ac..e98eb5b8 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/PlaylistServiceTestImport.java @@ -95,7 +95,7 @@ public class PlaylistServiceTestImport { doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8)); - String path = "/path/to/"+playlistName+".m3u"; + String path = "/path/to/" + playlistName + ".m3u"; playlistService.importPlaylist(username, playlistName, path, inputStream, null); verify(playlistDao).createPlaylist(actual.capture()); verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture()); @@ -129,7 +129,7 @@ public class PlaylistServiceTestImport { doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8)); - String path = "/path/to/"+playlistName+".pls"; + String path = "/path/to/" + playlistName + ".pls"; playlistService.importPlaylist(username, playlistName, path, inputStream, null); verify(playlistDao).createPlaylist(actual.capture()); verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture()); @@ -166,7 +166,7 @@ public class PlaylistServiceTestImport { doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any()); doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class)); InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8)); - String path = "/path/to/"+playlistName+".xspf"; + String path = "/path/to/" + playlistName + ".xspf"; playlistService.importPlaylist(username, playlistName, path, inputStream, null); verify(playlistDao).createPlaylist(actual.capture()); verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture()); diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/SecurityServiceTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/SecurityServiceTestCase.java index 6925419e..2c9f0995 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/SecurityServiceTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/SecurityServiceTestCase.java @@ -20,6 +20,7 @@ package org.airsonic.player.service; import junit.framework.TestCase; + /** * Unit test of {@link SecurityService}. * diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/TranscodingServiceIntTest.java b/airsonic-main/src/test/java/org/airsonic/player/service/TranscodingServiceIntTest.java index 1c9293b4..09a81406 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/TranscodingServiceIntTest.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/TranscodingServiceIntTest.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.junit4.SpringRunner; + import static org.mockito.Mockito.*; @RunWith(SpringRunner.class) diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/AbstractAirsonicHomeTest.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/AbstractAirsonicHomeTest.java index 27aeb141..67952ccc 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/AbstractAirsonicHomeTest.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/AbstractAirsonicHomeTest.java @@ -1,9 +1,5 @@ package org.airsonic.player.service.search; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Function; - import org.airsonic.player.TestCaseUtils; import org.airsonic.player.dao.DaoHelper; import org.airsonic.player.dao.MusicFolderDao; @@ -23,6 +19,10 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; + @ContextConfiguration(locations = { "/applicationContext-service.xml", "/applicationContext-cache.xml", diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/AirsonicHomeTest.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/AirsonicHomeTest.java index acc129b5..643136c2 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/AirsonicHomeTest.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/AirsonicHomeTest.java @@ -1,11 +1,11 @@ package org.airsonic.player.service.search; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - import org.airsonic.player.domain.MusicFolder; import org.airsonic.player.util.MusicFolderTestData; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + /** * Test case interface for scanning MusicFolder. */ diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/AnalyzerFactoryTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/AnalyzerFactoryTestCase.java index 7cc4f98c..4e56142d 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/AnalyzerFactoryTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/AnalyzerFactoryTestCase.java @@ -1,8 +1,10 @@ package org.airsonic.player.service.search; -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; +import org.junit.Test; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.StringReader; @@ -10,10 +12,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; -import org.junit.Test; -import org.slf4j.LoggerFactory; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; /** * Test case for Analyzer. @@ -218,7 +218,7 @@ public class AnalyzerFactoryTestCase { } }); - } + } /** * Simple test on FullWidth. @@ -480,18 +480,18 @@ public class AnalyzerFactoryTestCase { assertEquals(asList("abc", "def"), toTermString("~ABC~DEF~")); assertEquals(asList("abc", "def"), toTermString("*ABC*DEF*")); assertEquals(asList("abc", "def"), toTermString("?ABC?DEF?")); - assertEquals(asList("abc:def"), toTermString(":ABC:DEF:")); // XXX 3.x -> 8.x : abc def -> abc:def + assertEquals(asList("abc:def"), toTermString(":ABC:DEF:")); // XXX 3.x -> 8.x : abc def -> abc:def assertEquals(asList("abc", "def"), toTermString("-ABC-DEF-")); assertEquals(asList("abc", "def"), toTermString("/ABC/DEF/")); /* * XXX 3.x -> 8.x : _abc_def_ in UAX#29. * Since the effect is large, trim with Filter. */ - assertEquals(asList("abc_def"), toTermString("_ABC_DEF_")); // XXX 3.x -> 8.x : abc def -> abc_def + assertEquals(asList("abc_def"), toTermString("_ABC_DEF_")); // XXX 3.x -> 8.x : abc def -> abc_def assertEquals(asList("abc", "def"), toTermString(",ABC,DEF,")); assertEquals(asList("abc.def"), toTermString(".ABC.DEF.")); - assertEquals(asList("abc", "def"), toTermString("&ABC&DEF&")); // XXX 3.x -> 8.x : abc&def -> abc def - assertEquals(asList("abc", "def"), toTermString("@ABC@DEF@")); // XXX 3.x -> 8.x : abc@def -> abc def + assertEquals(asList("abc", "def"), toTermString("&ABC&DEF&")); // XXX 3.x -> 8.x : abc&def -> abc def + assertEquals(asList("abc", "def"), toTermString("@ABC@DEF@")); // XXX 3.x -> 8.x : abc@def -> abc def assertEquals(asList("abc'def"), toTermString("'ABC'DEF'")); // trim and delimiter and number @@ -511,15 +511,15 @@ public class AnalyzerFactoryTestCase { assertEquals(asList("abc1", "def"), toTermString("*ABC1*DEF*")); assertEquals(asList("abc1", "def"), toTermString("?ABC1?DEF?")); assertEquals(asList("abc1", "def"), toTermString(":ABC1:DEF:")); - assertEquals(asList("abc1", "def"), toTermString(",ABC1,DEF,")); // XXX 3.x -> 8.x : abc1,def -> abc1 def - assertEquals(asList("abc1", "def"), toTermString("-ABC1-DEF-")); // XXX 3.x -> 8.x : abc1-def -> abc1 def - assertEquals(asList("abc1", "def"), toTermString("/ABC1/DEF/")); // XXX 3.x -> 8.x : abc1/def -> abc1 def + assertEquals(asList("abc1", "def"), toTermString(",ABC1,DEF,")); // XXX 3.x -> 8.x : abc1,def -> abc1 def + assertEquals(asList("abc1", "def"), toTermString("-ABC1-DEF-")); // XXX 3.x -> 8.x : abc1-def -> abc1 def + assertEquals(asList("abc1", "def"), toTermString("/ABC1/DEF/")); // XXX 3.x -> 8.x : abc1/def -> abc1 def /* * XXX 3.x -> 8.x : _abc1_def_ in UAX#29. * Since the effect is large, trim with Filter. */ assertEquals(asList("abc1_def"), toTermString("_ABC1_DEF_")); - assertEquals(asList("abc1", "def"), toTermString(".ABC1.DEF.")); // XXX 3.x -> 8.x : abc1.def -> abc1 def + assertEquals(asList("abc1", "def"), toTermString(".ABC1.DEF.")); // XXX 3.x -> 8.x : abc1.def -> abc1 def assertEquals(asList("abc1", "def"), toTermString("&ABC1&DEF&")); assertEquals(asList("abc1", "def"), toTermString("@ABC1@DEF@")); assertEquals(asList("abc1", "def"), toTermString("'ABC1'DEF'")); @@ -631,8 +631,6 @@ public class AnalyzerFactoryTestCase { assertEquals("{ }", terms.get(0)); } - - private List toTermString(String str) { return toTermString(null, str); } diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/IndexManagerTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/IndexManagerTestCase.java index 536813a6..0d74838b 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/IndexManagerTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/IndexManagerTestCase.java @@ -26,8 +26,6 @@ import org.airsonic.player.domain.MusicFolder; import org.airsonic.player.domain.SearchCriteria; import org.airsonic.player.domain.SearchResult; import org.airsonic.player.service.SearchService; -import org.airsonic.player.service.search.IndexManager; -import org.airsonic.player.service.search.IndexType; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -36,9 +34,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ResourceLoader; import java.io.File; +import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.ArrayList; import static org.junit.Assert.assertEquals; import static org.springframework.util.ObjectUtils.isEmpty; diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialGenreTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialGenreTestCase.java index 53fb5b55..6eed7af1 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialGenreTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialGenreTestCase.java @@ -1,13 +1,7 @@ package org.airsonic.player.service.search; -import static org.springframework.util.ObjectUtils.isEmpty; - -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - +import com.google.common.base.Function; import org.airsonic.player.domain.MediaFile; import org.airsonic.player.domain.MusicFolder; import org.airsonic.player.domain.RandomSearchCriteria; @@ -17,7 +11,12 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; -import com.google.common.base.Function; +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static org.springframework.util.ObjectUtils.isEmpty; /* * Tests to prove what kind of strings/chars can be used in the genre field. @@ -63,7 +62,7 @@ public class SearchServiceSpecialGenreTestCase extends AbstractAirsonicHomeTest public void testQueryEscapeRequires() { Function simpleStringCriteria = s -> - new RandomSearchCriteria(Integer.MAX_VALUE, // count + new RandomSearchCriteria(Integer.MAX_VALUE, // count s, // genre, null, // fromYear null, // toYear @@ -194,7 +193,7 @@ public class SearchServiceSpecialGenreTestCase extends AbstractAirsonicHomeTest public void testBrackets() { Function simpleStringCriteria = s -> - new RandomSearchCriteria(Integer.MAX_VALUE, // count + new RandomSearchCriteria(Integer.MAX_VALUE, // count s, // genre, null, // fromYear null, // toYear @@ -268,7 +267,7 @@ public class SearchServiceSpecialGenreTestCase extends AbstractAirsonicHomeTest public void testOthers() { Function simpleStringCriteria = s -> - new RandomSearchCriteria(Integer.MAX_VALUE, // count + new RandomSearchCriteria(Integer.MAX_VALUE, // count s, // genre, null, // fromYear null, // toYear diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialPathTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialPathTestCase.java index 44095d95..02c19a66 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialPathTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceSpecialPathTestCase.java @@ -1,12 +1,6 @@ package org.airsonic.player.service.search; -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - import org.airsonic.player.domain.MediaFile; import org.airsonic.player.domain.MusicFolder; import org.airsonic.player.service.SearchService; @@ -14,6 +8,13 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; + +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + import static org.springframework.util.ObjectUtils.isEmpty; /* diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceStartWithStopwardsTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceStartWithStopwardsTestCase.java index f84eb4bf..aea0639d 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceStartWithStopwardsTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceStartWithStopwardsTestCase.java @@ -1,11 +1,6 @@ package org.airsonic.player.service.search; -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - import org.airsonic.player.domain.MusicFolder; import org.airsonic.player.domain.SearchCriteria; import org.airsonic.player.domain.SearchResult; @@ -14,6 +9,12 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; + +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import static org.springframework.util.ObjectUtils.isEmpty; /* diff --git a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceTestCase.java index 0989cc2c..039c4008 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/service/search/SearchServiceTestCase.java @@ -4,12 +4,6 @@ package org.airsonic.player.service.search; import com.codahale.metrics.ConsoleReporter; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; - -import java.util.Arrays; -import java.util.List; -import java.util.Random; -import java.util.concurrent.TimeUnit; - import org.airsonic.player.dao.AlbumDao; import org.airsonic.player.dao.MusicFolderDao; import org.airsonic.player.domain.Album; @@ -22,13 +16,17 @@ import org.airsonic.player.domain.RandomSearchCriteria; import org.airsonic.player.domain.SearchCriteria; import org.airsonic.player.domain.SearchResult; import org.airsonic.player.service.SearchService; -import org.airsonic.player.service.search.IndexType; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.subsonic.restapi.ArtistID3; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; + public class SearchServiceTestCase extends AbstractAirsonicHomeTest { @Autowired diff --git a/airsonic-main/src/test/java/org/airsonic/player/util/HomeRule.java b/airsonic-main/src/test/java/org/airsonic/player/util/HomeRule.java index 5350aa36..957e60ca 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/util/HomeRule.java +++ b/airsonic-main/src/test/java/org/airsonic/player/util/HomeRule.java @@ -1,7 +1,7 @@ package org.airsonic.player.util; -import org.junit.rules.ExternalResource; import org.airsonic.player.TestCaseUtils; +import org.junit.rules.ExternalResource; public class HomeRule extends ExternalResource { @Override diff --git a/airsonic-main/src/test/java/org/airsonic/player/util/MusicFolderTestData.java b/airsonic-main/src/test/java/org/airsonic/player/util/MusicFolderTestData.java index 44b719a9..11914435 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/util/MusicFolderTestData.java +++ b/airsonic-main/src/test/java/org/airsonic/player/util/MusicFolderTestData.java @@ -9,34 +9,33 @@ import java.util.List; public class MusicFolderTestData { - private static String baseResources = "/MEDIAS/"; - - public static String resolveBaseMediaPath() { - return MusicFolderTestData.class.getResource(baseResources).toString().replace("file:",""); - } - - public static String resolveMusicFolderPath() { - return (MusicFolderTestData.resolveBaseMediaPath() + "Music"); - } - - public static String resolveMusic2FolderPath() { - return (MusicFolderTestData.resolveBaseMediaPath() + "Music2"); - } - - public static String resolveMusic3FolderPath() { - return (MusicFolderTestData.resolveBaseMediaPath() + "Music3"); - } - - public static List getTestMusicFolders() { - List liste = new ArrayList<>(); - File musicDir = new File(MusicFolderTestData.resolveMusicFolderPath()); - MusicFolder musicFolder = new MusicFolder(1,musicDir,"Music",true,new Date()); - liste.add(musicFolder); - - File music2Dir = new File(MusicFolderTestData.resolveMusic2FolderPath()); - MusicFolder musicFolder2 = new MusicFolder(2,music2Dir,"Music2",true,new Date()); - liste.add(musicFolder2); - return liste; - } - + private static String baseResources = "/MEDIAS/"; + + public static String resolveBaseMediaPath() { + return MusicFolderTestData.class.getResource(baseResources).toString().replace("file:",""); + } + + public static String resolveMusicFolderPath() { + return (MusicFolderTestData.resolveBaseMediaPath() + "Music"); + } + + public static String resolveMusic2FolderPath() { + return (MusicFolderTestData.resolveBaseMediaPath() + "Music2"); + } + + public static String resolveMusic3FolderPath() { + return (MusicFolderTestData.resolveBaseMediaPath() + "Music3"); + } + + public static List getTestMusicFolders() { + List liste = new ArrayList<>(); + File musicDir = new File(MusicFolderTestData.resolveMusicFolderPath()); + MusicFolder musicFolder = new MusicFolder(1,musicDir,"Music",true,new Date()); + liste.add(musicFolder); + + File music2Dir = new File(MusicFolderTestData.resolveMusic2FolderPath()); + MusicFolder musicFolder2 = new MusicFolder(2,music2Dir,"Music2",true,new Date()); + liste.add(musicFolder2); + return liste; + } } diff --git a/airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java b/airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java index 4a676869..bc1f3879 100644 --- a/airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java +++ b/airsonic-main/src/test/java/org/airsonic/player/validator/PasswordSettingsValidatorTestCase.java @@ -17,7 +17,7 @@ public class PasswordSettingsValidatorTestCase extends TestCase { psc.setPassword("1234"); } - private Errors validatePassword(){ + private Errors validatePassword() { PasswordSettingsValidator psv = new PasswordSettingsValidator(); Errors errors = new BeanPropertyBindingResult(psc, "psv"); psv.validate(psc, errors); diff --git a/pom.xml b/pom.xml index f0c5e8c9..a2ea1009 100644 --- a/pom.xml +++ b/pom.xml @@ -249,6 +249,7 @@ UTF-8 true true + true check