Skip to content

Commit 9a39a00

Browse files
add tests
1 parent 983637f commit 9a39a00

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/fs/ModelsRoot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public File determineAspectModelFile( final AspectModelUrn urn ) {
5656
return resolveByCanonicalPath( path );
5757
}
5858

59-
private static File resolveByCanonicalPath( Path path ) {
59+
private static File resolveByCanonicalPath( final Path path ) {
6060
File file = path.toFile();
6161
try {
6262
if ( Objects.equals( path.toString(), file.getCanonicalPath() ) ) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.eclipse.esmf.aspectmodel.resolver.fs;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.io.File;
6+
import java.lang.reflect.Method;
7+
import java.nio.file.Path;
8+
import java.nio.file.Paths;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
class ModelsRootTest {
13+
14+
private static final File EMPTY_FILE = new File( "" );
15+
16+
@Test
17+
void resolveByCanonicalPathShouldReturnFileWhenCanonicalPathMatches() throws Exception {
18+
Path testPath = Paths.get( "src/test/resources/resolve", "Aspect.ttl" ).toAbsolutePath();
19+
20+
File result = invokeResolveByCanonicalPath( testPath );
21+
22+
assertThat( result ).isEqualTo( testPath.toFile() );
23+
}
24+
25+
@Test
26+
void resolveByCanonicalPathShouldReturnEmptyFileWhenCanonicalPathDoesNotMatch() throws Exception {
27+
Path invalidPath = Paths.get( "src/test/resources/resolve", "aspect.ttl" ).toAbsolutePath();
28+
29+
File result = invokeResolveByCanonicalPath( invalidPath );
30+
31+
assertThat( result ).isEqualTo( EMPTY_FILE );
32+
}
33+
34+
@Test
35+
void resolveByCanonicalPathShouldReturnEmptyFileWhenIOExceptionOccurs() throws Exception {
36+
Path pathCausingIOException = Paths.get( "pathCausingIOException" );
37+
38+
File result = invokeResolveByCanonicalPath( pathCausingIOException );
39+
40+
assertThat( result ).isEqualTo( EMPTY_FILE );
41+
}
42+
43+
private static File invokeResolveByCanonicalPath( Path path ) throws Exception {
44+
Method method = ModelsRoot.class.getDeclaredMethod( "resolveByCanonicalPath", Path.class );
45+
method.setAccessible( true );
46+
return (File) method.invoke( null, path );
47+
}
48+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2021 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0#> .
14+
15+
:TestAspect a samm:Aspect ;
16+
samm:name "TestAspect" ;
17+
samm:preferredName "Test Aspect"@en ;
18+
samm:properties ( ) ;
19+
samm:operations ( ) .

0 commit comments

Comments
 (0)