Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[small]Feature/66 #85

Merged
merged 4 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = 'com.josdem.jmetadata'
version = '1.3.1'
version = '1.3.2'

java {
toolchain {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/josdem/jmetadata/metadata/Mp3Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.File;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.asmatron.messengine.engines.support.ControlEngineConfigurator;
import org.asmatron.messengine.event.ValueEvent;
import org.jaudiotagger.audio.AudioFile;
Expand Down Expand Up @@ -126,8 +127,10 @@ private String getTrackNumber() {
return tag.getFirst(FieldKey.TRACK);
}

// This is a bug in jaudiotagger, it returns "null" instead of an empty string
private String getTotalTracks() {
return tag.getFirst(FieldKey.TRACK_TOTAL);
var totalTracks = tag.getFirst(FieldKey.TRACK_TOTAL);
return totalTracks != null && totalTracks.equals("null") ? StringUtils.EMPTY : totalTracks;
}

private String getCdNumber() {
Expand Down
34 changes: 23 additions & 11 deletions src/test/java/com/josdem/jmetadata/metadata/Mp3ReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.io.File;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.asmatron.messengine.ControlEngine;
import org.asmatron.messengine.engines.support.ControlEngineConfigurator;
import org.asmatron.messengine.event.ValueEvent;
Expand Down Expand Up @@ -198,7 +199,7 @@ void shouldGetVariableBitRate(TestInfo testInfo) throws Exception {

@Test
@DisplayName("getting track number")
public void shouldGetTrackNumber(TestInfo testInfo) throws Exception {
void shouldGetTrackNumber(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
var trackNumber = "11";
when(tag.getFirst(FieldKey.TRACK)).thenReturn(trackNumber);
Expand All @@ -209,7 +210,7 @@ public void shouldGetTrackNumber(TestInfo testInfo) throws Exception {

@Test
@DisplayName("getting total tracks")
public void shouldGetTotalTracks(TestInfo testInfo) throws Exception {
void shouldGetTotalTracks(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
var totalTracks = "20";
when(tag.getFirst(FieldKey.TRACK_TOTAL)).thenReturn(totalTracks);
Expand All @@ -218,9 +219,20 @@ public void shouldGetTotalTracks(TestInfo testInfo) throws Exception {
assertEquals(totalTracks, metadata.getTotalTracks());
}

@Test
@DisplayName("getting empty string when total tracks is 'null'")
void shouldGetEmptyTotalTracks(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
var totalTracks = "null";
when(tag.getFirst(FieldKey.TRACK_TOTAL)).thenReturn(totalTracks);
var metadata = reader.getMetadata(file);

assertEquals(StringUtils.EMPTY, metadata.getTotalTracks());
}

@Test
@DisplayName("getting cd number")
public void shouldGetCdNumber(TestInfo testInfo) throws Exception {
void shouldGetCdNumber(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
var cdNumber = "1";
when(tag.getFirst(FieldKey.DISC_NO)).thenReturn(cdNumber);
Expand All @@ -231,7 +243,7 @@ public void shouldGetCdNumber(TestInfo testInfo) throws Exception {

@Test
@DisplayName("getting total cds")
public void shouldGetTotalCds(TestInfo testInfo) throws Exception {
void shouldGetTotalCds(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
var totalCds = "2";
when(tag.getFirst(FieldKey.DISC_TOTAL)).thenReturn(totalCds);
Expand All @@ -242,7 +254,7 @@ public void shouldGetTotalCds(TestInfo testInfo) throws Exception {

@Test
@DisplayName("getting genre")
public void shouldGetGenre(TestInfo testInfo) throws Exception {
void shouldGetGenre(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
var genre = "Minimal Techno";
when(tag.getFirst(FieldKey.GENRE)).thenReturn(genre);
Expand All @@ -255,7 +267,7 @@ public void shouldGetGenre(TestInfo testInfo) throws Exception {

@Test
@DisplayName("getting genre by code")
public void shouldGetGenreByCode(TestInfo testInfo) throws Exception {
void shouldGetGenreByCode(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
var genreAsCode = "31";
var genre = "Trance";
Expand All @@ -267,7 +279,7 @@ public void shouldGetGenreByCode(TestInfo testInfo) throws Exception {

@Test
@DisplayName("getting cover art")
public void shouldNotGetCoverArt() throws Exception {
void shouldNotGetCoverArt() throws Exception {
when(artwork.getImage()).thenReturn(bufferedImage);
var metadata = reader.getMetadata(file);

Expand All @@ -276,7 +288,7 @@ public void shouldNotGetCoverArt() throws Exception {

@Test
@DisplayName("not getting cover art if no artwork")
public void shouldNotGetCoverArtIfNoArtWork(TestInfo testInfo) throws Exception {
void shouldNotGetCoverArtIfNoArtWork(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
when(tag.getFirstArtwork()).thenReturn(null);
var metadata = reader.getMetadata(file);
Expand All @@ -286,7 +298,7 @@ public void shouldNotGetCoverArtIfNoArtWork(TestInfo testInfo) throws Exception

@Test
@DisplayName("not getting cover art due to exception")
public void shouldNotGetCoverArtDueToException(TestInfo testInfo) throws Exception {
void shouldNotGetCoverArtDueToException(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
when(artwork.getImage()).thenThrow(new IOException("IO Exception"));
when(tag.getFirst(FieldKey.TITLE)).thenReturn(TITLE);
Expand All @@ -298,15 +310,15 @@ public void shouldNotGetCoverArtDueToException(TestInfo testInfo) throws Excepti

@Test
@DisplayName("getting file")
public void shouldGetFile(TestInfo testInfo) throws Exception {
void shouldGetFile(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
Metadata metadata = reader.getMetadata(file);
assertNotNull(metadata.getFile());
}

@Test
@DisplayName("getting new metadata when no tag or no header")
public void shouldReturnNewMetadataWhenNoTagOrNoHeader(TestInfo testInfo) throws Exception {
void shouldReturnNewMetadataWhenNoTagOrNoHeader(TestInfo testInfo) throws Exception {
log.info(testInfo.getDisplayName());
when(jAudioTaggerCollaborator.isValid(tag, header)).thenReturn(false);

Expand Down