Skip to content

Commit

Permalink
MET-5648 fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanaCMS committed Dec 11, 2023
1 parent 8582165 commit a38ec0b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.mockito.Mockito.when;

import eu.europeana.indexing.tiers.model.MediaTier;
import eu.europeana.indexing.tiers.model.TierClassifier.TierClassification;
import eu.europeana.indexing.tiers.view.ContentTierBreakdown;
import eu.europeana.indexing.tiers.view.MediaResourceTechnicalMetadata;
import eu.europeana.indexing.tiers.view.MediaResourceTechnicalMetadata.MediaResourceTechnicalMetadataBuilder;
Expand Down Expand Up @@ -73,7 +74,13 @@ void resetMocks() {
@Test
void testClassify_PreClassify() {
final RdfWrapper entity = mock(RdfWrapper.class);
doReturn(MediaTier.T0).when(classifier).preClassifyEntity(entity);
TierClassification<MediaTier, ContentTierBreakdown> mock = new TierClassification<>(MediaTier.T0, new ContentTierBreakdown.Builder()
.setThumbnailAvailable(false)
.setMediaTierBeforeLicenseCorrection(MediaTier.T0)
.setLicenseType(entity.getLicenseType())
.setMediaResourceTechnicalMetadataList(Collections.emptyList())
.build());
doReturn(mock).when(classifier).preClassifyEntity(entity);
assertEquals(MediaTier.T0, classifier.classify(entity).getTier());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void testPreClassifyEntity() {
doReturn(true).when(entity).hasThumbnails();
assertNull(classifier.preClassifyEntity(entity));
doReturn(false).when(entity).hasThumbnails();
assertEquals(MediaTier.T0, classifier.preClassifyEntity(entity));
assertEquals(MediaTier.T0, classifier.preClassifyEntity(entity).getTier());
}

@ParameterizedTest(name = "[{index}] - expectedTier:{0} for resolution:{1}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import static org.mockito.Mockito.verify;

import eu.europeana.indexing.tiers.model.MediaTier;
import eu.europeana.indexing.tiers.model.TierClassifier.TierClassification;
import eu.europeana.indexing.tiers.view.ContentTierBreakdown;
import eu.europeana.indexing.utils.RdfWrapper;
import eu.europeana.metis.schema.jibx.EdmType;
import java.util.Collections;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -46,11 +49,41 @@ void testClassify() {

// Create entity and tiers for various types
final RdfWrapper entity = mock(RdfWrapper.class);
final MediaTier audioTier = MediaTier.T1;
final MediaTier imageTier = MediaTier.T2;
final MediaTier textTier = MediaTier.T3;
final MediaTier videoTier = MediaTier.T4;
final MediaTier threeDTier = MediaTier.T2;
final TierClassification<MediaTier, ContentTierBreakdown> audioTier =
new TierClassification<>(MediaTier.T1, new ContentTierBreakdown.Builder()
.setThumbnailAvailable(false)
.setMediaTierBeforeLicenseCorrection(MediaTier.T1)
.setLicenseType(entity.getLicenseType())
.setMediaResourceTechnicalMetadataList(Collections.emptyList())
.build());
final TierClassification<MediaTier, ContentTierBreakdown> imageTier =
new TierClassification<>(MediaTier.T2, new ContentTierBreakdown.Builder()
.setThumbnailAvailable(false)
.setMediaTierBeforeLicenseCorrection(MediaTier.T2)
.setLicenseType(entity.getLicenseType())
.setMediaResourceTechnicalMetadataList(Collections.emptyList())
.build());
final TierClassification<MediaTier, ContentTierBreakdown> textTier =
new TierClassification<>(MediaTier.T3, new ContentTierBreakdown.Builder()
.setThumbnailAvailable(false)
.setMediaTierBeforeLicenseCorrection(MediaTier.T2)
.setLicenseType(entity.getLicenseType())
.setMediaResourceTechnicalMetadataList(Collections.emptyList())
.build());
final TierClassification<MediaTier, ContentTierBreakdown> videoTier =
new TierClassification<>(MediaTier.T4, new ContentTierBreakdown.Builder()
.setThumbnailAvailable(false)
.setMediaTierBeforeLicenseCorrection(MediaTier.T2)
.setLicenseType(entity.getLicenseType())
.setMediaResourceTechnicalMetadataList(Collections.emptyList())
.build());
final TierClassification<MediaTier, ContentTierBreakdown> threeDTier =
new TierClassification<>(MediaTier.T2, new ContentTierBreakdown.Builder()
.setThumbnailAvailable(false)
.setMediaTierBeforeLicenseCorrection(MediaTier.T2)
.setLicenseType(entity.getLicenseType())
.setMediaResourceTechnicalMetadataList(Collections.emptyList())
.build());
doReturn(audioTier).when(audioClassifier).classify(entity);
doReturn(imageTier).when(imageClassifier).classify(entity);
doReturn(textTier).when(textClassifier).classify(entity);
Expand All @@ -59,7 +92,7 @@ void testClassify() {

// Test audio
doReturn(EdmType.SOUND).when(entity).getEdmType();
assertEquals(audioTier, classifier.classify(entity).getTier());
assertEquals(audioTier.getTier(), classifier.classify(entity).getTier());
verify(audioClassifier, times(1)).classify(entity);
verify(imageClassifier, times(0)).classify(entity);
verify(textClassifier, times(0)).classify(entity);
Expand All @@ -68,7 +101,7 @@ void testClassify() {

// Test image
doReturn(EdmType.IMAGE).when(entity).getEdmType();
assertEquals(imageTier, classifier.classify(entity).getTier());
assertEquals(imageTier.getTier(), classifier.classify(entity).getTier());
verify(audioClassifier, times(1)).classify(entity);
verify(imageClassifier, times(1)).classify(entity);
verify(textClassifier, times(0)).classify(entity);
Expand All @@ -77,7 +110,7 @@ void testClassify() {

// Test text
doReturn(EdmType.TEXT).when(entity).getEdmType();
assertEquals(textTier, classifier.classify(entity).getTier());
assertEquals(textTier.getTier(), classifier.classify(entity).getTier());
verify(audioClassifier, times(1)).classify(entity);
verify(imageClassifier, times(1)).classify(entity);
verify(textClassifier, times(1)).classify(entity);
Expand All @@ -86,7 +119,7 @@ void testClassify() {

// Test video
doReturn(EdmType.VIDEO).when(entity).getEdmType();
assertEquals(videoTier, classifier.classify(entity).getTier());
assertEquals(videoTier.getTier(), classifier.classify(entity).getTier());
verify(audioClassifier, times(1)).classify(entity);
verify(imageClassifier, times(1)).classify(entity);
verify(textClassifier, times(1)).classify(entity);
Expand All @@ -95,7 +128,7 @@ void testClassify() {

// Test 3D
doReturn(EdmType._3_D).when(entity).getEdmType();
assertEquals(threeDTier, classifier.classify(entity).getTier());
assertEquals(threeDTier.getTier(), classifier.classify(entity).getTier());
verify(audioClassifier, times(1)).classify(entity);
verify(imageClassifier, times(1)).classify(entity);
verify(textClassifier, times(1)).classify(entity);
Expand Down

0 comments on commit a38ec0b

Please sign in to comment.