-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from josdem/feature/54
[small]Feature/54
- Loading branch information
Showing
7 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ plugins { | |
} | ||
|
||
group = 'com.josdem.jmetadata' | ||
version = '1.2.4' | ||
version = '1.2.5' | ||
|
||
java { | ||
toolchain { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2024 Jose Morales [email protected] | ||
Copyright 2025 Jose Morales [email protected] | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -17,8 +17,12 @@ | |
package com.josdem.jmetadata.service; | ||
|
||
import com.josdem.jmetadata.model.Album; | ||
import com.josdem.jmetadata.model.Metadata; | ||
import java.util.List; | ||
|
||
public interface MusicBrainzService { | ||
|
||
Album getAlbumByName(String name); | ||
|
||
List<Metadata> completeAlbum(List<Metadata> metadataList, Album album); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2025 Jose Morales [email protected] | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.josdem.jmetadata.util; | ||
|
||
public class AlbumUtils { | ||
|
||
private AlbumUtils() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
public static String formatYear(String date) { | ||
return date.substring(0, 4); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2024 Jose Morales [email protected] | ||
Copyright 2025 Jose Morales [email protected] | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -22,17 +22,22 @@ | |
|
||
import com.josdem.jmetadata.exception.BusinessException; | ||
import com.josdem.jmetadata.model.Album; | ||
import com.josdem.jmetadata.model.Metadata; | ||
import com.josdem.jmetadata.model.MusicBrainzResponse; | ||
import com.josdem.jmetadata.model.Release; | ||
import com.josdem.jmetadata.service.impl.MusicBrainzServiceImpl; | ||
import com.josdem.jmetadata.util.ApplicationState; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
@@ -51,6 +56,9 @@ public class MusicBrainzServiceTest { | |
|
||
@Mock private Call<Album> call; | ||
|
||
private final Metadata metadata = new Metadata(); | ||
private final Album album = new Album(); | ||
|
||
@BeforeEach | ||
void setup() { | ||
MockitoAnnotations.openMocks(this); | ||
|
@@ -89,4 +97,39 @@ private MusicBrainzResponse getExpectedResponse() { | |
musicBrainzResponse.setReleases(releases); | ||
return musicBrainzResponse; | ||
} | ||
|
||
@DisplayName("completing year from album") | ||
@ParameterizedTest | ||
@NullSource | ||
@ValueSource(strings = {"", " "}) | ||
void shouldCompleteYearFromAlbum(String metadataYear) { | ||
setMetadataExpectations(); | ||
metadata.setYear(metadataYear); | ||
var metadataList = List.of(metadata); | ||
album.setDate("1999-03-29"); | ||
|
||
var result = musicBrainzService.completeAlbum(metadataList, album); | ||
|
||
assertEquals("1999", result.getFirst().getYear()); | ||
assertEquals(1, result.size()); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullSource | ||
@ValueSource(strings = {"", " "}) | ||
@DisplayName("not completing year if not valid format") | ||
void shouldNotCompleteYearIfNotValidFormat(String date) { | ||
setMetadataExpectations(); | ||
metadata.setYear(StringUtils.EMPTY); | ||
var metadataList = List.of(metadata); | ||
album.setDate(date); | ||
|
||
assertThrows( | ||
BusinessException.class, () -> musicBrainzService.completeAlbum(metadataList, album)); | ||
} | ||
|
||
private void setMetadataExpectations() { | ||
metadata.setAlbum("Nightlife"); | ||
metadata.setArtist("Pet shop boys"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/java/com/josdem/jmetadata/service/TestMetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2014 Jose Morales [email protected] | ||
Copyright 2025 Jose Morales [email protected] | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|