forked from perforce/sonar-scm-perforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARSCPER-4 Do not fail when a file has no blame information
- Loading branch information
Showing
4 changed files
with
165 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 0 additions & 101 deletions
101
src/main/java/org/sonar/plugins/scm/perforce/PerforceBlameResult.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/test/java/org/sonar/plugins/scm/perforce/PerforceBlameCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* SonarQube :: Plugins :: SCM :: Perforce | ||
* Copyright (C) 2014 SonarSource | ||
* [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package org.sonar.plugins.scm.perforce; | ||
|
||
import com.perforce.p4java.core.file.FileSpecOpStatus; | ||
import com.perforce.p4java.core.file.IFileAnnotation; | ||
import com.perforce.p4java.core.file.IFileRevisionData; | ||
import com.perforce.p4java.core.file.IFileSpec; | ||
import com.perforce.p4java.option.server.GetFileAnnotationsOptions; | ||
import com.perforce.p4java.option.server.GetRevisionHistoryOptions; | ||
import com.perforce.p4java.server.IOptionsServer; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.Test; | ||
import org.sonar.api.batch.fs.InputFile; | ||
import org.sonar.api.batch.scm.BlameCommand.BlameOutput; | ||
import org.sonar.api.batch.scm.BlameLine; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Matchers.anyList; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyZeroInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class PerforceBlameCommandTest { | ||
|
||
@Test | ||
public void testBlameUnSubmittedFile() throws Exception { | ||
BlameOutput blameOutput = mock(BlameOutput.class); | ||
IOptionsServer server = mock(IOptionsServer.class); | ||
PerforceBlameCommand command = new PerforceBlameCommand(mock(PerforceConfiguration.class)); | ||
|
||
IFileAnnotation annotation = mock(IFileAnnotation.class); | ||
when(annotation.getDepotPath()).thenReturn(null); | ||
|
||
when(server.getFileAnnotations(anyList(), any(GetFileAnnotationsOptions.class))).thenReturn(Arrays.asList(annotation)); | ||
|
||
command.blame(mock(InputFile.class), server, blameOutput); | ||
|
||
verifyZeroInteractions(blameOutput); | ||
} | ||
|
||
@Test | ||
public void testBlameSubmittedFile() throws Exception { | ||
BlameOutput blameOutput = mock(BlameOutput.class); | ||
IOptionsServer server = mock(IOptionsServer.class); | ||
PerforceBlameCommand command = new PerforceBlameCommand(mock(PerforceConfiguration.class)); | ||
|
||
IFileAnnotation annotation = mock(IFileAnnotation.class); | ||
when(annotation.getDepotPath()).thenReturn("foo/bar/src/Foo.java"); | ||
when(annotation.getLower()).thenReturn(3); | ||
|
||
when(server.getFileAnnotations(anyList(), any(GetFileAnnotationsOptions.class))).thenReturn(Arrays.asList(annotation)); | ||
|
||
Map<IFileSpec, List<IFileRevisionData>> result = new HashMap<>(); | ||
IFileSpec fileSpecResult = mock(IFileSpec.class); | ||
when(fileSpecResult.getOpStatus()).thenReturn(FileSpecOpStatus.VALID); | ||
IFileRevisionData revision3 = mock(IFileRevisionData.class); | ||
when(revision3.getChangelistId()).thenReturn(3); | ||
Date date = new Date(); | ||
when(revision3.getDate()).thenReturn(date); | ||
when(revision3.getUserName()).thenReturn("jhenry"); | ||
result.put(fileSpecResult, Arrays.asList(revision3)); | ||
|
||
when(server.getRevisionHistory(anyList(), any(GetRevisionHistoryOptions.class))).thenReturn(result); | ||
|
||
InputFile inputFile = mock(InputFile.class); | ||
command.blame(inputFile, server, blameOutput); | ||
|
||
verify(blameOutput).blameResult(inputFile, Arrays.asList(new BlameLine().revision("3").date(date).author("jhenry"))); | ||
} | ||
|
||
} |