Skip to content

Commit

Permalink
Remove unused deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jul 18, 2023
1 parent 9e94c7d commit dad875c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,6 @@ public static String appendPath(String location, String path)
return location + path;
}

/**
* @deprecated use {@link Location#parentDirectory()} instead
*/
@Deprecated
public static String getParent(String location)
{
validateLocation(location);

int lastIndexOfSlash = location.lastIndexOf('/');
if (lastIndexOfSlash > 0) {
String parent = location.substring(0, lastIndexOfSlash);
if (!parent.endsWith("/") && !parent.endsWith(":")) {
return parent;
}
}
throw new IllegalArgumentException("Location does not have parent: " + location);
}

/**
* @deprecated use {@link Location#fileName()} instead
*/
@Deprecated
public static String getFileName(String location)
{
validateLocation(location);

return location.substring(location.lastIndexOf('/') + 1);
}

private static void validateLocation(String location)
{
checkArgument(location.indexOf('?') < 0, "location contains a query string: %s", location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import static io.trino.filesystem.Locations.appendPath;
import static io.trino.filesystem.Locations.areDirectoryLocationsEquivalent;
import static io.trino.filesystem.Locations.getFileName;
import static io.trino.filesystem.Locations.getParent;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

Expand Down Expand Up @@ -70,90 +68,6 @@ public void testInvalidLocationInAppendPath(String location, String exceptionMes
.hasMessageMatching(exceptionMessageRegexp);
}

private static Stream<Arguments> testGetFileNameFromLocationData()
{
return Stream.of(
Arguments.of("", ""),
Arguments.of("test_file", "test_file"),
Arguments.of("test>file", "test>file"),
Arguments.of("test_dir/", ""),
Arguments.of("/test_file.txt", "test_file.txt"),
Arguments.of("test_dir/test_file.txt", "test_file.txt"),
Arguments.of("/test_dir/test_file.txt", "test_file.txt"),
Arguments.of("test_dir /test_file.txt", "test_file.txt"),
Arguments.of("test_dir /test_file.txt", "test_file.txt"),
Arguments.of("test_<dir /test_file.txt", "test_file.txt"),
Arguments.of("test_dir/test_dir2/", ""),
Arguments.of("s3://test_dir/test_file.txt", "test_file.txt"),
Arguments.of("s3://test_dir/test_dir2/test_file.txt", "test_file.txt"),
Arguments.of("s3://dir_with_space /test_file.txt", "test_file.txt"),
Arguments.of("file://test_dir/test_file", "test_file"),
Arguments.of("file:/test_dir/test_file", "test_file"));
}

@ParameterizedTest
@MethodSource("testGetFileNameFromLocationData")
public void testGetFileNameFromLocation(String location, String fileName)
{
assertThat(getFileName(location)).isEqualTo(fileName);
}

@ParameterizedTest
@MethodSource("invalidLocations")
public void testGetFileNameFromInvalidLocation(String location, String exceptionMessageRegexp)
{
assertThatThrownBy(() -> getFileName(location))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching(exceptionMessageRegexp);
}

private static Stream<Arguments> validParentData()
{
return Stream.of(
Arguments.of("test_dir/", "test_dir"),
Arguments.of("test_dir/test_file.txt", "test_dir"),
Arguments.of("/test_dir/test_file.txt", "/test_dir"),
Arguments.of("test_dir /test_file.txt", "test_dir "),
Arguments.of("test_dir /test_file.txt", "test_dir "),
Arguments.of("test_<dir /test_file.txt", "test_<dir "),
Arguments.of("test_dir/test_dir2/", "test_dir/test_dir2"),
Arguments.of("s3:/test_dir/test_file.txt", "s3:/test_dir"),
Arguments.of("s3://test_dir/test_file.txt", "s3://test_dir"),
Arguments.of("s3://test_dir/test_dir2/test_file.txt", "s3://test_dir/test_dir2"),
Arguments.of("s3://dir_with_space /test_file.txt", "s3://dir_with_space "),
Arguments.of("file://test_dir/test_file", "file://test_dir"),
Arguments.of("file:/test_dir/test_file", "file:/test_dir"));
}

@ParameterizedTest
@MethodSource("validParentData")
public void testValidParent(String location, String parent)
{
assertThat(getParent(location)).isEqualTo(parent);
}

private static Stream<Arguments> invalidParentData()
{
return Stream.of(
Arguments.of("location?", "location contains a query string.*"),
Arguments.of("location#", "location contains a fragment.*"),
Arguments.of("", "Location does not have parent.*"),
Arguments.of("test_file", "Location does not have parent.*"),
Arguments.of("/test_file.txt", "Location does not have parent.*"),
Arguments.of("s3:/test_file", "Location does not have parent.*"),
Arguments.of("s3://test_file", "Location does not have parent.*"),
Arguments.of("s3:///test_file", "Location does not have parent.*"));
}

@ParameterizedTest
@MethodSource("invalidParentData")
public void testInvalidParent(String location, String exceptionMessageRegexp)
{
assertThatThrownBy(() -> getParent(location))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching(exceptionMessageRegexp);
}

@Test
public void testDirectoryLocationEquivalence()
{
Expand Down

0 comments on commit dad875c

Please sign in to comment.