-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#53 - updated tests and some clean up
Note: looks like we need to think twice about the current code structure as it's moving to bad place;)
- Loading branch information
Showing
25 changed files
with
128 additions
and
136 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
3 changes: 1 addition & 2 deletions
3
src/main/java/org/yu55/yagga/core/annotate/model/AnnotateResponseLine.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
8 changes: 2 additions & 6 deletions
8
src/main/java/org/yu55/yagga/handler/generic/Repositories.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
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
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
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
42 changes: 25 additions & 17 deletions
42
...a/org/yu55/yagga/handler/mercurial/command/annotate/MercurialAnnotateResponseFactory.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 |
---|---|---|
@@ -1,41 +1,49 @@ | ||
package org.yu55.yagga.handler.mercurial.command.annotate; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.yu55.yagga.core.annotate.model.AnnotateResponse; | ||
import org.yu55.yagga.core.annotate.model.AnnotateResponseLine; | ||
import org.yu55.yagga.handler.generic.command.CommandOutput; | ||
import org.yu55.yagga.handler.generic.command.CommandOutputLine; | ||
|
||
import java.util.List; | ||
|
||
public class MercurialAnnotateResponseFactory { | ||
|
||
private static final String LINE_PATTERN = | ||
"(\\w+)\\s+(\\w{12})\\s+(\\w{3}\\s+\\w{3}\\s+\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+\\d{4}\\s+[\\+\\-]?\\d{4})" + | ||
":(\\d+):\\s+(.*)"; | ||
|
||
public static AnnotateResponse factorizeAnnotateResponse(CommandOutput output) { | ||
List<CommandOutputLine> outputLines = output.getOutputLines(); | ||
|
||
StringBuilder annotationsStringBuilder = new StringBuilder(); | ||
StringBuilder fileContentStringBuilder = new StringBuilder(); | ||
AnnotateResponse response = new AnnotateResponse(); | ||
|
||
for (CommandOutputLine outputLine : outputLines) { | ||
String annotatedLine = outputLine.getLine(); | ||
if (output.getExitValue() == 0) { | ||
generateSuccessfulContent(annotationsStringBuilder, fileContentStringBuilder, annotatedLine); | ||
generateSuccessfulContent(response, annotatedLine); | ||
} else { | ||
generateFailureContent(annotationsStringBuilder, annotatedLine); | ||
generateUnsuccessfulContent(response, annotatedLine); | ||
} | ||
} | ||
|
||
return new AnnotateResponse(annotationsStringBuilder.toString(), fileContentStringBuilder.toString()); | ||
return response; | ||
} | ||
|
||
private static void generateSuccessfulContent(StringBuilder annotationsStringBuilder, | ||
StringBuilder fileContentStringBuilder, String annotatedLine) { | ||
int splitIndex = StringUtils.ordinalIndexOf(annotatedLine,":", 4); | ||
annotationsStringBuilder.append(annotatedLine.substring(0, splitIndex + 1)).append("\n"); | ||
fileContentStringBuilder.append(annotatedLine.substring(splitIndex + 1)).append("\n"); | ||
private static void generateSuccessfulContent(AnnotateResponse response, String annotatedLine) { | ||
Matcher matcher = Pattern.compile(LINE_PATTERN).matcher(annotatedLine); | ||
if (matcher.matches()) { | ||
AnnotateResponseLine annotationResponseLine = new AnnotateResponseLine( | ||
matcher.group(2).trim(), | ||
matcher.group(1).trim(), matcher.group(3).trim(), | ||
Integer.parseInt(matcher.group(4).trim()), | ||
matcher.group(5)); | ||
response.addAnnotationResponseLine(annotationResponseLine); | ||
} | ||
} | ||
|
||
private static void generateFailureContent(StringBuilder annotationsStringBuilder, String annotatedLine) { | ||
annotationsStringBuilder.append(annotatedLine).append("\n"); | ||
private static void generateUnsuccessfulContent(AnnotateResponse response, String line) { | ||
response.addAnnotationResponseLine(new AnnotateResponseLine(line)); | ||
} | ||
|
||
} |
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
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
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
20 changes: 9 additions & 11 deletions
20
...test/java/org/yu55/yagga/handler/git/command/annotate/GitAnnotateResponseFactoryTest.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 |
---|---|---|
@@ -1,34 +1,32 @@ | ||
package org.yu55.yagga.handler.git.command.annotate; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.yu55.yagga.handler.git.command.annotate.GitAnnotateResponseFactory.factorizeAnnotateResponse; | ||
|
||
import org.junit.Test; | ||
import org.yu55.yagga.core.annotate.model.AnnotateResponse; | ||
import org.yu55.yagga.core.annotate.model.AnnotateResponseLine; | ||
import org.yu55.yagga.core.annotate.model.AnnotateResponseLineAssert; | ||
import org.yu55.yagga.handler.generic.command.CommandOutput; | ||
import org.yu55.yagga.handler.generic.command.CommandOutputLine; | ||
|
||
public class GitAnnotateResponseFactoryTest { | ||
|
||
@Test | ||
public void testFactorizeAnnotateResponse2() throws Exception { | ||
public void testFactorizeAnnotateResponse() throws Exception { | ||
// given | ||
CommandOutput annotateCommandOutput = new CommandOutput(); | ||
annotateCommandOutput.addOutputLine(new CommandOutputLine( | ||
"af7545c8\t( Mikołaj Fejzer 2015-11-21 20:07:59 +0100 1)package org.yu55.yagga.handler.api.command.grep;" | ||
"af7545c8\t( Mikołaj 2015-11-21 20:07:59 +0100 1)package org.yu55.yagga.handler.api.command.grep;" | ||
)); | ||
|
||
// when | ||
AnnotateResponse annotateResponse = factorizeAnnotateResponse(annotateCommandOutput); | ||
|
||
// then | ||
// TODO: change assertions to custom ones (generated)! | ||
AnnotateResponseLine annotateResponseLine = annotateResponse.getAnnotationResponseLines().get(0); | ||
assertThat(annotateResponseLine.getCommitId()).isEqualTo("af7545c8"); | ||
assertThat(annotateResponseLine.getAuthor()).isEqualTo("Mikołaj Fejzer"); | ||
assertThat(annotateResponseLine.getCommitDate()).isEqualTo("2015-11-21 20:07:59 +0100"); | ||
assertThat(annotateResponseLine.getLineNumber()).isEqualTo(1); | ||
assertThat(annotateResponseLine.getLine()).isEqualTo("package org.yu55.yagga.handler.api.command.grep;"); | ||
AnnotateResponseLineAssert.assertThat(annotateResponse.getAnnotationResponseLines().get(0)) | ||
.hasCommitId("af7545c8") | ||
.hasAuthor("Mikołaj") | ||
.hasCommitDate("2015-11-21 20:07:59 +0100") | ||
.hasLineNumber(1) | ||
.hasLine("package org.yu55.yagga.handler.api.command.grep;"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/java/org/yu55/yagga/handler/git/command/grep/GitGrepResponseLineFactoryTest.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
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
Oops, something went wrong.