Skip to content

Commit

Permalink
Update mockito tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Jan 3, 2025
1 parent 201f684 commit ae796f8
Show file tree
Hide file tree
Showing 34 changed files with 168 additions and 116 deletions.
12 changes: 7 additions & 5 deletions core/src/test/java/org/nzbhydra/NzbHandlerTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package org.nzbhydra;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.downloading.FileDownloadEntity;
import org.nzbhydra.downloading.FileDownloadRepository;
import org.nzbhydra.downloading.FileHandler;

import static org.mockito.Mockito.when;

import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class NzbHandlerTest {

@InjectMocks
Expand All @@ -26,7 +28,7 @@ public class NzbHandlerTest {

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);

when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
}

Expand Down
6 changes: 4 additions & 2 deletions core/src/test/java/org/nzbhydra/api/CapsGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.config.category.CategoriesConfig;
Expand All @@ -32,6 +33,7 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class CapsGeneratorTest {

@Mock
Expand All @@ -42,7 +44,7 @@ public class CapsGeneratorTest {

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);

BaseConfig baseConfig = new BaseConfig();

CategoriesConfig categoriesConfig = new CategoriesConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.category.Category;
import org.nzbhydra.searching.CategoryProvider;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class CategoryConverterTest {

@InjectMocks
Expand All @@ -21,7 +23,7 @@ public class CategoryConverterTest {

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);

testee.setCategoryProvider(categoryProviderMock);
}

Expand Down
7 changes: 4 additions & 3 deletions core/src/test/java/org/nzbhydra/api/ExternalApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.mockito.stubbing.Answer;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
Expand Down Expand Up @@ -39,7 +40,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;


@MockitoSettings(strictness = Strictness.LENIENT)
public class ExternalApiTest {

BaseConfig baseConfig = new BaseConfig();
Expand Down Expand Up @@ -76,7 +77,7 @@ public class ExternalApiTest {

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);

when(configProvider.getBaseConfig()).thenReturn(baseConfig);
baseConfig.setMain(new MainConfig());
baseConfig.getMain().setApiKey("apikey");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.config.MainConfig;
Expand All @@ -39,6 +40,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class NewznabXmlTransformerTest {

@Mock
Expand All @@ -56,7 +58,7 @@ public class NewznabXmlTransformerTest {

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);

when(configProvider.getBaseConfig()).thenReturn(baseConfig);
baseConfig.setMain(new MainConfig());
baseConfig.getMain().setApiKey("apikey");
Expand Down
9 changes: 5 additions & 4 deletions core/src/test/java/org/nzbhydra/backup/BackupTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.genericstorage.GenericStorage;
Expand All @@ -22,8 +23,10 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

@MockitoSettings(strictness = Strictness.LENIENT)
public class BackupTaskTest {

BaseConfig config = new BaseConfig();
@Mock
private BackupAndRestore backupAndRestore;
@Mock
Expand All @@ -32,14 +35,12 @@ public class BackupTaskTest {
private ConfigProvider configProvider;
@Captor
private ArgumentCaptor<BackupData> backupDataArgumentCaptor;
BaseConfig config = new BaseConfig();

@InjectMocks
private BackupTask testee = new BackupTask();

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);


when(configProvider.getBaseConfig()).thenReturn(config);
config.getMain().setBackupEveryXDays(7);
Expand Down
16 changes: 7 additions & 9 deletions core/src/test/java/org/nzbhydra/config/BaseConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.category.Category;
import org.nzbhydra.config.validation.BaseConfigValidator;
import org.nzbhydra.config.validation.ConfigValidationTools;
Expand All @@ -27,22 +28,21 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

@MockitoSettings(strictness = Strictness.LENIENT)
public class BaseConfigTest {

//If true the actual content of the config in code and in baseConfig.yml will be compared
//If false only the structure will be compare, meaning both sides have to have the same keys but the values can be different
private static final boolean COMPARE_CONFIG_VALUES = false;
private Set<String> dontCheckTheseLists = Sets.newHashSet("categories");

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}

@InjectMocks
private BaseConfig testee = new BaseConfig();
private BaseConfigValidator baseConfigValidator = new BaseConfigValidator();

@BeforeEach
public void setUp() throws Exception {

}

@Test
void shouldRecognizeRestartRequired() {
Expand Down Expand Up @@ -88,8 +88,6 @@ void applicationPropertiesShouldHaveTheSameKeysAsConfigClasses() throws Exceptio
}




private void compare(Object left, Object right) {
if (left instanceof HashMap) {
compareMaps((HashMap) left, (HashMap) right);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.MainConfig;

Expand All @@ -40,6 +41,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class ConfigMigrationTest {

@Mock
Expand All @@ -55,7 +57,7 @@ public class ConfigMigrationTest {

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);

objectMapper.registerModule(new Jdk8Module());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.downloading.downloaders.Downloader;
Expand All @@ -38,6 +39,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

@MockitoSettings(strictness = Strictness.LENIENT)
public class DownloadStatusUpdaterTest {

@Mock
Expand All @@ -54,7 +56,7 @@ public class DownloadStatusUpdaterTest {

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);

when(downloaderProvider.getAllDownloaders()).thenReturn(Collections.singletonList(downloaderMock));
when(downloaderMock.isEnabled()).thenReturn(true);
when(configProvider.getBaseConfig()).thenReturn(new BaseConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.config.SearchSource;
Expand All @@ -53,6 +54,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class IndexerUniquenessScoreSaverTest {

@Mock
Expand Down Expand Up @@ -80,7 +82,7 @@ public class IndexerUniquenessScoreSaverTest {

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);

final BaseConfig value = new BaseConfig();
value.getMain().setKeepHistory(true);
when(configProviderMock.getBaseConfig()).thenReturn(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.nzbhydra.config.downloading.DownloaderConfig;
import org.nzbhydra.downloading.FileDownloadEntity;
import org.nzbhydra.downloading.FileDownloadStatus;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class DownloaderTest {

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);

testee.nzbHandler = nzbHandler;
testee.searchResultRepository = searchResultRepository;
testee.downloaderConfig = new DownloaderConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
import org.nzbhydra.downloading.DownloadResult;
Expand All @@ -32,6 +33,7 @@

import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class TorrentFileHandlerTest {

@Mock
Expand All @@ -44,7 +46,7 @@ public class TorrentFileHandlerTest {

@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);


final BaseConfig baseConfig = new BaseConfig();
when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
Expand Down
8 changes: 5 additions & 3 deletions core/src/test/java/org/nzbhydra/indexers/AnizbTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.mockito.stubbing.Answer;
import org.nzbhydra.config.BaseConfig;
import org.nzbhydra.config.ConfigProvider;
Expand All @@ -23,11 +24,12 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@MockitoSettings(strictness = Strictness.LENIENT)
public class AnizbTest {

BaseConfig baseConfig = new BaseConfig();
@Mock
private ConfigProvider configProviderMock;
BaseConfig baseConfig = new BaseConfig();
@Mock
private QueryGenerator queryGeneratorMock;

Expand All @@ -37,7 +39,7 @@ public class AnizbTest {

@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);

when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
testee.config = new IndexerConfig();
testee.config.setName("anizb");
Expand Down
Loading

0 comments on commit ae796f8

Please sign in to comment.