Skip to content

Commit

Permalink
Migrated tests of webtester-support-assertj3 to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
slu-it authored and Axel Schüssler committed Nov 27, 2016
1 parent 6acf8f8 commit a96b235
Show file tree
Hide file tree
Showing 16 changed files with 781 additions and 556 deletions.
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
<!-- dependency versions -->

<version.junit>4.12</version.junit>
<version.junit5>5.0.0-M2</version.junit5>
<version.junit5.platform>1.0.0-M2</version.junit5.platform>
<version.hamcrest>1.3</version.hamcrest>
<version.assertj>3.4.1</version.assertj>
<version.mockito>2.2.1</version.mockito>
Expand Down Expand Up @@ -203,6 +205,23 @@
<artifactId>junit</artifactId>
<version>${version.junit}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit5}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit5}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${version.junit5.platform}</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
Expand Down
41 changes: 41 additions & 0 deletions webtester-support-assertj3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,47 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<!-- Currently only the surefire plugin can execute JUnit 5 tests. -->
<!-- Therefore it needs to be reconfigured to execute all tests regardless of their type. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${version.junit5.platform}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<!-- Currently only the failsafe plugin can't execute JUnit 5 tests. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @see GenericTextFieldAssert
* @since 2.0
*/
public final class WebTesterAssertions extends Assertions {
public final class WebTesterAssertions {

/**
* Creates a new {@link PageFragmentAssert} for the given {@link PageFragment}.
Expand Down Expand Up @@ -79,6 +79,7 @@ public static ButtonAssert assertThat(Button actual) {
* @see GenericSelectAssert
* @since 2.0
*/
@SuppressWarnings("unchecked")
public static GenericSelectAssert assertThat(GenericSelect actual) {
return new GenericSelectAssert(actual, GenericSelectAssert.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,4 @@ public A and() {
return ( A ) this;
}

protected final void failOnActualBeingNull() {
if (actual == null) {
failWithMessage("actual is null");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public abstract class AbstractPageFragmentAssert<A extends AbstractPageFragmentA

protected AbstractPageFragmentAssert(B actual, Class<A> selfType) {
super(actual, selfType);
failOnActualBeingNull();
}

/* tag name */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public MultiSelectAssert(MultiSelect actual) {
* @since 2.0
*/
public MultiSelectAssert hasSelectionWithTexts(String... texts) {
String errorMessage = "Expected select's selection texts to be <%s>, but were <%s>.";
String errorMessage = "Expected select's selected texts to be <%s>, but they were <%s>.";
List<String> actualTexts = actual.getSelectionTexts();
assertThat(actualTexts).overridingErrorMessage(errorMessage, Arrays.toString(texts), actualTexts)
.containsExactly(texts);
Expand All @@ -47,7 +47,7 @@ public MultiSelectAssert hasSelectionWithTexts(String... texts) {
* @since 2.0
*/
public MultiSelectAssert hasSelectionWithValues(String... values) {
String errorMessage = "Expected select's selection values to be <%s>, but were <%s>.";
String errorMessage = "Expected select's selected values to be <%s>, but they were <%s>.";
List<String> actualValues = actual.getSelectionValues();
assertThat(actualValues).overridingErrorMessage(errorMessage, Arrays.toString(values), actualValues)
.containsExactly(values);
Expand All @@ -63,7 +63,7 @@ public MultiSelectAssert hasSelectionWithValues(String... values) {
* @since 2.0
*/
public MultiSelectAssert hasSelectionWithIndices(Integer... indices) {
String errorMessage = "Expected select's selection indices to be <%s>, but were <%s>.";
String errorMessage = "Expected select's selected indices to be <%s>, but they were <%s>.";
List<Integer> actualIndices = actual.getSelectionIndices();
assertThat(actualIndices).overridingErrorMessage(errorMessage, Arrays.toString(indices), actualIndices)
.containsExactly(indices);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
package info.novatec.testit.webtester.support.assertj.assertions;

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;


@RunWith(Enclosed.class)
public class AbstractWebTesterAssertTest {

public static class FailOnActualBeingNull {
@Nested
class AssertionsProvideFluentApi {

@Test
public void nonNullActualPasses() {
new TestAssert("foo").failOnActualBeingNull();
}

@Test(expected = AssertionError.class)
public void nullActualThrowsError() {
new TestAssert(null).failOnActualBeingNull();
}

}

public static class And {

@Test
public void invocationReturnsSameAssertionInstance() {
public void and() {
TestAssert original = new TestAssert("foo");
TestAssert returned = original.and();
Assertions.assertThat(returned).isSameAs(original);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,62 +1,77 @@
package info.novatec.testit.webtester.support.assertj.assertions.pagefragments;

import static info.novatec.testit.webtester.support.assertj.WebTesterAssertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.expectThrows;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import info.novatec.testit.webtester.pagefragments.Button;


@RunWith(Enclosed.class)
public class ButtonAssertTest {

public static class HasLabel {
@Nested
class HasLabelAssertion {

@Test
public void havingLabelPasses() {
assertThat(buttonWithLabel("foo")).hasLabel("foo");
}

@Test(expected = AssertionError.class)
public void notHavingLabelFails() {
assertThat(buttonWithLabel("bar")).hasLabel("foo");
void passesForMatchingLabels() {
Button fooButton = buttonWithLabel("foo");
assertThat(fooButton).hasLabel("foo");
}

@Test
public void invocationReturnsSameAssertionInstance() {
ButtonAssert original = assertThat(buttonWithLabel("foo"));
ButtonAssert returned = original.hasLabel("foo");
assertThat(returned).isSameAs(original);
void failsForDifferentLabels() {
Button barButton = buttonWithLabel("bar");
assertThat(expectThrows(AssertionError.class, () -> {
assertThat(barButton).hasLabel("foo");
})).hasMessage("Expected buttons's label to be <foo>, but was <bar>.");
}

}

public static class NotHasLabel {
@Nested
class HasNotLabelAssertion {

@Test
void passesForDifferentLabels() {
Button barButton = buttonWithLabel("bar");
assertThat(barButton).hasNotLabel("foo");
}

@Test
public void notHavingLabelPasses() {
assertThat(buttonWithLabel("bar")).hasNotLabel("foo");
void failsForMatchingLabels() {
Button fooButton = buttonWithLabel("foo");
assertThat(expectThrows(AssertionError.class, () -> {
assertThat(fooButton).hasNotLabel("foo");
})).hasMessage("Expected buttons's label not to be <foo>, but it was.");
}

@Test(expected = AssertionError.class)
public void havingLabelFails() {
assertThat(buttonWithLabel("foo")).hasNotLabel("foo");
}

@Nested
class AssertionsProvideFluentApi {

@Test
void hasLabel() {
ButtonAssert original = assertThat(buttonWithLabel("foo"));
ButtonAssert returned = original.hasLabel("foo");
assertThat(returned).isSameAs(original);
}

@Test
public void invocationReturnsSameAssertionInstance() {
void hasNotLabel() {
ButtonAssert original = assertThat(buttonWithLabel("bar"));
ButtonAssert returned = original.hasNotLabel("foo");
assertThat(returned).isSameAs(original);
}

}

private static Button buttonWithLabel(String label) {
Button buttonWithLabel(String label) {
Button button = mock(Button.class);
doReturn(label).when(button).getLabel();
return button;
Expand Down
Loading

0 comments on commit a96b235

Please sign in to comment.