Fix tests by project mocking
@@ -35,8 +35,11 @@ import io.github.mzmine.datamodel.identities.iontype.IonModification;
import io.github.mzmine.datamodel.identities.iontype.IonNetwork;
import io.github.mzmine.datamodel.identities.iontype.IonNetworkLogic;
import io.github.mzmine.datamodel.identities.iontype.IonType;
+import io.github.mzmine.main.MZmineCore;
import io.github.mzmine.modules.dataprocessing.id_formulaprediction.ResultFormula;
import io.github.mzmine.parameters.parametertypes.tolerances.MZTolerance;
+import io.github.mzmine.project.ProjectManager;
+import io.github.mzmine.project.impl.MZmineProjectImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
@@ -44,6 +47,8 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
/**
@@ -59,6 +64,9 @@ public class IonIdentityTest {
@Mock
RawDataFile raw;
+ @Mock
+ ProjectManager projectManager;
+
@Mock
ResultFormula formula;
@@ -67,6 +75,13 @@ public class IonIdentityTest {
@Test
void ionIdentityTest() {
+ MZmineProjectImpl project = new MZmineProjectImpl();
+ try (MockedStatic<MZmineCore> utilities = Mockito.mockStatic(MZmineCore.class)) {
+ utilities.when(MZmineCore::getProjectManager).thenReturn(projectManager);
+ doReturn(project).when(projectManager).getCurrentProject();
+ assertEquals(project, MZmineCore.getProjectManager().getCurrentProject());
+
+ // create feature list need project manager and project
ModularFeatureList flist = new ModularFeatureList("A", null, raw);
flist.addRowType(new IDType());
@@ -148,5 +163,5 @@ public class IonIdentityTest {
"Cannot access formula specific types from sub types of IonIdentityModularType.class");
}
-
+ }
}
