Skip to content

Commit

Permalink
Merge branch 'master' into fix/release-1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
l-1squared authored Jun 3, 2022
2 parents 279dcbb + 9e6cec6 commit aa3e648
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 71 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/jgiven_examples_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ jobs:
run: >
source scripts/source_files/helper_functions.sh
&& runGradleTestOnGivenProject example-projects/spring-boot/build.gradle 1.1-t
- name: Test TestNG Example Project
run: >
source scripts/source_files/helper_functions.sh
&& runGradleTestOnGivenProject example-projects/testng/build.gradle 1.1-t
- name: Test Maven Example Project
run: >
source scripts/source_files/helper_functions.sh
Expand Down Expand Up @@ -73,6 +69,8 @@ jobs:
run: source scripts/local_release_with_version.sh
- name: Test Java 11 Project
run: source scripts/source_files/helper_functions.sh && runMavenTestOnGivenProject example-projects/java11/pom.xml 1.1-t
- name: Test TestNG Example Project
run: source scripts/source_files/helper_functions.sh && runGradleTestOnGivenProject example-projects/testng/build.gradle 1.1-t
- name: Upload test results html files
continue-on-error: true
if: ${{failure()}}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'io.codearte.nexus-staging' version '0.30.0'
id 'com.github.ben-manes.versions' version '0.42.0'
id 'org.sonarqube' version '3.3' apply false
id 'com.github.node-gradle.node' version '3.2.1' apply false
id 'com.github.node-gradle.node' version '3.3.0' apply false
}

apply plugin: 'project-report'
Expand Down
2 changes: 1 addition & 1 deletion example-projects/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ configurations {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.appcompat:appcompat:1.4.2'

androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', {
exclude group: 'com.android.support', module: 'support-annotations'
Expand Down
6 changes: 3 additions & 3 deletions example-projects/selenium/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ repositories {
dependencies {
testImplementation "com.tngtech.jgiven:jgiven-junit:${version}"
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
testImplementation 'io.github.bonigarcia:webdrivermanager:5.1.1'
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.seleniumhq.selenium:selenium-java:4.2.1'
testImplementation 'io.github.bonigarcia:webdrivermanager:5.2.0'
testImplementation 'org.assertj:assertj-core:3.23.1'

}

Expand Down
4 changes: 2 additions & 2 deletions example-projects/spring-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

plugins {
id 'org.springframework.boot' version '2.6.7'
id 'org.springframework.boot' version '2.7.0'
}

apply plugin: 'java'
Expand All @@ -29,7 +29,7 @@ repositories {
}

ext {
assertjVersion = '3.22.0'
assertjVersion = '3.23.1'
junitDataproviderVersion = '1.13.1'
jgivenVersion = version
hsqldbVersion = '2.6.1'
Expand Down
2 changes: 1 addition & 1 deletion example-projects/testng/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {

dependencies {
testImplementation "com.tngtech.jgiven:jgiven-testng:${version}"
testImplementation 'org.testng:testng:7.5'
testImplementation 'org.testng:testng:7.6.0'
}

test.useTestNG() {
Expand Down
2 changes: 1 addition & 1 deletion jgiven-android-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ configurations {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.appcompat:appcompat:1.4.2'

androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', {
exclude group: 'com.android.support', module: 'support-annotations'
Expand Down
2 changes: 1 addition & 1 deletion jgiven-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies {
api "com.google.guava:guava:$guavaAndroidVersion"
api("net.bytebuddy:byte-buddy-android:$byteBuddyVersion")
api "junit:junit:$junitVersion"
implementation "androidx.appcompat:appcompat:1.4.1"
implementation "androidx.appcompat:appcompat:1.4.2"
implementation('androidx.test:core:1.4.0')
implementation('androidx.test:rules:1.4.0') {
exclude group: "junit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ private void addTags(ResolvedTags tags) {
if (reportModel != null) {
this.reportModel.addTags(tags.getDeclaredTags());
//The report model needs to declare the parent tags in a tag map, or the tags cannot be displayed.
this.reportModel.addTags(tags.getParents());
this.reportModel.addTags(tags.getAncestors());
}

if (scenarioModel != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.tngtech.jgiven.report.model.Tag;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand All @@ -15,25 +16,28 @@ public List<Tag> getDeclaredTags() {
return resolvedTags.stream().map(resolvedTag -> resolvedTag.tag).collect(Collectors.toList());
}

public List<Tag> getParents() {
return resolvedTags.stream().flatMap(resolvedTag -> resolvedTag.parents.stream()).collect(Collectors.toList());
@SuppressWarnings("CheckStyle")
public Set<Tag> getAncestors() {
return resolvedTags.stream()
.flatMap(resolvedTag -> resolvedTag.ancestors.stream())
.collect(Collectors.toSet());
}

public boolean isEmpty() {
return resolvedTags.isEmpty();
}

/**
* A single tag declared for a scenario and the parents necessary to display it.
* A single tag declared for a scenario and the ancestors necessary to display it.
*/
public static class ResolvedTag {
public final Tag tag;
public final List<Tag> parents;
public final List<Tag> ancestors;

ResolvedTag(Tag tag, List<Tag> parents) {
ResolvedTag(Tag tag, List<Tag> ancestors) {

this.tag = tag;
this.parents = parents;
this.ancestors = ancestors;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.tngtech.jgiven.report.model.Tag;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -48,14 +49,14 @@ public ResolvedTags toTags(Class<? extends Annotation> annotationClass, String..
return new ResolvedTags();
}

List<Tag> parents = getTags(annotationClass);
List<Tag> ancestors = getAllAncestorTags(annotationClass);
if (values.length > 0) {
List<Tag> explodedTags = getExplodedTags(Iterables.getOnlyElement(tags), values, null, tagConfig);
return explodedTags.stream()
.map(tag -> new ResolvedTags.ResolvedTag(tag, parents))
.map(tag -> new ResolvedTags.ResolvedTag(tag, ancestors))
.collect(new TagCollector());
} else {
return ResolvedTags.from(new ResolvedTags.ResolvedTag(Iterables.getOnlyElement(tags), parents));
return ResolvedTags.from(new ResolvedTags.ResolvedTag(Iterables.getOnlyElement(tags), ancestors));
}
}

Expand All @@ -71,7 +72,7 @@ public ResolvedTags toTags(Annotation annotation) {
}

List<Tag> tags = processConfiguredAnnotation(tagConfig, annotation);
List<Tag> parents = getTags(annotationType);
List<Tag> parents = getAllAncestorTags(annotationType);
return tags.stream()
.map(tag -> new ResolvedTags.ResolvedTag(tag, parents))
.collect(new TagCollector());
Expand Down Expand Up @@ -177,37 +178,34 @@ private TagConfiguration fromIsTag(IsTag isTag, Class<? extends Annotation> anno
.cssClass(isTag.cssClass())
.color(isTag.color())
.style(isTag.style())
.tags(getTagNames(annotationType))
.tags(getNamesOfParentTags(annotationType))
.href(isTag.href())
.hrefGenerator(isTag.hrefGenerator())
.showInNavigation(isTag.showInNavigation())
.build();
}

private List<String> getTagNames(Class<? extends Annotation> annotationType) {
List<Tag> tags = getTags(annotationType);
List<String> tagNames = Lists.newArrayList();
for (Tag tag : tags) {
tagNames.add(tag.toIdString());
}
return tagNames;
private List<String> getNamesOfParentTags(Class<? extends Annotation> annotationType) {
return getTagAnnotationsOn(annotationType)
.flatMap(resolvedTags -> resolvedTags.getDeclaredTags().stream())
.map(Tag::toIdString)
.collect(Collectors.toList());
}

private List<Tag> getTags(Class<? extends Annotation> annotationType) {
List<Tag> allTags = Lists.newArrayList();

for (Annotation annotation : annotationType.getAnnotations()) {
if (annotation.annotationType().isAnnotationPresent(IsTag.class)) {
allTags.addAll(toTags(annotation).resolvedTags.stream()
.flatMap(tag -> {
Stream<Tag> tagStream = Stream.of(tag.tag);
return Stream.concat(tagStream, tag.parents.stream());
})
.collect(Collectors.toList()));
}
}
private List<Tag> getAllAncestorTags(Class<? extends Annotation> annotationType) {
return getTagAnnotationsOn(annotationType)
.flatMap(resolvedTags -> resolvedTags.resolvedTags.stream())
.flatMap(tag -> {
Stream<Tag> tagStream = Stream.of(tag.tag);
return Stream.concat(tagStream, tag.ancestors.stream());
})
.collect(Collectors.toList());
}

return allTags;
private Stream<ResolvedTags> getTagAnnotationsOn(Class<? extends Annotation> annotationType) {
return Arrays.stream(annotationType.getAnnotations())
.filter(a -> a.annotationType().isAnnotationPresent(IsTag.class))
.map(this::toTags);
}

private List<String> toStringList(Object[] value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ public synchronized void addTag(Tag tag) {
this.tagMap.put(tag.toIdString(), tag);
}

public synchronized void addTags(List<Tag> tags) {
for (Tag tag : tags) {
addTag(tag);
}
public synchronized void addTags(Iterable<Tag> tags) {
tags.forEach(this::addTag);
}

public synchronized Tag getTagWithId(String tagId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class ResolvedTagsTest {
public void testResolvedTagsFiltersForDirectTags() {
ResolvedTags underTest = TestTagGenerator.getEnumeratedResolvedTags(5);
assertThat(underTest.getDeclaredTags()).extracting(Tag::getFullType)
.containsExactly("tag1", "tag2", "tag3", "tag4", "tag5");
.containsExactlyInAnyOrder("tag1", "tag2", "tag3", "tag4", "tag5");
}

@Test
public void testResolvedTagsFiltersForParents() {
ResolvedTags underTest = TestTagGenerator.getEnumeratedResolvedTags(5);
assertThat(underTest.getParents()).extracting(Tag::getFullType)
.containsExactly("parent1", "parent2", "parent3", "parent4", "parent5");
assertThat(underTest.getAncestors()).extracting(Tag::getFullType)
.containsExactlyInAnyOrder("parent1", "parent2", "parent3", "parent4", "parent5");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ class AnnotationWithDescriptionAndIgnoreValue {
@interface TagWithGrandparentTags {
}



@SuppressWarnings("checkstyle:OneTopLevelClass")
@TagWithParentTags
class AnnotationWithParentTag {
}


Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -29,7 +30,7 @@ public void addLogInterceptor() {
@Test
public void testAnnotationParsing() {
Tag tag = getOnlyTagFor(AnnotationTestClass.class.getAnnotations()[0]);
assertThat(tag.getName()).isEqualTo("AnnotationWithoutValue");
assertThat(tag.getName()).isEqualTo(AnnotationWithoutValue.class.getSimpleName());
assertThat(tag.getValues()).isEmpty();
assertThat(interceptor.containsLoggingEvent(record -> record.getLevel() == Level.SEVERE))
.as("Attempt to convert an annotation without value method results in an error log")
Expand All @@ -39,7 +40,7 @@ public void testAnnotationParsing() {
@Test
public void testAnnotationWithValueParsing() {
Tag tag = getOnlyTagFor(AnnotationWithSingleValueTestClass.class.getAnnotations()[0]);
assertThat(tag.getName()).isEqualTo("AnnotationWithSingleValue");
assertThat(tag.getName()).isEqualTo(AnnotationWithSingleValue.class.getSimpleName());
assertThat(tag.getValues()).containsExactly("testvalue");
}

Expand All @@ -54,15 +55,15 @@ public void testAnnotationWithName() {
@Test
public void testAnnotationWithIgnoredValueParsing() {
Tag tag = getOnlyTagFor(AnnotationWithIgnoredValueTestClass.class.getAnnotations()[0]);
assertThat(tag.getName()).isEqualTo("AnnotationWithIgnoredValue");
assertThat(tag.getName()).isEqualTo(AnnotationWithIgnoredValue.class.getSimpleName());
assertThat(tag.getValues()).isEmpty();
assertThat(tag.toIdString()).isEqualTo(AnnotationWithIgnoredValue.class.getName());
}

@Test
public void testAnnotationWithoutExplodedArrayParsing() {
Tag tag = getOnlyTagFor(AnnotationWithoutExplodedArrayValueTestClass.class.getAnnotations()[0]);
assertThat(tag.getName()).isEqualTo("AnnotationWithoutExplodedArray");
assertThat(tag.getName()).isEqualTo(AnnotationWithoutExplodedArray.class.getSimpleName());
assertThat(tag.getValues()).containsExactly("foo", "bar");
}

Expand All @@ -85,7 +86,7 @@ public void testAnnotationWithParentTag() {
Tag tag = getOnlyTagFor(AnnotationWithParentTag.class.getAnnotations()[0]);
assertThat(tag.getTags()).containsAll(Arrays.asList(
ParentTag.class.getName(),
ParentTagWithValue.class.getPackage().getName() + ".ParentTagWithValue-SomeValue")
ParentTagWithValue.class.getName() + "-SomeValue")
);
}

Expand All @@ -102,13 +103,35 @@ public void testAnnotationWithArrayParsing() {

@Test
public void testAllParentsOfTagAreResolved() {
String[] expectedNames = Stream.of(TagWithParentTags.class, ParentTag.class, ParentTagWithValue.class)
.map(Class::getSimpleName).toArray(String[]::new);

ResolvedTags resolvedTags = underTest.toTags(TagWithGrandparentTags.class);
assertThat(resolvedTags.getDeclaredTags())
.extracting(Tag::getName)
.containsExactly("TagWithGrandparentTags");
assertThat(resolvedTags.getParents())
.extracting(Tag::getName)
.containsExactlyInAnyOrder("TagWithParentTags", "ParentTag", "ParentTagWithValue");

assertThat(resolvedTags.getAncestors()).extracting(Tag::getName).containsExactlyInAnyOrder(expectedNames);
assertThat(resolvedTags.getDeclaredTags()).extracting(Tag::getName)
.containsExactly(TagWithGrandparentTags.class.getSimpleName());
}

@Test
public void testTagConfigurationOnlyRefersToTheTagsSingleParent() {
ResolvedTags resolvedTags = underTest.toTags(TagWithGrandparentTags.class);
assertThat(resolveParentNames(resolvedTags)).containsExactly(TagWithParentTags.class.getName());
}

@Test
public void testTagConfigurationRefersToBothParentTags() {
ResolvedTags resolvedTags = underTest.toTags(TagWithParentTags.class);
assertThat(resolveParentNames(resolvedTags)).containsExactlyInAnyOrder(
ParentTag.class.getName(),
ParentTagWithValue.class.getName() + "-SomeValue"
);
}

private Stream<String> resolveParentNames(ResolvedTags resolvedTags) {
return resolvedTags.getDeclaredTags().stream()
.map(Tag::getTags)
.flatMap(List::stream);
}

private Tag getOnlyTagFor(Annotation annotation) {
Expand Down
2 changes: 1 addition & 1 deletion jgiven-junit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
testImplementation "junit:junit:$junitVersion"
testImplementation "pl.pragmatists:JUnitParams:$junitParamsVersion"
testImplementation "com.googlecode.junit-toolbox:junit-toolbox:2.4"
testImplementation "org.mockito:mockito-core:4.5.1"
testImplementation "org.mockito:mockito-core:4.6.1"
}

test.finalizedBy(jgivenHtml5Report)
Expand Down
2 changes: 1 addition & 1 deletion jgiven-testng/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
compileOnly "org.testng:testng:$testngVersion"

testImplementation "org.testng:testng:$testngVersion"
testImplementation "org.mockito:mockito-core:4.5.1"
testImplementation "org.mockito:mockito-core:4.6.1"
}

test.useTestNG() {
Expand Down
Loading

0 comments on commit aa3e648

Please sign in to comment.