Skip to content

Commit

Permalink
Compare classes, not classnames in tests (IQSS#9014)
Browse files Browse the repository at this point in the history
* Use instanceof to compare types, not class names

* Use instanceof in FileDataProviderFactoryTest

Instead of comparing class names, the tests assert that
`result instanceof Class` (for each appropriate class).
  • Loading branch information
bencomp authored Jul 12, 2024
1 parent 54767b9 commit 5ba74e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/SwordIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public void testCreateAndDeleteDatasetInRoot() {
assertNull(attemptToGetFileId);
} catch (Exception ex) {
System.out.println("We expect an exception here because we can no longer find the file because deleted it: " + ex);
assertTrue(ex.getClass().getName().equals(ArrayIndexOutOfBoundsException.class.getName()));
assertTrue(ex instanceof ArrayIndexOutOfBoundsException);
}

String newTitle = "A New Hope";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ public class FileDataProviderFactoryTest {
public void should_return_FolderDataProvider_when_parameter_is_path() {
FileDataProvider result = target.getFileDataProvider(Path.of(UUID.randomUUID().toString()));

MatcherAssert.assertThat(result.getClass().getName(), Matchers.is(FolderDataProvider.class.getName()));
MatcherAssert.assertThat("should return FolderDataProvider when parameter is path", result instanceof FolderDataProvider);
}

@Test
public void should_return_ZipFileDataProvider_when_parameter_is_file() throws IOException {
FileDataProvider result = target.getFileDataProvider(Path.of(FIXTURE_DIRECTORY, "FileDataProviderFactoryTest.zip").toFile());

MatcherAssert.assertThat(result.getClass().getName(), Matchers.is(ZipFileDataProvider.class.getName()));
MatcherAssert.assertThat("should return ZipFileDataProvider when parameter is file", result instanceof ZipFileDataProvider);
}

@Test
public void should_return_DataFileDataProvider_when_parameter_is_datafiles() {
FileDataProvider result = target.getFileDataProvider("test-name", Collections.emptyList());

MatcherAssert.assertThat(result.getClass().getName(), Matchers.is(DataFileDataProvider.class.getName()));
MatcherAssert.assertThat("should return DataFileDataProvider when parameter is datafiles", result instanceof DataFileDataProvider);
}

}

0 comments on commit 5ba74e8

Please sign in to comment.