Skip to content

Commit

Permalink
comment assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
RoRoche committed May 2, 2020
1 parent 875fa22 commit b0b47f1
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ import org.gradle.api.Task

import static org.junit.jupiter.api.Assertions.assertNotNull

/**
* Assertion that checks a task is properly created.
*/
class CreateTaskAssertion implements Assertion {

private final Project project;
private final String taskName;
private final Class<? extends Task> taskClass;

/**
* Primary constructor.
*
* @param project The Project to be configured.
* @param taskName The name of the task to create.
* @param taskClass The Class of the task to create.
*/
CreateTaskAssertion(
final Project project,
final String taskName,
Expand All @@ -23,6 +33,10 @@ class CreateTaskAssertion implements Assertion {
this.taskClass = taskClass
}

/**
* Check the assertion.
* @throws Exception
*/
@Override
void check() throws Exception {
final Task task = project.task(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import com.github.roroche.BuildClassDiagramTask
import com.pragmaticobjects.oo.tests.Assertion
import org.gradle.api.Project

/**
* Assertion that checks that BuildClassDiagramTask is properly executed.
*/
class ExecuteBuildClassDiagramTaskAssertion implements Assertion {

private final Project project
private final File output
private final Assertion delegate

/**
* Primary constructor.
*
* @param project The Project to be configured.
* @param output The output file of the task.
* @param delegate The delegate assertion.
*/
ExecuteBuildClassDiagramTaskAssertion(
final Project project,
final File output,
Expand All @@ -19,6 +29,10 @@ class ExecuteBuildClassDiagramTaskAssertion implements Assertion {
this.delegate = delegate
}

/**
* Check the assertion.
* @throws Exception
*/
@Override
void check() throws Exception {
final BuildClassDiagramTask task = project.task(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ import org.gradle.api.Task

import static org.junit.jupiter.api.Assertions.assertNotNull

/**
* Assertion that checks a task is found in project.
*/
class FindTaskAssertion implements Assertion {

private final Project project;
private final String taskName;

/**
* Primary constructor.
*
* @param project The Project to be configured.
* @param taskName The name of the task to find.
*/
FindTaskAssertion(
final Project project,
final String taskName
Expand All @@ -19,6 +28,10 @@ class FindTaskAssertion implements Assertion {
this.taskName = taskName
}

/**
* Check the assertion.
* @throws Exception
*/
@Override
void check() throws Exception {
final Task task = project.tasks.findByName(taskName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@ import com.pragmaticobjects.oo.tests.Assertion

import static org.assertj.core.api.Assertions.assertThat

/**
* Groovy specific assertion to check that a file has a specific content.
*/
class GrvFileHasContentAssertion implements Assertion {
private final File file;
private final String expectedContent;

GrvFileHasContentAssertion(File file, String expectedContent) {
/**
* Primary constructor.
*
* @param file The file to check content.
* @param expectedContent The expected content.
*/
GrvFileHasContentAssertion(
final File file,
final String expectedContent
) {
this.file = file
this.expectedContent = expectedContent
}

/**
* Check the assertion.
* @throws Exception
*/
@Override
void check() throws Exception {
assertThat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import org.gradle.api.Project

import static org.junit.jupiter.api.Assertions.assertTrue

/**
* Assertion that checks a plugin is properly applied to a project.
*/
class ProjectWithPluginAssertion implements Assertion {

private final Project project;
private final String pluginId;
private final List<FindTaskAssertion> taskAssertions;

/**
* Primary constructor.
*
* @param project The Project to be configured.
* @param pluginId The ID of the plugin to apply.
* @param taskAssertions The tasks to be found.
*/
ProjectWithPluginAssertion(
final Project project,
final String pluginId,
Expand All @@ -21,6 +31,10 @@ class ProjectWithPluginAssertion implements Assertion {
this.taskAssertions = taskAssertions
}

/**
* Check the assertion.
* @throws Exception
*/
@Override
void check() throws Exception {
project.pluginManager.apply(pluginId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import com.github.roroche.classes.Classes
import com.pragmaticobjects.oo.tests.Assertion
import org.assertj.core.api.Assertions.assertThat

/**
* Assertion that checks that [Classes] contains given [Class].
*
* @property classes The [Classes] to check.
* @property expectedClasses The expected [Class].
*/
class ClsContainsExactlyAssertion(
private val classes: Classes,
private val expectedClasses: List<Class<out Any>>
) : Assertion {
/**
* Check the assertion.
*/
override fun check() {
assertThat(
classes.list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import com.github.roroche.classes.Classes
import com.pragmaticobjects.oo.tests.Assertion
import org.assertj.core.api.Assertions.assertThat

/**
* Assertion that checks that [Classes] is empty.
*
* @property classes The [Classes] to check.
*/
class ClsIsEmptyAssertion(
private val classes: Classes
) : Assertion {
/**
* Check the assertion.
*/
override fun check() {
assertThat(
classes.list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import com.github.roroche.diagrams.Diagram
import com.pragmaticobjects.oo.tests.Assertion
import org.assertj.core.api.Assertions.assertThat

/**
* Assertion that checks that a diagram has a specific content.
*
* @property diagram The [Diagram] to check.
* @property expectedContent The expected content.
*/
class DiagramHasContentAssertion(
private val diagram: Diagram,
private val expectedContent: String
) : Assertion {
/**
* Check the assertion.
*/
override fun check() {
assertThat(
diagram.content()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@ import com.pragmaticobjects.oo.tests.Assertion
import org.assertj.core.api.Assertions.assertThat
import java.io.File

/**
* Kotlin specific assertion that checks that a file has a specific content.
*
* @property file The [File] to check.
* @property expectedContent The expected content.
*/
class KtFileHasContentAssertion(
private val file: File,
private val expectedContent: String
) : Assertion {

/**
* Secondary constructor to build defaults params.
*
* @param diagram The [Diagram] to print in [File].
* @param file The [File] where to print the [Diagram].
* @param expectedContent The expected content.
*/
constructor(
diagram: Diagram,
file: File,
Expand All @@ -23,6 +36,9 @@ class KtFileHasContentAssertion(
expectedContent
)

/**
* Check the assertion.
*/
override fun check() {
assertThat(
file.readText()
Expand Down

0 comments on commit b0b47f1

Please sign in to comment.