Skip to content

Commit

Permalink
API version verification and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
murfffi committed Dec 21, 2020
1 parent 86ea58e commit a10d36d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
42 changes: 39 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>zebra4j</groupId>
<artifactId>zebra4j</artifactId>
<version>0.3</version>
<version>0.4-SNAPSHOT</version>

<name>zebra4j</name>
<url>https://github.com/murfffi/zebra4j</url>
Expand Down Expand Up @@ -71,7 +71,7 @@
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<plugin>
Expand Down Expand Up @@ -160,12 +160,48 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.revapi</groupId>
<artifactId>revapi-maven-plugin</artifactId>
<version>0.12.2</version>
<dependencies>
<dependency>
<groupId>org.revapi</groupId>
<artifactId>revapi-java</artifactId>
<version>0.22.1</version>
</dependency>
</dependencies>
<configuration>
<analysisConfiguration>
<!-- Documented at https://revapi.org/revapi-basic-features/semver-ignore.html -->
<revapi.semver.ignore>
<enabled>true</enabled>
<versionIncreaseAllows>
<major>breaking</major>
<!-- Breaking changes at minor version, allowed while major is 0 -->
<minor>breaking</minor>
<patch>nonBreaking</patch>
</versionIncreaseAllows>
<passThroughDifferences>
<item>java.class.nonPublicPartOfAPI</item>
</passThroughDifferences>
</revapi.semver.ignore>
</analysisConfiguration>
</configuration>
<executions>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<scm>
<url>https://github.com/murfffi/zebra4j</url>
<connection>scm:git:ssh://[email protected]/murfffi/zebra4j.git</connection>
<tag>v0.3</tag>
</scm>
<distributionManagement>
<repository>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/zebra4j/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public String toSentence() {
return about.questionSentencePart() + " " + towards.description() + "?";
}

/**
* Answers this question about the given solution, if applicable
*
* @param solution required
* @return the answer, present if this {@link #appliesTo} solution
*/
public Optional<Attribute> answer(PuzzleSolution solution) {
return solution.findPerson(towards).flatMap(person -> Optional.ofNullable(person.findAttribute(about)));
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/zebra4j/QuestionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
package zebra4j;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.Random;

import org.junit.Test;
Expand All @@ -43,4 +45,19 @@ public void testGenerate_Stable() {
assertEquals(question, Question.generate(solution.getAttributeSets(), new Random(1)));
}

@Test
public void testAnswer() {
PuzzleSolution solution = PuzzleGeneratorTest.simpleSolutionWithCriminal();
Question question = Question.NAME_OF_CRIMINAL;
assertEquals(PersonName.ГЕОРГИ, question.answer(solution).get());
}

@Test
public void testAnswer_DoesNotApply() {
PuzzleSolution solution = PuzzleGeneratorTest.simpleSolutionWithCriminal();
Question question = new Question(Criminal.YES,
new BasicAttributeType(Collections.singleton("test"), "questionSentencePart"));
assertFalse(question.answer(solution).isPresent());
}

}

0 comments on commit a10d36d

Please sign in to comment.