Skip to content

Commit c197f16

Browse files
committed
Fix tests
1 parent 3134131 commit c197f16

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

core/esmf-aspect-model-aas-generator/src/main/java/org/eclipse/esmf/aspectmodel/aas/AasToAspectModelGenerator.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.URI;
2020
import java.util.ArrayDeque;
2121
import java.util.Arrays;
22+
import java.util.Collections;
2223
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Locale;
@@ -180,20 +181,29 @@ private <T> Collector<T, ArrayDeque<T>, ArrayDeque<T>> reverseOrder() {
180181
}
181182

182183
private String iriToReversedHostNameNotation( final IRI iri ) {
183-
final URI uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );
184+
URI uri;
185+
try {
186+
uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );
187+
} catch ( IllegalArgumentException e ) {
188+
throw new IllegalArgumentException( "Incorrect IRI: " + iri, e );
189+
}
184190

185-
final String[] hostParts = uri.getHost().split( "\\." );
186-
final String[] pathParts = uri.getPath().split( "/" );
191+
if ( uri.getHost() == null ) {
192+
throw new IllegalArgumentException( "URI doesn't contain host: " + uri );
193+
}
187194

188-
final String reversedHost = String.join( ".", Arrays.stream( hostParts )
189-
.collect( reverseOrder() ) );
195+
final String[] hostParts = uri.getHost().split( "\\." );
196+
final List<String> hostPartsList = Arrays.asList( hostParts );
197+
Collections.reverse( hostPartsList );
198+
final String reversedHost = String.join( ".", hostPartsList );
190199

200+
final String[] pathParts = uri.getPath().split( "/" );
191201
final String path = Arrays.stream( pathParts )
192202
.filter( StringUtils::isNotBlank )
193-
.limit( pathParts.length - 2 )
203+
.limit( Math.max( 0, pathParts.length - 2 ) )
194204
.collect( Collectors.joining( "." ) );
195205

196-
return reversedHost + "." + path;
206+
return reversedHost + ( path.isEmpty() ? "" : "." + path );
197207
}
198208

199209
private Optional<IRI> iri( final String lexicalRepresentation ) {

0 commit comments

Comments
 (0)