Skip to content

Commit

Permalink
[java] Removing usages of deprecated methods in Require.java
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Jun 26, 2024
1 parent 2b32dbd commit dcd99ce
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions java/test/org/openqa/selenium/RequireTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,40 +189,40 @@ void canCheckIntegerArgumentWithCheckerObject() {
@Test
void canCheckFileArgument() throws IOException {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Require.argument("Target", (File) null).isFile())
.isThrownBy(() -> Require.argument("Target", (Path) null).isFile())
.withMessage("Target must be set");
File tempFile = File.createTempFile("example", "tmp");
tempFile.deleteOnExit();
assertThat(Require.argument("Target", tempFile).isFile()).isSameAs(tempFile);
assertThat(Require.argument("Target", tempFile.toPath()).isFile()).isSameAs(tempFile.toPath());
File dir = tempFile.getParentFile();
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Require.argument("Target", dir).isFile())
.isThrownBy(() -> Require.argument("Target", dir.toPath()).isFile())
.withMessage("Target must be a regular file: %s", dir);
if (!tempFile.delete()) {
fail("Unable to delete temp file");
}
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Require.argument("Target", tempFile).isFile())
.isThrownBy(() -> Require.argument("Target", tempFile.toPath()).isFile())
.withMessage("Target must exist: %s", tempFile);
}

@Test
void canCheckDirectoryArgument() throws IOException {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Require.argument("Target", (File) null).isDirectory())
.isThrownBy(() -> Require.argument("Target", (Path) null).isDirectory())
.withMessage("Target must be set");
File tempFile = File.createTempFile("example", "tmp");
tempFile.deleteOnExit();
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Require.argument("Target", tempFile).isDirectory())
.isThrownBy(() -> Require.argument("Target", tempFile.toPath()).isDirectory())
.withMessage("Target must be a directory: %s", tempFile);
File dir = tempFile.getParentFile();
assertThat(Require.argument("Target", dir).isDirectory()).isSameAs(dir);
assertThat(Require.argument("Target", dir.toPath()).isDirectory()).isSameAs(dir.toPath());
if (!tempFile.delete()) {
fail("Unable to delete temp file");
}
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> Require.argument("Target", tempFile).isDirectory())
.isThrownBy(() -> Require.argument("Target", tempFile.toPath()).isDirectory())
.withMessage("Target must exist: %s", tempFile);
}

Expand Down Expand Up @@ -264,40 +264,40 @@ void canCheckStateClass() {
@Test
void canCheckFileState() throws IOException {
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> Require.state("Target", (File) null).isFile())
.isThrownBy(() -> Require.state("Target", (Path) null).isFile())
.withMessage("Target must be set");
File tempFile = File.createTempFile("example", "tmp");
tempFile.deleteOnExit();
assertThat(Require.state("Target", tempFile).isFile()).isSameAs(tempFile);
assertThat(Require.state("Target", tempFile.toPath()).isFile()).isSameAs(tempFile.toPath());
File dir = tempFile.getParentFile();
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> Require.state("Target", dir).isFile())
.isThrownBy(() -> Require.state("Target", dir.toPath()).isFile())
.withMessage("Target must be a regular file: %s", dir);
if (!tempFile.delete()) {
fail("Unable to delete temp file");
}
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> Require.state("Target", tempFile).isFile())
.isThrownBy(() -> Require.state("Target", tempFile.toPath()).isFile())
.withMessage("Target must exist: %s", tempFile);
}

@Test
void canCheckDirectoryState() throws IOException {
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> Require.state("Target", (File) null).isDirectory())
.isThrownBy(() -> Require.state("Target", (Path) null).isDirectory())
.withMessage("Target must be set");
File tempFile = File.createTempFile("example", "tmp");
tempFile.deleteOnExit();
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> Require.state("Target", tempFile).isDirectory())
.isThrownBy(() -> Require.state("Target", tempFile.toPath()).isDirectory())
.withMessage("Target must be a directory: %s", tempFile);
File dir = tempFile.getParentFile();
assertThat(Require.state("Target", dir).isDirectory()).isSameAs(dir);
assertThat(Require.state("Target", dir.toPath()).isDirectory()).isSameAs(dir.toPath());
if (!tempFile.delete()) {
fail("Unable to delete temp file");
}
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> Require.state("Target", tempFile).isDirectory())
.isThrownBy(() -> Require.state("Target", tempFile.toPath()).isDirectory())
.withMessage("Target must exist: %s", tempFile);
}

Expand Down

3 comments on commit dcd99ce

@joerg1985
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diemol i think this created duplicate tests, there was allready a test for the Path
canCheckDirectoryState -> canCheckDirectoryPathState
canCheckFileState -> canCheckFilePathState

I think canCheckDirectoryPathState and canCheckFilePathState can be deleted now.

@diemol
Copy link
Member Author

@diemol diemol commented on dcd99ce Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have deleted the tests for the deprecated methods when we marked them. I'll do that now.

@joerg1985
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sorry i missed it. I was not sure if it is okay to delete it, before deleting the methods.

Please sign in to comment.