Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
(#183) Fixed more checkstyle issues (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
llorllale committed Apr 4, 2018
1 parent b519c8a commit 9ac0840
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 83 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -423,7 +423,7 @@
<linkXRef>false</linkXRef>
<violationSeverity>info</violationSeverity>
<!--
@todo #181 <sourceDirectory> should be '${basedir}/src' in order to include
@todo #183 <sourceDirectory> should be '${basedir}/src' in order to include
test sources in the checks, but there are MANY failures triggered there.
Will need to fix those step by step. Keep going.
-->
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/llorllale/youtrack/api/BadRequestTest.java
Expand Up @@ -21,15 +21,16 @@
import org.llorllale.youtrack.api.mock.http.response.MockBadRequestResponse;

/**
*
* Unit tests for {@link BadRequest}.
* @author George Aristy (george.aristy@gmail.com)
* @since 1.0.0-SNAPSHOT
* @since 1.0.0
* @checkstyle MethodName (500 lines)
*/
public class BadRequestTest {
public final class BadRequestTest {

/**
* Should throw {@link IOException} if server returns error code 400.
*
* @throws Exception unexpected
* @since 1.0.0
*/
@Test(expected = IOException.class)
Expand Down
72 changes: 47 additions & 25 deletions src/test/java/org/llorllale/youtrack/api/BasicFieldTest.java
Expand Up @@ -16,76 +16,98 @@

package org.llorllale.youtrack.api;

// @checkstyle AvoidStaticImport (4 lines)
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import static org.junit.Assert.*;
import org.llorllale.youtrack.api.mock.MockField;
import org.llorllale.youtrack.api.mock.MockProject;

/**
* Unit tests for {@link BasicField}.
*
*
* @author George Aristy (george.aristy@gmail.com)
* @since 0.8.0
* @checkstyle MultipleStringLiterals (500 lines)
* @checkstyle MethodName (500 lines)
*/
public class BasicFieldTest {
public final class BasicFieldTest {
/**
* Must return the given name.
*/
@Test
public void testName() {
final String name = "test";

assertThat(
new BasicField(name, null).name(),
is(name)
new BasicField(name, null).name(),
is(name)
);
}

/**
* Must be equal to itself.
*/
@Test
public void equalsItself() {
final Field field = new BasicField("field", new MockProject());

assertTrue(
field.equals(field)
field.equals(field)
);
}

/**
* Must equal another field with the same name and belonging to the same project.
*/
@Test
public void equalsOtherField() {
assertTrue(
new BasicField(
"field",
new MockProject()
).equals(
new MockField(
"field",
new MockProject()
)
new BasicField(
"field",
new MockProject()
).equals(
new MockField(
"field",
new MockProject()
)
)
);
}

/**
* Cannot be equal to null.
*/
@Test
public void notEqualsNull() {
assertFalse(
new BasicField("field", new MockProject()).equals(null)
new BasicField("field", new MockProject()).equals(null)
);
}

/**
* Cannot be equal to another field with the same name but belong to a different project.
*/
@Test
public void notEqualsDiffProjects() {
assertFalse(
new BasicField(
"field",
new MockProject("p1", "p1", "")
).equals(
new MockField("field", new MockProject("p2", "p2", ""))
)
new BasicField(
"field",
new MockProject("p1", "p1", "")
).equals(
new MockField("field", new MockProject("p2", "p2", ""))
)
);
}

/**
* Cannot be equal to another type.
*/
@Test
public void notEqualsObject() {
assertFalse(
new BasicField("field", new MockProject()).equals(new Object())
new BasicField("field", new MockProject()).equals(new Object())
);
}
}
}
59 changes: 34 additions & 25 deletions src/test/java/org/llorllale/youtrack/api/DefaultCommentsTest.java
Expand Up @@ -16,8 +16,10 @@

package org.llorllale.youtrack.api;

// @checkstyle AvoidStaticImport (2 lines)
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.llorllale.youtrack.api.mock.MockIssue;
import org.llorllale.youtrack.api.mock.MockProject;
Expand All @@ -29,34 +31,41 @@
* Unit tests for {@link DefaultComments}.
* @author George Aristy (george.aristy@gmail.com)
* @since 0.4.0
* @checkstyle MultipleStringLiterals (500 lines)
*/
public class DefaultCommentsTest {
public final class DefaultCommentsTest {
private static final String COMMENTS
= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
+ "<comments>\n"
// @checkstyle LineLength (1 line)
+ " <comment id=\"42-306\" author=\"root\" issueId=\"HBR-63\" deleted=\"false\" text=\"comment 1!\" shownForIssueAuthor=\"false\"\n"
+ " created=\"1267030230127\">\n"
+ " <replies/>\n"
+ " </comment>\n"
// @checkstyle LineLength (1 line)
+ " <comment id=\"42-307\" author=\"root\" issueId=\"HBR-63\" deleted=\"false\" text=\"comment 2?\" shownForIssueAuthor=\"false\"\n"
+ " created=\"1267030238721\" updated=\"1267030230127\">\n"
+ " <replies/>\n"
+ " </comment>\n"
+ "</comments>";

/**
* Stream returns all comments.
* @throws Exception unexpected
*/
@Test
public void testStream() throws Exception {
assertThat(
new DefaultComments(
new MockSession(),
new MockIssue(
new MockProject("", "", "")
),
new MockHttpClient(
new MockOkResponse(COMMENTS)
)
).stream().count(),
is(2L)
new DefaultComments(
new MockSession(),
new MockIssue(
new MockProject("", "", "")
),
new MockHttpClient(
new MockOkResponse(COMMENTS)
)
).stream().count(),
is(2L)
);
}

private static final String COMMENTS =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<comments>\n" +
" <comment id=\"42-306\" author=\"root\" issueId=\"HBR-63\" deleted=\"false\" text=\"comment 1!\" shownForIssueAuthor=\"false\"\n" +
" created=\"1267030230127\">\n" +
" <replies/>\n" +
" </comment>\n" +
" <comment id=\"42-307\" author=\"root\" issueId=\"HBR-63\" deleted=\"false\" text=\"comment 2?\" shownForIssueAuthor=\"false\"\n" +
" created=\"1267030238721\" updated=\"1267030230127\">\n" +
" <replies/>\n" +
" </comment>\n" +
"</comments>";
}
}
22 changes: 17 additions & 5 deletions src/test/java/org/llorllale/youtrack/api/DefaultFieldsIT.java
Expand Up @@ -16,36 +16,48 @@

package org.llorllale.youtrack.api;

// @checkstyle AvoidStaticImport (3 lines)
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertThat;

import org.junit.BeforeClass;
import org.junit.Test;
import org.llorllale.youtrack.api.session.PermanentToken;
import org.llorllale.youtrack.api.session.Session;

/**
* Integration tests for {@link DefaultFields}.
*
* @author George Aristy (george.aristy@gmail.com)
* @since 0.8.0
* @checkstyle AbbreviationAsWordInName (2 lines)
*/
public class DefaultFieldsIT {
public final class DefaultFieldsIT {
private static Session session;
private static Project project;

/**
* Setup.
* @throws Exception unexpected
*/
@BeforeClass
public static void setup() throws Exception {
final IntegrationTestsConfig config = new IntegrationTestsConfig();
session = new PermanentToken(config.youtrackUrl(), config.youtrackUserToken()).login();
session = new PermanentToken(
config.youtrackUrl(), config.youtrackUserToken()
).login();
project = new DefaultYouTrack(session).projects().stream().findAny().get();
}

/**
* Stream returns the fields pre-configured for the project.
* @throws Exception unexpected
*/
@Test
public void testStream() throws Exception {
assertThat(
new DefaultFields(session, project).stream().count(),
is(greaterThan(0L))
new DefaultFields(session, project).stream().count(),
is(greaterThan(0L))
);
}
}
47 changes: 24 additions & 23 deletions src/test/java/org/llorllale/youtrack/api/DefaultFieldsTest.java
Expand Up @@ -16,10 +16,12 @@

package org.llorllale.youtrack.api;

import java.util.stream.Collectors;
// @checkstyle AvoidStaticImport (3 lines)
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;

import java.util.stream.Collectors;
import org.junit.Test;
import org.llorllale.youtrack.api.mock.MockProject;
import org.llorllale.youtrack.api.mock.http.MockHttpClient;
Expand All @@ -28,47 +30,46 @@

/**
* Unit tests for {@link DefaultFields}.
*
* @author George Aristy (george.aristy@gmail.com)
* @since 1.0.0
*/
public class DefaultFieldsTest {
public final class DefaultFieldsTest {
/**
* {@link DefaultFields#project()} must return the same project.
*
* @since 1.0.0
*/
@Test
public void project() {
final Project project = new MockProject();
assertThat(
new DefaultFields(null, project).project(),
is(project)
new DefaultFields(null, project).project(),
is(project)
);
}

/**
* {@link DefaultFields#stream()} must return all fields returned by the server.
*
* @throws Exception
* {@link DefaultFields#stream()} must return all fields returned by the
* server.
* @throws Exception unexpected
* @since 1.0.0
*/
@Test
public void stream() throws Exception {
assertThat(
new DefaultFields(
new MockSession(),
new MockProject(),
new MockHttpClient(
new MockOkResponse(
"<projectCustomFieldRefs>\n" +
" <projectCustomField name=\"Pyatiletka\" url=\"http://youtrack.jetbrains.net/rest/admin/project/CMN/customfield/Plan\"/>\n" +
" <projectCustomField name=\"Region\" url=\"http://youtrack.jetbrains.net/rest/admin/project/CMN/customfield/Region\"/>\n" +
"</projectCustomFieldRefs>"
)
)
).stream().map(ProjectField::name).collect(Collectors.toList()),
containsInAnyOrder("Pyatiletka", "Region")
new DefaultFields(
new MockSession(),
new MockProject(),
new MockHttpClient(
new MockOkResponse(
"<projectCustomFieldRefs>\n"
// @checkstyle LineLength (2 lines)
+ " <projectCustomField name=\"Pyatiletka\" url=\"http://youtrack.jetbrains.net/rest/admin/project/CMN/customfield/Plan\"/>\n"
+ " <projectCustomField name=\"Region\" url=\"http://youtrack.jetbrains.net/rest/admin/project/CMN/customfield/Region\"/>\n"
+ "</projectCustomFieldRefs>"
)
)
).stream().map(ProjectField::name).collect(Collectors.toList()),
containsInAnyOrder("Pyatiletka", "Region")
);
}
}
}

2 comments on commit 9ac0840

@0pdd
Copy link

@0pdd 0pdd commented on 9ac0840 Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 181-ffcedfbe disappeared from pom.xml, that's why I closed #183. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 9ac0840 Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 183-ffcedfbe discovered in pom.xml and submitted as #186. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.