Skip to content

Commit

Permalink
Merge pull request #72 from josdem/feature/59
Browse files Browse the repository at this point in the history
[medium]Feature/59
  • Loading branch information
josdem authored Jan 19, 2025
2 parents 99e5510 + dcd4e84 commit 0144d2d
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 164 deletions.
4 changes: 3 additions & 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.2.7'
version = '1.2.8'

java {
toolchain {
Expand All @@ -32,6 +32,7 @@ ext {
javaAnnotationVersion = '1.3.2'
commonsLangVersion = '3.17.0'
mockitoVersion = '3.12.4'
mockitoInlineVersion = '5.2.0'
targetDir = "src/main/java/com/josdem/jmetadata"
}

Expand Down Expand Up @@ -71,6 +72,7 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation "org.mockito:mockito-core:$mockitoVersion"
testImplementation "org.mockito:mockito-inline:$mockitoInlineVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
Expand Down
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.
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/josdem/jmetadata/helper/RetrofitInstance.java
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.helper;

import org.springframework.stereotype.Component;
import retrofit2.Retrofit;

@Component
public class RetrofitInstance {

public Retrofit getRetrofit() {
return RetrofitHelper.getRetrofit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DefaultServiceImpl implements DefaultService {

private static final String CD_NUMBER = "1";
private static final String TOTAL_CD_NUMBER = "1";

@Autowired private MetadataService metadataService;
private final MetadataService metadataService;

private final Logger log = LoggerFactory.getLogger(this.getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@
import java.net.MalformedURLException;
import java.util.Date;
import java.util.HashMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j

/**
* @understands A class who evaluates metadata and decides if LastFM can help to complete
* information
*/
@Service
@RequiredArgsConstructor
public class LastFMCompleteServiceImpl implements LastFMCompleteService {

@Autowired private LastFMAlbumHelper lastfmHelper;
@Autowired private ImageService imageService;
private final ImageService imageService;
private final LastFMAlbumHelper lastfmHelper;

private HashMap<String, Album> cachedAlbums = new HashMap<String, Album>();
private final HashMap<String, Album> cachedAlbums = new HashMap<>();

public boolean canLastFMHelpToComplete(Metadata metadata) {
String artist = metadata.getArtist();
Expand All @@ -65,7 +61,7 @@ public boolean canLastFMHelpToComplete(Metadata metadata) {
}
}
}
return info == null ? false : true;
return info != null;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
import com.josdem.jmetadata.service.LastfmService;
import java.io.IOException;
import java.net.MalformedURLException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class LastfmServiceImpl implements LastfmService {

@Autowired private LastFMCompleteService completeService;
private final LastFMCompleteService completeService;

public synchronized ActionResult completeLastFM(Metadata metadata) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.asmatron.messengine.engines.support.ControlEngineConfigurator;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.tag.TagException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class MetadataServiceImpl implements MetadataService {

@Autowired private ControlEngineConfigurator configurator;
@Autowired private MetadataHelper metadataHelper;
@Autowired private ExtractService extractService;
@Autowired private MetadataReader mp3Reader;
@Autowired private FileUtils fileUtils;
@Autowired private Properties properties;
private final ControlEngineConfigurator configurator;
private final MetadataHelper metadataHelper;
private final ExtractService extractService;
private final MetadataReader mp3Reader;
private final FileUtils fileUtils;
private final Properties properties;

private List<Metadata> metadataList;
private Set<File> filesWithoutMinimumMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.josdem.jmetadata.service.impl;

import com.josdem.jmetadata.exception.BusinessException;
import com.josdem.jmetadata.helper.RetrofitHelper;
import com.josdem.jmetadata.helper.RetrofitInstance;
import com.josdem.jmetadata.model.Album;
import com.josdem.jmetadata.model.CoverArt;
import com.josdem.jmetadata.model.CoverArtResponse;
Expand All @@ -31,22 +31,26 @@
import java.io.IOException;
import java.util.List;
import javax.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Response;

@Slf4j
@Service
@Setter
@RequiredArgsConstructor
public class MusicBrainzServiceImpl implements MusicBrainzService {

private RestService restService;
@Autowired private ImageService imageService;
private final ImageService imageService;
private final RetrofitInstance retrofitInstance;

@PostConstruct
void setup() {
restService = RetrofitHelper.getRetrofit().create(RestService.class);
public void setup() {
restService = retrofitInstance.getRetrofit().create(RestService.class);
}

public Album getAlbumByName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.mockito.Mockito.when;

import com.josdem.jmetadata.exception.BusinessException;
import com.josdem.jmetadata.helper.RetrofitInstance;
import com.josdem.jmetadata.model.Album;
import com.josdem.jmetadata.model.CoverArtImage;
import com.josdem.jmetadata.model.CoverArtResponse;
Expand All @@ -44,11 +45,11 @@
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;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;

@Slf4j
public class MusicBrainzServiceTest {
Expand All @@ -58,10 +59,14 @@ public class MusicBrainzServiceTest {
private static final String COVER_ART_URL =
"http://coverartarchive.org/release/7f3e3b3b-0b0b-4b3b-8b3b-4f3b3b3b3b3b/1234567890.jpg";

@InjectMocks private MusicBrainzService musicBrainzService = new MusicBrainzServiceImpl();
private MusicBrainzServiceImpl musicBrainzService;

@Mock private RestService restService;

@Mock private Retrofit retrofit;

@Mock private RetrofitInstance retrofitInstance;

@Mock private Call<Album> call;

@Mock private ImageService imageService;
Expand All @@ -76,6 +81,11 @@ void setup() {
MockitoAnnotations.openMocks(this);
MusicBrainzResponse musicBrainzResponse = getExpectedResponse();
ApplicationState.cache.put("Night Life", musicBrainzResponse);
when(retrofitInstance.getRetrofit()).thenReturn(retrofit);
when(retrofit.create(RestService.class)).thenReturn(restService);
when(restService.getRelease(ALBUM_ID)).thenReturn(call);
musicBrainzService = new MusicBrainzServiceImpl(imageService, retrofitInstance);
musicBrainzService.setup();
}

@Test
Expand All @@ -85,7 +95,6 @@ void shouldGetReleaseIdByName(TestInfo testInfo) throws Exception {
var expectedAlbum = new Album();
expectedAlbum.setId(ALBUM_ID);
when(call.execute()).thenReturn(Response.success(expectedAlbum));
when(restService.getRelease(ALBUM_ID)).thenReturn(call);

var result = musicBrainzService.getAlbumByName(ALBUM_NAME);
assertEquals(ALBUM_ID, result.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand All @@ -45,7 +44,7 @@ class TestDefaultService {
private static final String TOTAL_CD_NUMBER = "1";
private static final Log log = LogFactory.getLog(TestDefaultService.class);

@InjectMocks private final DefaultService defaultService = new DefaultServiceImpl();
private DefaultService defaultService;

@Mock private Metadata metadata_one;
@Mock private Metadata metadata_two;
Expand All @@ -56,6 +55,7 @@ class TestDefaultService {
@BeforeEach
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
defaultService = new DefaultServiceImpl(metadataService);
}

@Test
Expand Down
Loading

0 comments on commit 0144d2d

Please sign in to comment.