From 957b42e6633b71d4d1984b48c153f90ebf748983 Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Fri, 24 May 2024 15:20:51 +0200 Subject: [PATCH] Fixes #435 --- .../utils/commonsvfs/FileObjectDetector.java | 2 +- .../aadarchi/inferer/maven/TestFor435.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 maven-metadata-inferer/src/test/java/org/ndx/aadarchi/inferer/maven/TestFor435.java diff --git a/base/src/main/java/org/ndx/aadarchi/base/utils/commonsvfs/FileObjectDetector.java b/base/src/main/java/org/ndx/aadarchi/base/utils/commonsvfs/FileObjectDetector.java index da604e84..85220ebd 100644 --- a/base/src/main/java/org/ndx/aadarchi/base/utils/commonsvfs/FileObjectDetector.java +++ b/base/src/main/java/org/ndx/aadarchi/base/utils/commonsvfs/FileObjectDetector.java @@ -96,7 +96,7 @@ public Optional whenFileDetected(Element element, FileSelector filter = new FileFilterSelector(fileFilter); try { FileObject[] found = elementRoot.findFiles(filter); - if (found.length == 0) { + if (found==null || found.length == 0) { return onNoFileDetected.apply(elementRoot); } else if (found.length > 1) { return onMultipleFileDetected.apply(elementRoot, found); diff --git a/maven-metadata-inferer/src/test/java/org/ndx/aadarchi/inferer/maven/TestFor435.java b/maven-metadata-inferer/src/test/java/org/ndx/aadarchi/inferer/maven/TestFor435.java new file mode 100644 index 00000000..1fed6ef1 --- /dev/null +++ b/maven-metadata-inferer/src/test/java/org/ndx/aadarchi/inferer/maven/TestFor435.java @@ -0,0 +1,49 @@ +package org.ndx.aadarchi.inferer.maven; + +import java.util.Arrays; + +import jakarta.inject.Inject; + +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.assertj.core.api.Assertions; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.jboss.weld.junit5.EnableWeld; +import org.jboss.weld.junit5.WeldInitiator; +import org.jboss.weld.junit5.WeldSetup; +import org.junit.jupiter.api.Test; +import org.ndx.aadarchi.base.ArchitectureEnhancer; +import org.ndx.aadarchi.base.enhancers.ModelElementKeys; +import org.ndx.aadarchi.base.enhancers.ModelElementKeys.ConfigProperties.BasePath; +import org.ndx.aadarchi.cdi.deltaspike.ConfigProperty; + +import com.structurizr.Workspace; +import com.structurizr.model.Container; +import com.structurizr.model.SoftwareSystem; + +@EnableWeld +public class TestFor435 { + @WeldSetup + public WeldInitiator weld = WeldInitiator.performDefaultDiscovery(); + + @Inject MavenDetailsInfererEnhancer tested; + @Inject ArchitectureEnhancer enhancer; + + @Inject @ConfigProperty(name=BasePath.NAME, defaultValue = BasePath.VALUE) FileObject basePath; + + @Test public void not_finding_file_doesnt_throw_NullPoinerException() throws FileSystemException { + // Given + var w = new Workspace(getClass().getName(), "a test workspace"); + SoftwareSystem system = w.getModel().addSoftwareSystem("The system to decorate with maven informations"); + system.addProperty(ModelElementKeys.ConfigProperties.BasePath.NAME, + basePath.getName().getPath()+"/a/folder/which/doesnt/exists"); + // When + // We emulate in-depth visit (but do not really perform it) + enhancer.enhance(w, tested); + // Then + Assertions.assertThat(system.getContainers()) + .describedAs("No container should be found, since path in which we search the maven pom doesn't exists") + .isEmpty() + ; + } +}