Skip to content

Commit

Permalink
devonfw#103 fixed tests
Browse files Browse the repository at this point in the history
added missing answers to IdeTestContext
  • Loading branch information
jan-vcapgemini committed Apr 2, 2024
1 parent 3834ce8 commit ba4bc07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.devonfw.tools.ide.context;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.Condition;
import org.assertj.core.api.ListAssert;

import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.io.FileAccessImpl;
import com.devonfw.tools.ide.io.FileCopyMode;
import com.devonfw.tools.ide.io.IdeProgressBarTestImpl;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.log.IdeTestLogger;
import com.devonfw.tools.ide.repo.ToolRepositoryMock;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.Condition;
import org.assertj.core.api.ListAssert;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

/**
* Abstract base class for tests that need mocked instances of {@link IdeContext}.
Expand All @@ -37,7 +38,7 @@ public abstract class AbstractIdeContextTest extends Assertions {

/**
* @param testProject the (folder)name of the project test case, in this folder a 'project' folder represents the test
* project in {@link #TEST_PROJECTS}. E.g. "basic".
* project in {@link #TEST_PROJECTS}. E.g. "basic".
* @return the {@link IdeTestContext} pointing to that project.
*/
protected IdeTestContext newContext(String testProject) {
Expand All @@ -47,7 +48,7 @@ protected IdeTestContext newContext(String testProject) {

/**
* @param testProject the (folder)name of the project test case, in this folder a 'project' folder represents the test
* project in {@link #TEST_PROJECTS}. E.g. "basic".
* project in {@link #TEST_PROJECTS}. E.g. "basic".
* @param projectPath the relative path inside the test project where to create the context.
* @return the {@link IdeTestContext} pointing to that project.
*/
Expand All @@ -58,15 +59,16 @@ protected static IdeTestContext newContext(String testProject, String projectPat

/**
* @param testProject the (folder)name of the project test case, in this folder a 'project' folder represents the test
* project in {@link #TEST_PROJECTS}. E.g. "basic".
* project in {@link #TEST_PROJECTS}. E.g. "basic".
* @param projectPath the relative path inside the test project where to create the context.
* @param copyForMutation - {@code true} to create a copy of the project that can be modified by the test,
* {@code false} otherwise (only to save resources if you are 100% sure that your test never modifies anything in that
* project.)
* {@code false} otherwise (only to save resources if you are 100% sure that your test never modifies anything
* in that project.)
* @param answers the answers to use for the {@link IdeTestContext}.
* @return the {@link IdeTestContext} pointing to that project.
*/
protected static IdeTestContext newContext(String testProject, String projectPath, boolean copyForMutation) {
protected static IdeTestContext newContext(String testProject, String projectPath, boolean copyForMutation,
String... answers) {

Path ideRoot = TEST_PROJECTS.resolve(testProject);
if (copyForMutation) {
Expand All @@ -87,7 +89,7 @@ protected static IdeTestContext newContext(String testProject, String projectPat
if (Files.isDirectory(repositoryFolder)) {
toolRepository = new ToolRepositoryMock(repositoryFolder);
}
IdeTestContext context = new IdeTestContext(ideHome, toolRepository);
IdeTestContext context = new IdeTestContext(ideHome, toolRepository, answers);
if (toolRepository != null) {
toolRepository.setContext(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void testSecurityRiskInteractionCurrentVersionIsSafe() {
*/
private IdeContext getContextForSecurityJsonTests(Class<? extends ToolCommandlet> dummyTool, String... answers) {

String path = "workspaces/foo-test/my-git-repo";
String path = "project/workspaces/foo-test/my-git-repo";
// if I don't pass answers here I get: End of answers reached!
IdeContext context = newContext("basic", path, true, answers);
ToolCommandlet toolCommandlet = context.getCommandletManager().getCommandlet(dummyTool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class UrlSecurityJsonFileTest extends AbstractIdeContextTest {
public void testUrlJsonSecurityFileLoad() {

// arrange
String path = "workspaces/foo-test/my-git-repo";
String path = "project/workspaces/foo-test/my-git-repo";
UrlSecurityWarning warning1 = new UrlSecurityWarning();
warning1.setVersionRange(VersionRange.of("[3.0.6,3.2.1)"));
warning1.setSeverity(BigDecimal.valueOf(5.8));
Expand Down Expand Up @@ -54,7 +54,7 @@ public void testUrlJsonSecurityFileLoad() {
public void testUrlJsonSecurityFileAddAndSave() {

// arrange
String path = "workspaces/foo-test/my-git-repo";
String path = "project/workspaces/foo-test/my-git-repo";
IdeContext context = newContext("basic", path, true);
UrlSecurityJsonFile securityFile = context.getUrls().getEdition("mvn", "mvn").getSecurityJsonFile();
Path securityFilePath = securityFile.getPath();
Expand Down Expand Up @@ -82,7 +82,7 @@ public void testUrlJsonSecurityFileAddAndSave() {
public void testUrlSecurityJsonFileContains() {

// arrange
String path = "workspaces/foo-test/my-git-repo";
String path = "project/workspaces/foo-test/my-git-repo";
IdeContext context = newContext("basic", path, true);
UrlSecurityJsonFile securityFile = context.getUrls().getEdition("mvn", "mvn").getSecurityJsonFile();

Expand All @@ -99,7 +99,7 @@ public void testUrlSecurityJsonFileContains() {
public void testUrlSecurityJsonFileContainsIgnoreWarningsThatAffectAllVersions() {

// arrange
String path = "workspaces/foo-test/my-git-repo";
String path = "project/workspaces/foo-test/my-git-repo";
IdeContext context = newContext("basic", path, true);
UrlEdition edition = context.getUrls().getEdition("mvn", "mvn");
UrlSecurityJsonFile securityFile = edition.getSecurityJsonFile();
Expand All @@ -114,7 +114,7 @@ public void testUrlSecurityJsonFileContainsIgnoreWarningsThatAffectAllVersions()
public void testGetMatchingSecurityWarnings() {

// arrange
String path = "workspaces/foo-test/my-git-repo";
String path = "project/workspaces/foo-test/my-git-repo";
IdeContext context = newContext("basic", path, true);
UrlEdition edition = context.getUrls().getEdition("mvn", "mvn");
UrlSecurityJsonFile securityFile = edition.getSecurityJsonFile();
Expand Down

0 comments on commit ba4bc07

Please sign in to comment.