Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,30 @@
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.joshka</groupId>
<artifactId>junit-json-params</artifactId>
<version>5.10.2-r0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<testResources>
<testResource>
<directory>resources</directory>
</testResource>
</testResources>
<resources>
<resource>
<directory>../resources</directory>
<directory>resources</directory>
</resource>
</resources>
<plugins>
Expand Down Expand Up @@ -234,6 +251,12 @@
<exclude>
dependencies:org.cactoos:cactoos:jar:0.56.1:compile
</exclude>
<exclude>
dependencies:jakarta.json:jakarta.json-api:jar:2.1.3:provided
</exclude>
<exclude>
dependencies:org.junit.jupiter:junit-jupiter-params:jar:5.10.3:test
</exclude>
</excludes>
</configuration>
<executions>
Expand Down
23 changes: 23 additions & 0 deletions src/io/github/artemget/prbot/domain/pr/AccJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import io.github.artemget.prbot.config.EJsonStr;
import io.github.artemget.prbot.config.EntryException;
import java.util.Objects;
import javax.json.JsonObject;

/**
Expand Down Expand Up @@ -83,4 +84,26 @@ public String username() throws EmptyArgumentException {
);
}
}

// @todo #20:45min Intellij generates equals and hashcode
// not the elegant way. Lets add custom template for equals.
//@checkstyle NeedBracesCheck (20 lines)
//@checkstyle HiddenFieldCheck (10 lines)
@SuppressWarnings({
"PMD.ControlStatementBraces",
"PMD.OnlyOneReturn",
"AnnotationUseStyleCheck"
})
@Override
public boolean equals(final Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
final AccJson json = (AccJson) object;
return Objects.equals(this.json, json.json);
}

@Override
public int hashCode() {
return Objects.hash(this.json);
}
}
21 changes: 21 additions & 0 deletions src/io/github/artemget/prbot/domain/pr/BrJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import io.github.artemget.prbot.config.EJsonStr;
import io.github.artemget.prbot.config.EntryException;
import java.util.Objects;
import javax.json.JsonObject;

/**
Expand Down Expand Up @@ -83,4 +84,24 @@ public String link() throws EmptyArgumentException {
);
}
}

//@checkstyle NeedBracesCheck (20 lines)
//@checkstyle HiddenFieldCheck (10 lines)
@SuppressWarnings({
"PMD.ControlStatementBraces",
"PMD.OnlyOneReturn",
"AnnotationUseStyleCheck"
})
@Override
public boolean equals(final Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
final BrJson json = (BrJson) object;
return Objects.equals(this.json, json.json);
}

@Override
public int hashCode() {
return Objects.hash(this.json);
}
}
7 changes: 4 additions & 3 deletions src/io/github/artemget/prbot/domain/pr/PrJsonStrict.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.github.artemget.prbot.config.EntryException;
import java.io.StringReader;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import javax.json.Json;
import javax.json.JsonArray;
Expand Down Expand Up @@ -111,7 +112,7 @@ public String link() throws EmptyArgumentException {
public Status status() throws EmptyArgumentException {
final String status;
try {
status = new EJsonStr(this.json, "link").value();
status = new EJsonStr(this.json, "status").value();
} catch (final EntryException exception) {
throw new EmptyArgumentException(
String.format(
Expand All @@ -122,7 +123,7 @@ public Status status() throws EmptyArgumentException {
);
}
try {
return PullRequest.Status.valueOf(status);
return PullRequest.Status.valueOf(status.toUpperCase(Locale.getDefault()));
} catch (final IllegalArgumentException exception) {
throw new EmptyArgumentException(
String.format(
Expand Down Expand Up @@ -152,7 +153,7 @@ public Account from() throws EmptyArgumentException {

@Override
public List<Account> assigners() throws EmptyArgumentException {
return this.accounts("assigners");
return this.accounts("assignees");
}

@Override
Expand Down
5 changes: 0 additions & 5 deletions src/io/github/artemget/prbot/domain/pr/ProjJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
* Git project from json source.
*
* @since 0.0.1
* @todo #20:45 {@link io.github.artemget.prbot.domain.pr.ProjJson}
* and {@link io.github.artemget.prbot.domain.pr.PrJsonStrict}
* is not covered by tests. Lets cover it's methods. I suggest using
* <a href="https://github.com/joshka/junit-json-params">joshka/junit-json-params</a>
* with it's @JsonSource annotation, test sources is placed under resources dir.
*/
public final class ProjJson implements Project {
/**
Expand Down
171 changes: 171 additions & 0 deletions test/io/github/artemget/prbot/domain/pr/PrJsonStrictTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* MIT License
*
* Copyright (c) 2024-2025. Artem Getmanskii
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.artemget.prbot.domain.pr;

import io.github.artemget.prbot.config.EntryException;
import jakarta.json.JsonObject;
import java.util.List;
import javax.json.Json;
import net.joshka.junit.json.params.JsonFileSource;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;

/**
* Test case for {@link io.github.artemget.prbot.domain.pr.PrJsonStrict}
*
* @since 0.0.1
*/
class PrJsonStrictTest {

@Test
void throwsAtWrongJsonFormatAtCreation() {
Assertions.assertThrows(
EntryException.class,
() -> new PrJsonStrict("not json"),
"Not thrown at wrong json format"
);
}

@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsIdentity(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong identity",
new PrJsonStrict(object.toString()).identity(),
Matchers.equalTo("10")
);
}

@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsLink(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong link",
new PrJsonStrict(object.toString()).link(),
Matchers.equalTo("https://github.com/ArtemGet/prbot/pull/10")
);
}

@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsStatus(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong status",
new PrJsonStrict(object.toString()).status(),
Matchers.equalTo(PullRequest.Status.OPENED)
);
}

@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsFrom(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong from account",
new PrJsonStrict(object.toString()).from(),
Matchers.equalTo(
new AccJson(
Json.createObjectBuilder()
.add("id", "123")
.add("username", "ArtemGet")
.build()
)
)
);
}

@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsAssigners(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong assigner account",
new PrJsonStrict(object.toString()).assigners(),
Matchers.equalTo(
List.of(
new AccJson(
Json.createObjectBuilder()
.add("id", "123")
.add("username", "ArtemGet")
.build()
)
)
)
);
}

@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsReviewers(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong reviewer account",
new PrJsonStrict(object.toString()).reviewers(),
Matchers.equalTo(
List.of(
new AccJson(
Json.createObjectBuilder()
.add("id", "321")
.add("username", "ReviewerUser")
.build()
)
)
)
);
}

@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsBranchFrom(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong source branch",
new PrJsonStrict(object.toString()).branchFrom(),
Matchers.equalTo(
new BrJson(
Json.createObjectBuilder()
.add("name", "Eh/#6")
.add("link", "https://github.com/ArtemGet/prbot/tree/eh/%236")
.build()
)
)
);
}
@ParameterizedTest
@JsonFileSource(resources = "/PrStrict.json")
void returnsBranchTo(JsonObject object) throws EntryException, EmptyArgumentException {
MatcherAssert.assertThat(
"Wrong target branch",
new PrJsonStrict(object.toString()).branchTo(),
Matchers.equalTo(
new BrJson(
Json.createObjectBuilder()
.add("name", "main")
.add("link", "https://github.com/ArtemGet/prbot/tree/main")
.build()
)
)
);
}
}