Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yauhenikapl committed Sep 10, 2024
1 parent 3134131 commit c197f16
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.URI;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -180,20 +181,29 @@ private <T> Collector<T, ArrayDeque<T>, ArrayDeque<T>> reverseOrder() {
}

private String iriToReversedHostNameNotation( final IRI iri ) {
final URI uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );
URI uri;
try {
uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );
} catch ( IllegalArgumentException e ) {
throw new IllegalArgumentException( "Incorrect IRI: " + iri, e );
}

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

final String reversedHost = String.join( ".", Arrays.stream( hostParts )
.collect( reverseOrder() ) );
final String[] hostParts = uri.getHost().split( "\\." );
final List<String> hostPartsList = Arrays.asList( hostParts );
Collections.reverse( hostPartsList );
final String reversedHost = String.join( ".", hostPartsList );

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

return reversedHost + "." + path;
return reversedHost + ( path.isEmpty() ? "" : "." + path );
}

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

0 comments on commit c197f16

Please sign in to comment.