2020import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
2121import static org .junit .jupiter .api .Assertions .assertEquals ;
2222import static org .junit .jupiter .api .Assertions .assertNotEquals ;
23+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2324
2425import java .nio .file .Paths ;
2526import java .util .ArrayList ;
@@ -32,27 +33,30 @@ class GitDirectoryEntryTest {
3233
3334 private static final byte [] ZERO_ID = new byte [20 ];
3435
36+ @ Test
37+ void testConstructor () {
38+ assertThrows (NullPointerException .class , () -> new GitDirectoryEntry (null , GitDirectoryEntry .Type .REGULAR , ZERO_ID ));
39+ assertThrows (NullPointerException .class , () -> new GitDirectoryEntry (Paths .get ("hello.txt" ), null , ZERO_ID ));
40+ assertThrows (NullPointerException .class , () -> new GitDirectoryEntry (Paths .get ("hello.txt" ), GitDirectoryEntry .Type .REGULAR , null ));
41+ assertThrows (IllegalArgumentException .class , () -> new GitDirectoryEntry (Paths .get ("/" ), GitDirectoryEntry .Type .REGULAR , ZERO_ID ));
42+ }
43+
3544 /**
3645 * Equality and hash code are based solely on the entry name.
3746 */
3847 @ Test
3948 void testEqualityBasedOnNameOnly () {
4049 final byte [] otherId = new byte [20 ];
4150 Arrays .fill (otherId , (byte ) 0xff );
42-
4351 final GitDirectoryEntry regular = new GitDirectoryEntry (Paths .get ("foo" ), GitDirectoryEntry .Type .REGULAR , ZERO_ID );
4452 final GitDirectoryEntry executable = new GitDirectoryEntry (Paths .get ("foo" ), GitDirectoryEntry .Type .EXECUTABLE , otherId );
45-
4653 // Same name, different type and object id -> equal
4754 assertEquals (regular , executable );
4855 assertEquals (regular .hashCode (), executable .hashCode ());
49-
5056 // Different name -> not equal
5157 assertNotEquals (regular , new GitDirectoryEntry (Paths .get ("bar" ), GitDirectoryEntry .Type .REGULAR , ZERO_ID ));
52-
5358 // Same reference -> equal
5459 assertEquals (regular , regular );
55-
5660 // Not equal to null or unrelated type
5761 assertNotEquals (regular , null );
5862 assertNotEquals (regular , "foo" );
@@ -66,7 +70,6 @@ void testPathConstructorUsesFilename() {
6670 final GitDirectoryEntry fromLabel = new GitDirectoryEntry (Paths .get ("hello.txt" ), GitDirectoryEntry .Type .REGULAR , ZERO_ID );
6771 final GitDirectoryEntry fromRelative = new GitDirectoryEntry (Paths .get ("subdir/hello.txt" ), GitDirectoryEntry .Type .REGULAR , ZERO_ID );
6872 final GitDirectoryEntry fromAbsolute = new GitDirectoryEntry (Paths .get ("hello.txt" ).toAbsolutePath (), GitDirectoryEntry .Type .REGULAR , ZERO_ID );
69-
7073 assertEquals (fromLabel , fromRelative );
7174 assertEquals (fromLabel , fromAbsolute );
7275 assertArrayEquals (fromLabel .toTreeEntryBytes (), fromRelative .toTreeEntryBytes ());
@@ -85,10 +88,8 @@ void testSortOrder() {
8588 final GitDirectoryEntry fooDir = new GitDirectoryEntry (Paths .get ("foo" ), GitDirectoryEntry .Type .DIRECTORY , ZERO_ID );
8689 final GitDirectoryEntry foobar = new GitDirectoryEntry (Paths .get ("foobar" ), GitDirectoryEntry .Type .REGULAR , ZERO_ID );
8790 final GitDirectoryEntry zeta = new GitDirectoryEntry (Paths .get ("zeta.txt" ), GitDirectoryEntry .Type .REGULAR , ZERO_ID );
88-
8991 final List <GitDirectoryEntry > entries = new ArrayList <>(Arrays .asList (zeta , foobar , fooDir , alpha , fooTxt ));
9092 entries .sort (GitDirectoryEntry ::compareTo );
91-
9293 assertEquals (Arrays .asList (alpha , fooTxt , fooDir , foobar , zeta ), entries );
9394 }
9495}
0 commit comments