@@ -79,6 +79,7 @@ public void testParseModifyChange() throws Exception {
7979 assertEquals ("There should be 1 change detected" , 1 , changes .size ());
8080 final GitChange expected = ImmutableGitChange .builder ()
8181 .path ("HelloWorld" )
82+ .addAddedLines (0 )
8283 .build ();
8384 assertEquals ("The change is not as expected" , expected , changes .get (0 ));
8485 }
@@ -203,4 +204,71 @@ public void testParseFilePermissionChange() throws Exception {
203204 }
204205 }
205206 }
207+
208+ @ Test
209+ public void testParseLineChangesAddLine () throws Exception {
210+ try (Repository repository = GitUtils .createNewRepository ()) {
211+ final File helloWorld = GitUtils .addAnEmptyFileAndCommit (repository , "HelloWorld" );
212+ Files .write (helloWorld .toPath (), "line 0\n "
213+ .getBytes (Charset .forName ("UTF-8" )), StandardOpenOption .APPEND );
214+ GitUtils .addAllAndCommit (repository , "add original line" );
215+ GitUtils .createNewBranchAndCheckout (repository , "foo" );
216+ Files .write (helloWorld .toPath (), "line 1 added\n line 2 added\n "
217+ .getBytes (Charset .forName ("UTF-8" )), StandardOpenOption .APPEND );
218+ GitUtils .addAllAndCommit (repository , "add line 1, 2" );
219+ final List <GitChange > changes = DiffParser .parse (
220+ repository .getDirectory ().getParent (), "foo" );
221+ assertEquals ("There should be 1 change detected" , 1 , changes .size ());
222+ final GitChange expected = ImmutableGitChange .builder ()
223+ .path ("HelloWorld" )
224+ .addAddedLines (1 , 2 )
225+ .build ();
226+ assertEquals ("The change is not as expected" , expected , changes .get (0 ));
227+ }
228+ }
229+
230+ @ Test
231+ public void testParseLineChangesRemoveLine () throws Exception {
232+ try (Repository repository = GitUtils .createNewRepository ()) {
233+ final File helloWorld = GitUtils .addAnEmptyFileAndCommit (repository , "HelloWorld" );
234+ Files .write (helloWorld .toPath (), "line 0\n line 1 to be removed\n line 2 to be removed\n "
235+ .getBytes (Charset .forName ("UTF-8" )), StandardOpenOption .APPEND );
236+ GitUtils .addAllAndCommit (repository , "add original three lines" );
237+ GitUtils .createNewBranchAndCheckout (repository , "foo" );
238+ Files .write (helloWorld .toPath (), "line 0\n "
239+ .getBytes (Charset .forName ("UTF-8" )), StandardOpenOption .TRUNCATE_EXISTING );
240+ GitUtils .addAllAndCommit (repository , "remove two lines" );
241+ final List <GitChange > changes = DiffParser .parse (
242+ repository .getDirectory ().getParent (), "foo" );
243+ assertEquals ("There should be 1 change detected" , 1 , changes .size ());
244+ final GitChange expected = ImmutableGitChange .builder ()
245+ .path ("HelloWorld" )
246+ .addDeletedLines (1 , 2 )
247+ .build ();
248+ assertEquals ("The change is not as expected" , expected , changes .get (0 ));
249+ }
250+ }
251+
252+ @ Test
253+ public void testParseLineChangesModifyLine () throws Exception {
254+ try (Repository repository = GitUtils .createNewRepository ()) {
255+ final File helloWorld = GitUtils .addAnEmptyFileAndCommit (repository , "HelloWorld" );
256+ Files .write (helloWorld .toPath (), "line 0\n line 1\n line 2\n "
257+ .getBytes (Charset .forName ("UTF-8" )), StandardOpenOption .APPEND );
258+ GitUtils .addAllAndCommit (repository , "add original three lines" );
259+ GitUtils .createNewBranchAndCheckout (repository , "foo" );
260+ Files .write (helloWorld .toPath (), "line 0\n line 1 changed\n line 2 changed\n "
261+ .getBytes (Charset .forName ("UTF-8" )), StandardOpenOption .TRUNCATE_EXISTING );
262+ GitUtils .addAllAndCommit (repository , "modify two lines" );
263+ final List <GitChange > changes = DiffParser .parse (
264+ repository .getDirectory ().getParent (), "foo" );
265+ assertEquals ("There should be 1 change detected" , 1 , changes .size ());
266+ final GitChange expected = ImmutableGitChange .builder ()
267+ .path ("HelloWorld" )
268+ .addAddedLines (1 , 2 )
269+ .addDeletedLines (1 , 2 )
270+ .build ();
271+ assertEquals ("The change is not as expected" , expected , changes .get (0 ));
272+ }
273+ }
206274}
0 commit comments