Skip to content

Commit

Permalink
Add SubmissionResultParser test case for failed checkstyle
Browse files Browse the repository at this point in the history
Also cleaned checkstyle violations from tests and parser
  • Loading branch information
cxcorp committed Dec 1, 2016
1 parent 7a94b20 commit ff3e6fd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public SubmissionResult.Status deserialize(
}
}

private static class ValidationErrorInstanceCreator implements InstanceCreator<ValidationError> {
private static class ValidationErrorInstanceCreator
implements InstanceCreator<ValidationError> {
@Override
public ValidationError createInstance(Type type) {
return new ValidationErrorImpl();
Expand All @@ -114,14 +115,15 @@ public ValidationError createInstance(Type type) {
private static class FileDeserializer implements JsonDeserializer<File> {
@Override
public File deserialize(
JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext)
JsonElement jsonElement, Type type, JsonDeserializationContext context)
throws JsonParseException {
String filePath = jsonElement.getAsString();
return new File(filePath);
}
}

private static class ImmutableListJsonDeserializer implements JsonDeserializer<ImmutableList<?>> {
private static class ImmutableListJsonDeserializer
implements JsonDeserializer<ImmutableList<?>> {
@Override
public ImmutableList<?> deserialize(
JsonElement json, Type type, JsonDeserializationContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
import fi.helsinki.cs.tmc.core.communication.serialization.SubmissionResultParser;
import fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult;
import fi.helsinki.cs.tmc.core.utils.TestUtils;
import fi.helsinki.cs.tmc.langs.abstraction.Strategy;
import fi.helsinki.cs.tmc.langs.abstraction.ValidationError;
import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult;
import fi.helsinki.cs.tmc.langs.domain.TestResult;
import fi.helsinki.cs.tmc.testrunner.TestCase;

import com.google.common.collect.ImmutableList;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.net.URI;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class SubmissionResultParserTest {


private SubmissionResultParser parser;

@Before
Expand All @@ -39,7 +37,7 @@ public void parsesNonLangsTestResult() throws Exception {
TestResult test = tests.get(0);
assertThat(test.getException()).isInstanceOf(ImmutableList.class);
assertThat(test.getException().size()).isEqualTo(27);
for (String str : test.getException()){
for (String str : test.getException()) {
assertThat(str).isInstanceOf(String.class);
}
}
Expand All @@ -54,8 +52,30 @@ public void parsesLangsTestResult() throws Exception {
TestResult test = tests.get(0);
assertThat(test.getDetailedMessage()).isInstanceOf(ImmutableList.class);
assertThat(test.getDetailedMessage().size()).isEqualTo(26);
for (String str : test.getDetailedMessage()){
for (String str : test.getDetailedMessage()) {
assertThat(str).isInstanceOf(String.class);
}
}

@Test
public void parsesTestResultsWithFailedCheckstyle() throws IOException {
String json = TestUtils.readJsonFile(this.getClass(), "checkstyleFailed.json");
SubmissionResult submissionResult = parser.parseFromJson(json);
assertThat(submissionResult).isNotNull();

ValidationResult result = submissionResult.getValidationResult();
assertThat(result.getStrategy()).isEqualTo(Strategy.FAIL);

Map<File, List<ValidationError>> filesErrors = result.getValidationErrors();
assertThat(filesErrors).hasSize(1);

List<ValidationError> errors = filesErrors.get(new File("error/errorMessages.java"));
assertThat(errors).hasSize(73);

for (ValidationError error : errors) {
assertThat(error).isNotNull();
assertThat(error.getMessage()).isNotNull();
assertThat(error.getSourceName()).isNotNull();
}
}
}
4 changes: 2 additions & 2 deletions src/test/resources/json/checkstyleFailed.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
"strategy": "FAIL",
"validationErrors":
{
"eRror/errorMessages.java":
"error/errorMessages.java":
[
{
"column": 0,
Expand Down Expand Up @@ -725,4 +725,4 @@
"requests_review": false,
"submitted_at": "2015-06-04T13:34:58.155+03:00"

}
}

0 comments on commit ff3e6fd

Please sign in to comment.