diff --git a/README.md b/README.md index ccb73e9c..f76b1180 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,13 @@ AssertJ examples is divided in two : assertions-examples (core, guava and joda a Please have a look at **[assertions examples sources](assertions-examples/src/test/java/org/assertj/examples)**. The **master** branch contains examples with the latest released version of AssertJ modules, you can build it with `mvn clean install` command. +In your IDE, add `src/test/generated-assertions` to the project java sources if you IDE shows errors/missing classes. +This folder is where custom assertions classes are generated, it shows what you have with the maven assertions generator plugin. Building **with-latest-snapshot-versions** is a little more complicated : - you need to build the needed SNAPSHOT dependencies before - most probably assertj-core and maybe other modules. - run `mvn clean install` in `assertj-examples/assertions-examples`. -- In your IDE, add `target/generated-test-sources` to the project java sources if you IDE shows errors/missing classes. +- In your IDE, add `src/test/generated-assertions` to the project java sources if you IDE shows errors/missing classes. ### AssertJ-Swing examples diff --git a/assertions-examples/.classpath b/assertions-examples/.classpath new file mode 100644 index 00000000..4b25f5b9 --- /dev/null +++ b/assertions-examples/.classpath @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assertions-examples/.gitignore b/assertions-examples/.gitignore index d6030c64..c4fc0efa 100644 --- a/assertions-examples/.gitignore +++ b/assertions-examples/.gitignore @@ -1,7 +1,5 @@ /target /.settings -/.classpath -/.project .DS_Store .idea /*.iml diff --git a/assertions-examples/.project b/assertions-examples/.project new file mode 100644 index 00000000..4205c53a --- /dev/null +++ b/assertions-examples/.project @@ -0,0 +1,14 @@ + + + assertj-examples + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + + + org.eclipse.jdt.core.javabuilder + + + + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/assertions-examples/pom.xml b/assertions-examples/pom.xml index 451b3073..faa9a34a 100644 --- a/assertions-examples/pom.xml +++ b/assertions-examples/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> 4.0.0 org.assertj @@ -33,7 +33,7 @@ org.assertj assertj-core - 1.6.1 + 1.7.0 test @@ -79,7 +79,7 @@ ch.qos.logback logback-classic - 1.0.9 + 1.0.13 junit @@ -123,18 +123,14 @@ **/*Examples.java -Xms128m -Xmx512m - - + + org.assertj assertj-assertions-generator-maven-plugin - 1.4.0 - + 1.4.1 @@ -144,29 +140,26 @@ + org.assertj.examples.rpg org.assertj.examples.data com.google.common.net true - src/test/java - org.assertj.examples.data - + org.assertj + .*google.*HostSpecifier .*google.*Headers .*google.*MediaType .*google.*Escaper.* + src/test/generated-assertions org.codehaus.mojo build-helper-maven-plugin - 1.8 + 1.9 add-source @@ -177,7 +170,7 @@ - target/generated-test-sources/assertj-assertions + src/test/generated-assertions diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/BasketBallPlayer.java b/assertions-examples/src/main/java/org/assertj/examples/data/BasketBallPlayer.java index 24f220e2..600f65d0 100644 --- a/assertions-examples/src/main/java/org/assertj/examples/data/BasketBallPlayer.java +++ b/assertions-examples/src/main/java/org/assertj/examples/data/BasketBallPlayer.java @@ -25,6 +25,8 @@ public class BasketBallPlayer { private Name name; + public double size; + private float weight; private int pointsPerGame; private int assistsPerGame; private int reboundsPerGame; @@ -49,6 +51,14 @@ public void setName(Name name) { this.name = name; } + public float getWeight() { + return weight; + } + + public void setWeight(float weight) { + this.weight = weight; + } + public int getPointsPerGame() { return pointsPerGame; } diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/Book.java b/assertions-examples/src/main/java/org/assertj/examples/data/Book.java new file mode 100644 index 00000000..4996413d --- /dev/null +++ b/assertions-examples/src/main/java/org/assertj/examples/data/Book.java @@ -0,0 +1,41 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.data; + +public class Book { + + private Title title; + + public Book(String title) { + + this.title = new Title(title); + } + + public Title getTitle() { + return title; + } + + public static class Title { + private String title; + + public Title(String title) { + super(); + this.title = title; + } + + public String getTitle() { + return title; + } + } + +} diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/MyAssert.java b/assertions-examples/src/main/java/org/assertj/examples/data/MyAssert.java new file mode 100644 index 00000000..f78ab296 --- /dev/null +++ b/assertions-examples/src/main/java/org/assertj/examples/data/MyAssert.java @@ -0,0 +1,18 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.data; + +// only used to verify that we don't generate assertions classes for *Assert classes +public class MyAssert { + // empty +} diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/Race.java b/assertions-examples/src/main/java/org/assertj/examples/data/Race.java index 6857532d..7ec03e6e 100644 --- a/assertions-examples/src/main/java/org/assertj/examples/data/Race.java +++ b/assertions-examples/src/main/java/org/assertj/examples/data/Race.java @@ -27,7 +27,7 @@ public enum Race { HOBBIT("Hobbit", false, GOOD), MAIA("Maia", true, GOOD), MAN("Man", false, NEUTRAL), ELF("Elf", true, GOOD), DWARF("Dwarf", false, GOOD), ORC("Orc", false, EVIL); private final String name; - private final boolean immortal; + public final boolean immortal; private Alignment alignment; Race(String name, boolean immortal, Alignment alignment) { @@ -40,10 +40,6 @@ public String getName() { return name; } - public boolean isImmortal() { - return immortal; - } - public Alignment getAlignment() { return alignment; } diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/TolkienCharacter.java b/assertions-examples/src/main/java/org/assertj/examples/data/TolkienCharacter.java index 4f40036b..fcdc773b 100644 --- a/assertions-examples/src/main/java/org/assertj/examples/data/TolkienCharacter.java +++ b/assertions-examples/src/main/java/org/assertj/examples/data/TolkienCharacter.java @@ -78,7 +78,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return name + " " + age + " years old " + race.getName(); + return name + " " + age + " years old " + (race != null ? race.getName() : "unknown race"); } } diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/bug18/Dollar$.java b/assertions-examples/src/main/java/org/assertj/examples/data/bug18/Dollar$.java new file mode 100644 index 00000000..1c4eb6fd --- /dev/null +++ b/assertions-examples/src/main/java/org/assertj/examples/data/bug18/Dollar$.java @@ -0,0 +1,19 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.data.bug18; + +// test for https://github.com/joel-costigliola/assertj-assertions-generator/issues/18 +public class Dollar$ { + public String test; + +} \ No newline at end of file diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/bug26/WithGenericListType.java b/assertions-examples/src/main/java/org/assertj/examples/data/bug26/WithGenericListType.java new file mode 100644 index 00000000..925effdb --- /dev/null +++ b/assertions-examples/src/main/java/org/assertj/examples/data/bug26/WithGenericListType.java @@ -0,0 +1,24 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.data.bug26; + +import java.util.ArrayList; +import java.util.List; + +import org.assertj.examples.data.movie.Movie; + +public class WithGenericListType { + + public Iterable movies = new ArrayList(); + +} diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/bug27/MyIteratorWrapper.java b/assertions-examples/src/main/java/org/assertj/examples/data/bug27/MyIteratorWrapper.java new file mode 100644 index 00000000..39a33d3d --- /dev/null +++ b/assertions-examples/src/main/java/org/assertj/examples/data/bug27/MyIteratorWrapper.java @@ -0,0 +1,33 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.data.bug27; + +import java.util.Iterator; + +@SuppressWarnings("rawtypes") +public class MyIteratorWrapper implements Iterator { + + @Override + public boolean hasNext() { + return false; + } + + @Override + public Object next() { + return null; + } + + @Override + public void remove() { + } +} diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/bug27/MyModelClass.java b/assertions-examples/src/main/java/org/assertj/examples/data/bug27/MyModelClass.java new file mode 100644 index 00000000..59799c66 --- /dev/null +++ b/assertions-examples/src/main/java/org/assertj/examples/data/bug27/MyModelClass.java @@ -0,0 +1,21 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.data.bug27; + +public class MyModelClass { + @SuppressWarnings("unused") + private MyIteratorWrapper iterator; + + public static class MyBean { + } +} \ No newline at end of file diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/movie/Team.java b/assertions-examples/src/main/java/org/assertj/examples/data/movie/Team.java new file mode 100644 index 00000000..24d02676 --- /dev/null +++ b/assertions-examples/src/main/java/org/assertj/examples/data/movie/Team.java @@ -0,0 +1,31 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.data.movie; + +import java.util.List; + +// another Team class to test generated assertion can make the difference between the Team classes. +public class Team { + + private List actors; + + public Team(List actors) { + super(); + this.actors = actors; + } + + public List getActors() { + return actors; + } + +} diff --git a/assertions-examples/src/main/java/org/assertj/examples/data/neo4j/DragonBallGraph.java b/assertions-examples/src/main/java/org/assertj/examples/data/neo4j/DragonBallGraph.java index 85c4137e..49de683b 100644 --- a/assertions-examples/src/main/java/org/assertj/examples/data/neo4j/DragonBallGraph.java +++ b/assertions-examples/src/main/java/org/assertj/examples/data/neo4j/DragonBallGraph.java @@ -1,13 +1,13 @@ /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * Copyright 2012-2014 the original author or authors. */ package org.assertj.examples.data.neo4j; @@ -38,134 +38,126 @@ public class DragonBallGraph { - private final GraphDatabaseService graphDB; - private final ExecutionEngine cypherEngine; + private final GraphDatabaseService graphDB; + private final ExecutionEngine cypherEngine; - public DragonBallGraph(GraphDatabaseService graphDB) { - this.graphDB = graphDB; - cypherEngine = new ExecutionEngine(this.graphDB); - } + public DragonBallGraph(GraphDatabaseService graphDB) { + this.graphDB = graphDB; + cypherEngine = new ExecutionEngine(this.graphDB); + } - public final void importGraph(InputStream dataFile) throws IOException { - InputStreamReader reader = new InputStreamReader(dataFile); - try (Transaction transaction = graphDB.beginTx()) { - for (String statement : statements(reader)) { - cypherEngine.execute(statement); - } - transaction.success(); - } + public final void importGraph(InputStream dataFile) throws IOException { + InputStreamReader reader = new InputStreamReader(dataFile); + try (Transaction transaction = graphDB.beginTx()) { + for (String statement : statements(reader)) { + cypherEngine.execute(statement); + } + transaction.success(); } + } + + public Iterable disciplesOf(String masterName) { + try (Transaction transaction = graphDB.beginTx(); + ResourceIterator nodes = discipleRowsOf(masterName).columnAs("disciples")) { - public Iterable disciplesOf(String masterName) { - try (Transaction transaction = graphDB.beginTx(); - ResourceIterator nodes = discipleRowsOf(masterName).columnAs("disciples")) { - - Collection disciples = new LinkedList<>(); - while (nodes.hasNext()) { - disciples.add(nodes.next()); - } - transaction.success(); - return disciples; - } + Collection disciples = new LinkedList<>(); + while (nodes.hasNext()) { + disciples.add(nodes.next()); + } + transaction.success(); + return disciples; } + } public ExecutionResult discipleRowsOf(String masterName) { Map parameters = newHashMap(); parameters.put("name", masterName); - return cypherEngine.execute( - "MATCH (disciples:CHARACTER)-[:HAS_TRAINED_WITH]->(master:MASTER {name: {name}}) " + - "RETURN disciples, master", - parameters - ); + return cypherEngine.execute("MATCH (disciples:CHARACTER)-[:HAS_TRAINED_WITH]->(master:MASTER {name: {name}}) " + + "RETURN disciples, master", parameters); } public Iterable fusions() { - try (Transaction transaction = graphDB.beginTx(); - ResourceIterator relationships = cypherEngine.execute( - "MATCH (:CHARACTER)-[fusions:IN_FUSION_WITH]-(:CHARACTER) RETURN fusions" - ).columnAs("fusions")) { - - Collection fusions = new LinkedHashSet<>(); - while (relationships.hasNext()) { - fusions.add(relationships.next()); - } - transaction.success(); - return fusions; - } + try (Transaction tx = graphDB.beginTx(); + ResourceIterator relationships = cypherEngine.execute( + "MATCH (:CHARACTER)-[fusions:IN_FUSION_WITH]-(:CHARACTER) RETURN fusions").columnAs("fusions")) { + + Collection fusions = new LinkedHashSet<>(); + while (relationships.hasNext()) { + fusions.add(relationships.next()); + } + tx.success(); + return fusions; } + } - public Node findCharacter(String characterName) { - Map parameters = newHashMap(); - parameters.put("name", characterName); - try (Transaction transaction = graphDB.beginTx(); - ResourceIterator relationships = cypherEngine.execute( - "MATCH (character:CHARACTER {name: {name}}) RETURN character", - parameters - ).columnAs("character")) { - - Collection characters = new LinkedHashSet<>(); - while (relationships.hasNext()) { - characters.add(relationships.next()); - } - if (characters.size() > 1) { - throw new IllegalStateException(format( - "There should be only one character named <%s>", - characterName - )); - } - transaction.success(); - return characters.iterator().next(); - } + public ResourceIterator fusionCharactersIterator() { + try (Transaction tx = graphDB.beginTx()) { + ResourceIterator relationships = cypherEngine.execute( + "MATCH (:CHARACTER)-[fusions:IN_FUSION_WITH]-(:CHARACTER) RETURN DISTINCT fusions.into ORDER BY fusions.into").columnAs("fusions.into"); + + tx.success(); + return relationships; } + } - public Path findShortestPathBetween(String characterOne, String characterTwo) { - Map parameters = newHashMap(); - parameters.put("name1", characterOne); - parameters.put("name2", characterTwo); - try (Transaction transaction = graphDB.beginTx()) { - Path path = cypherEngine.execute( - "MATCH (character1:CHARACTER {name: {name1}}), " + - "(character2:CHARACTER {name: {name2}}), " + - "path = shortestPath((character1)-[*..15]-(character2)) " + - "RETURN path", - parameters - ).columnAs("path").next(); - transaction.success(); - return path; - } + public Node findCharacter(String characterName) { + Map parameters = newHashMap(); + parameters.put("name", characterName); + try (Transaction transaction = graphDB.beginTx(); + ResourceIterator relationships = cypherEngine.execute( + "MATCH (character:CHARACTER {name: {name}}) RETURN character", parameters).columnAs("character")) { + + Collection characters = new LinkedHashSet<>(); + while (relationships.hasNext()) { + characters.add(relationships.next()); + } + if (characters.size() > 1) { + throw new IllegalStateException(format("There should be only one character named <%s>", characterName)); + } + transaction.success(); + return characters.iterator().next(); } + } - public Relationship findTrainingFrom(String characterName) { - Map parameters = newHashMap(); - parameters.put("name", characterName); - try (Transaction transaction = graphDB.beginTx(); - ResourceIterator relationships = cypherEngine.execute( - "MATCH (:CHARACTER {name: {name}})-[training:HAS_TRAINED_WITH]->(:MASTER) RETURN training", - parameters - ).columnAs("training")) { - - LinkedList trainings = new LinkedList<>(); - while (relationships.hasNext()) { - trainings.add(relationships.next()); - } - - if (trainings.size() > 1) { - throw new IllegalStateException(format( - "There should be only one training involving character named <%s>", - characterName - )); - } - transaction.success(); - return trainings.iterator().next(); - } + public Path findShortestPathBetween(String characterOne, String characterTwo) { + Map parameters = newHashMap(); + parameters.put("name1", characterOne); + parameters.put("name2", characterTwo); + try (Transaction transaction = graphDB.beginTx()) { + Path path = cypherEngine + .execute( + "MATCH (character1:CHARACTER {name: {name1}}), " + "(character2:CHARACTER {name: {name2}}), " + + "path = shortestPath((character1)-[*..15]-(character2)) " + "RETURN path", parameters) + . columnAs("path").next(); + transaction.success(); + return path; } + } - private Collection statements(InputStreamReader reader) throws IOException { - return from(on(';') - .trimResults() - .omitEmptyStrings() - .split(CharStreams.toString(reader))) - .toList(); + public Relationship findTrainingFrom(String characterName) { + Map parameters = newHashMap(); + parameters.put("name", characterName); + try (Transaction transaction = graphDB.beginTx(); + ResourceIterator relationships = cypherEngine.execute( + "MATCH (:CHARACTER {name: {name}})-[training:HAS_TRAINED_WITH]->(:MASTER) RETURN training", parameters) + .columnAs("training")) { + + LinkedList trainings = new LinkedList<>(); + while (relationships.hasNext()) { + trainings.add(relationships.next()); + } + + if (trainings.size() > 1) { + throw new IllegalStateException(format("There should be only one training involving character named <%s>", + characterName)); + } + transaction.success(); + return trainings.iterator().next(); } + } + + private Collection statements(InputStreamReader reader) throws IOException { + return from(on(';').trimResults().omitEmptyStrings().split(CharStreams.toString(reader))).toList(); + } } diff --git a/assertions-examples/src/main/java/org/assertj/examples/exception/NameException.java b/assertions-examples/src/main/java/org/assertj/examples/exception/NameException.java index 199c002c..aea818cc 100644 --- a/assertions-examples/src/main/java/org/assertj/examples/exception/NameException.java +++ b/assertions-examples/src/main/java/org/assertj/examples/exception/NameException.java @@ -16,6 +16,8 @@ @SuppressWarnings("serial") public class NameException extends Exception { + private static final long serialVersionUID = 1L; + public NameException(Name name) { super("Invalid name " + name); } diff --git a/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractHostAndPortAssert.java b/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractHostAndPortAssert.java new file mode 100644 index 00000000..9591cea6 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractHostAndPortAssert.java @@ -0,0 +1,65 @@ +package com.google.common.net; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link HostAndPort} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractHostAndPortAssert, A extends HostAndPort> extends AbstractAssert { + + /** + * Creates a new {@link AbstractHostAndPortAssert} to make assertions on actual HostAndPort. + * @param actual the HostAndPort we want to make assertions on. + */ + protected AbstractHostAndPortAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual HostAndPort's hostText is equal to the given one. + * @param hostText the given hostText to compare the actual HostAndPort's hostText to. + * @return this assertion object. + * @throws AssertionError - if the actual HostAndPort's hostText is not equal to the given one. + */ + public S hasHostText(String hostText) { + // check that actual HostAndPort we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected hostText of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualHostText = actual.getHostText(); + if (!org.assertj.core.util.Objects.areEqual(actualHostText, hostText)) { + failWithMessage(assertjErrorMessage, actual, hostText, actualHostText); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual HostAndPort's port is equal to the given one. + * @param port the given port to compare the actual HostAndPort's port to. + * @return this assertion object. + * @throws AssertionError - if the actual HostAndPort's port is not equal to the given one. + */ + public S hasPort(int port) { + // check that actual HostAndPort we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected port of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // check + int actualPort = actual.getPort(); + if (actualPort != port) { + failWithMessage(assertjErrorMessage, actual, port, actualPort); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractInetAddressesAssert.java b/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractInetAddressesAssert.java new file mode 100644 index 00000000..3fe89c69 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractInetAddressesAssert.java @@ -0,0 +1,19 @@ +package com.google.common.net; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link InetAddresses} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractInetAddressesAssert, A extends InetAddresses> extends AbstractAssert { + + /** + * Creates a new {@link AbstractInetAddressesAssert} to make assertions on actual InetAddresses. + * @param actual the InetAddresses we want to make assertions on. + */ + protected AbstractInetAddressesAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractInternetDomainNameAssert.java b/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractInternetDomainNameAssert.java new file mode 100644 index 00000000..72879f64 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/com/google/common/net/AbstractInternetDomainNameAssert.java @@ -0,0 +1,127 @@ +package com.google.common.net; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link InternetDomainName} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractInternetDomainNameAssert, A extends InternetDomainName> extends AbstractAssert { + + /** + * Creates a new {@link AbstractInternetDomainNameAssert} to make assertions on actual InternetDomainName. + * @param actual the InternetDomainName we want to make assertions on. + */ + protected AbstractInternetDomainNameAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual InternetDomainName is publicSuffix. + * @return this assertion object. + * @throws AssertionError - if the actual InternetDomainName is not publicSuffix. + */ + public S isPublicSuffix() { + // check that actual InternetDomainName we want to make assertions on is not null. + isNotNull(); + + // check + if (!actual.isPublicSuffix()) { + failWithMessage("\nExpected actual InternetDomainName to be publicSuffix but was not."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual InternetDomainName is not publicSuffix. + * @return this assertion object. + * @throws AssertionError - if the actual InternetDomainName is publicSuffix. + */ + public S isNotPublicSuffix() { + // check that actual InternetDomainName we want to make assertions on is not null. + isNotNull(); + + // check + if (actual.isPublicSuffix()) { + failWithMessage("\nExpected actual InternetDomainName not to be publicSuffix but was."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual InternetDomainName is topPrivateDomain. + * @return this assertion object. + * @throws AssertionError - if the actual InternetDomainName is not topPrivateDomain. + */ + public S isTopPrivateDomain() { + // check that actual InternetDomainName we want to make assertions on is not null. + isNotNull(); + + // check + if (!actual.isTopPrivateDomain()) { + failWithMessage("\nExpected actual InternetDomainName to be topPrivateDomain but was not."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual InternetDomainName is not topPrivateDomain. + * @return this assertion object. + * @throws AssertionError - if the actual InternetDomainName is topPrivateDomain. + */ + public S isNotTopPrivateDomain() { + // check that actual InternetDomainName we want to make assertions on is not null. + isNotNull(); + + // check + if (actual.isTopPrivateDomain()) { + failWithMessage("\nExpected actual InternetDomainName not to be topPrivateDomain but was."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual InternetDomainName is underPublicSuffix. + * @return this assertion object. + * @throws AssertionError - if the actual InternetDomainName is not underPublicSuffix. + */ + public S isUnderPublicSuffix() { + // check that actual InternetDomainName we want to make assertions on is not null. + isNotNull(); + + // check + if (!actual.isUnderPublicSuffix()) { + failWithMessage("\nExpected actual InternetDomainName to be underPublicSuffix but was not."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual InternetDomainName is not underPublicSuffix. + * @return this assertion object. + * @throws AssertionError - if the actual InternetDomainName is underPublicSuffix. + */ + public S isNotUnderPublicSuffix() { + // check that actual InternetDomainName we want to make assertions on is not null. + isNotNull(); + + // check + if (actual.isUnderPublicSuffix()) { + failWithMessage("\nExpected actual InternetDomainName not to be underPublicSuffix but was."); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/com/google/common/net/HostAndPortAssert.java b/assertions-examples/src/test/generated-assertions/com/google/common/net/HostAndPortAssert.java new file mode 100644 index 00000000..c4b9906f --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/com/google/common/net/HostAndPortAssert.java @@ -0,0 +1,29 @@ +package com.google.common.net; + + +/** + * {@link HostAndPort} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractHostAndPortAssert} instead. + */ +public class HostAndPortAssert extends AbstractHostAndPortAssert { + + /** + * Creates a new {@link HostAndPortAssert} to make assertions on actual HostAndPort. + * @param actual the HostAndPort we want to make assertions on. + */ + public HostAndPortAssert(HostAndPort actual) { + super(actual, HostAndPortAssert.class); + } + + /** + * An entry point for HostAndPortAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myHostAndPort) and get specific assertion with code completion. + * @param actual the HostAndPort we want to make assertions on. + * @return a new {@link HostAndPortAssert} + */ + public static HostAndPortAssert assertThat(HostAndPort actual) { + return new HostAndPortAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/com/google/common/net/InetAddressesAssert.java b/assertions-examples/src/test/generated-assertions/com/google/common/net/InetAddressesAssert.java new file mode 100644 index 00000000..d0f3f5c1 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/com/google/common/net/InetAddressesAssert.java @@ -0,0 +1,29 @@ +package com.google.common.net; + + +/** + * {@link InetAddresses} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractInetAddressesAssert} instead. + */ +public class InetAddressesAssert extends AbstractInetAddressesAssert { + + /** + * Creates a new {@link InetAddressesAssert} to make assertions on actual InetAddresses. + * @param actual the InetAddresses we want to make assertions on. + */ + public InetAddressesAssert(InetAddresses actual) { + super(actual, InetAddressesAssert.class); + } + + /** + * An entry point for InetAddressesAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myInetAddresses) and get specific assertion with code completion. + * @param actual the InetAddresses we want to make assertions on. + * @return a new {@link InetAddressesAssert} + */ + public static InetAddressesAssert assertThat(InetAddresses actual) { + return new InetAddressesAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/com/google/common/net/InternetDomainNameAssert.java b/assertions-examples/src/test/generated-assertions/com/google/common/net/InternetDomainNameAssert.java new file mode 100644 index 00000000..04f11249 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/com/google/common/net/InternetDomainNameAssert.java @@ -0,0 +1,29 @@ +package com.google.common.net; + + +/** + * {@link InternetDomainName} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractInternetDomainNameAssert} instead. + */ +public class InternetDomainNameAssert extends AbstractInternetDomainNameAssert { + + /** + * Creates a new {@link InternetDomainNameAssert} to make assertions on actual InternetDomainName. + * @param actual the InternetDomainName we want to make assertions on. + */ + public InternetDomainNameAssert(InternetDomainName actual) { + super(actual, InternetDomainNameAssert.class); + } + + /** + * An entry point for InternetDomainNameAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myInternetDomainName) and get specific assertion with code completion. + * @param actual the InternetDomainName we want to make assertions on. + * @return a new {@link InternetDomainNameAssert} + */ + public static InternetDomainNameAssert assertThat(InternetDomainName actual) { + return new InternetDomainNameAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/Assertions.java b/assertions-examples/src/test/generated-assertions/org/assertj/Assertions.java new file mode 100644 index 00000000..57c561b7 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/Assertions.java @@ -0,0 +1,275 @@ +package org.assertj; + +/** + * Entry point for assertions of different data types. Each method in this class is a static factory for the + * type-specific assertion objects. + */ +public class Assertions { + + /** + * Creates a new instance of {@link com.google.common.net.HostAndPortAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static com.google.common.net.HostAndPortAssert assertThat(com.google.common.net.HostAndPort actual) { + return new com.google.common.net.HostAndPortAssert(actual); + } + + /** + * Creates a new instance of {@link com.google.common.net.InetAddressesAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static com.google.common.net.InetAddressesAssert assertThat(com.google.common.net.InetAddresses actual) { + return new com.google.common.net.InetAddressesAssert(actual); + } + + /** + * Creates a new instance of {@link com.google.common.net.InternetDomainNameAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static com.google.common.net.InternetDomainNameAssert assertThat(com.google.common.net.InternetDomainName actual) { + return new com.google.common.net.InternetDomainNameAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.AlignmentAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.AlignmentAssert assertThat(org.assertj.examples.data.Alignment actual) { + return new org.assertj.examples.data.AlignmentAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.BasketBallPlayerAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.BasketBallPlayerAssert assertThat(org.assertj.examples.data.BasketBallPlayer actual) { + return new org.assertj.examples.data.BasketBallPlayerAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.BookAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.BookAssert assertThat(org.assertj.examples.data.Book actual) { + return new org.assertj.examples.data.BookAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.BookTitleAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.BookTitleAssert assertThat(org.assertj.examples.data.Book.Title actual) { + return new org.assertj.examples.data.BookTitleAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.EmployeeAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.EmployeeAssert assertThat(org.assertj.examples.data.Employee actual) { + return new org.assertj.examples.data.EmployeeAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.MagicalAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.MagicalAssert assertThat(org.assertj.examples.data.Magical actual) { + return new org.assertj.examples.data.MagicalAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.MansionAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.MansionAssert assertThat(org.assertj.examples.data.Mansion actual) { + return new org.assertj.examples.data.MansionAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.NameAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.NameAssert assertThat(org.assertj.examples.data.Name actual) { + return new org.assertj.examples.data.NameAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.PersonAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.PersonAssert assertThat(org.assertj.examples.data.Person actual) { + return new org.assertj.examples.data.PersonAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.RaceAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.RaceAssert assertThat(org.assertj.examples.data.Race actual) { + return new org.assertj.examples.data.RaceAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.RingAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.RingAssert assertThat(org.assertj.examples.data.Ring actual) { + return new org.assertj.examples.data.RingAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.TeamAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.TeamAssert assertThat(org.assertj.examples.data.Team actual) { + return new org.assertj.examples.data.TeamAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.TolkienCharacterAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.TolkienCharacterAssert assertThat(org.assertj.examples.data.TolkienCharacter actual) { + return new org.assertj.examples.data.TolkienCharacterAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug18.Dollar$Assert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug18.Dollar$Assert assertThat(org.assertj.examples.data.bug18.Dollar$ actual) { + return new org.assertj.examples.data.bug18.Dollar$Assert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug26.WithGenericListTypeAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug26.WithGenericListTypeAssert assertThat(org.assertj.examples.data.bug26.WithGenericListType actual) { + return new org.assertj.examples.data.bug26.WithGenericListTypeAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug27.MyIteratorWrapperAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug27.MyIteratorWrapperAssert assertThat(org.assertj.examples.data.bug27.MyIteratorWrapper actual) { + return new org.assertj.examples.data.bug27.MyIteratorWrapperAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug27.MyModelClassAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug27.MyModelClassAssert assertThat(org.assertj.examples.data.bug27.MyModelClass actual) { + return new org.assertj.examples.data.bug27.MyModelClassAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug27.MyModelClassMyBeanAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug27.MyModelClassMyBeanAssert assertThat(org.assertj.examples.data.bug27.MyModelClass.MyBean actual) { + return new org.assertj.examples.data.bug27.MyModelClassMyBeanAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.movie.MovieAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.movie.MovieAssert assertThat(org.assertj.examples.data.movie.Movie actual) { + return new org.assertj.examples.data.movie.MovieAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.movie.TeamAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.movie.TeamAssert assertThat(org.assertj.examples.data.movie.Team actual) { + return new org.assertj.examples.data.movie.TeamAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.neo4j.DragonBallGraphAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.neo4j.DragonBallGraphAssert assertThat(org.assertj.examples.data.neo4j.DragonBallGraph actual) { + return new org.assertj.examples.data.neo4j.DragonBallGraphAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.service.GameServiceAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.service.GameServiceAssert assertThat(org.assertj.examples.data.service.GameService actual) { + return new org.assertj.examples.data.service.GameServiceAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.service.TeamManagerAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.service.TeamManagerAssert assertThat(org.assertj.examples.data.service.TeamManager actual) { + return new org.assertj.examples.data.service.TeamManagerAssert(actual); + } + + /** + * Creates a new {@link Assertions}. + */ + protected Assertions() { + // empty + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/BddAssertions.java b/assertions-examples/src/test/generated-assertions/org/assertj/BddAssertions.java new file mode 100644 index 00000000..01295850 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/BddAssertions.java @@ -0,0 +1,275 @@ +package org.assertj; + +/** + * Entry point for BDD assertions of different data types. Each method in this class is a static factory for the + * type-specific assertion objects. + */ +public class BddAssertions { + + /** + * Creates a new instance of {@link com.google.common.net.HostAndPortAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static com.google.common.net.HostAndPortAssert then(com.google.common.net.HostAndPort actual) { + return new com.google.common.net.HostAndPortAssert(actual); + } + + /** + * Creates a new instance of {@link com.google.common.net.InetAddressesAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static com.google.common.net.InetAddressesAssert then(com.google.common.net.InetAddresses actual) { + return new com.google.common.net.InetAddressesAssert(actual); + } + + /** + * Creates a new instance of {@link com.google.common.net.InternetDomainNameAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static com.google.common.net.InternetDomainNameAssert then(com.google.common.net.InternetDomainName actual) { + return new com.google.common.net.InternetDomainNameAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.AlignmentAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.AlignmentAssert then(org.assertj.examples.data.Alignment actual) { + return new org.assertj.examples.data.AlignmentAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.BasketBallPlayerAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.BasketBallPlayerAssert then(org.assertj.examples.data.BasketBallPlayer actual) { + return new org.assertj.examples.data.BasketBallPlayerAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.BookAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.BookAssert then(org.assertj.examples.data.Book actual) { + return new org.assertj.examples.data.BookAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.BookTitleAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.BookTitleAssert then(org.assertj.examples.data.Book.Title actual) { + return new org.assertj.examples.data.BookTitleAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.EmployeeAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.EmployeeAssert then(org.assertj.examples.data.Employee actual) { + return new org.assertj.examples.data.EmployeeAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.MagicalAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.MagicalAssert then(org.assertj.examples.data.Magical actual) { + return new org.assertj.examples.data.MagicalAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.MansionAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.MansionAssert then(org.assertj.examples.data.Mansion actual) { + return new org.assertj.examples.data.MansionAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.NameAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.NameAssert then(org.assertj.examples.data.Name actual) { + return new org.assertj.examples.data.NameAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.PersonAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.PersonAssert then(org.assertj.examples.data.Person actual) { + return new org.assertj.examples.data.PersonAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.RaceAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.RaceAssert then(org.assertj.examples.data.Race actual) { + return new org.assertj.examples.data.RaceAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.RingAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.RingAssert then(org.assertj.examples.data.Ring actual) { + return new org.assertj.examples.data.RingAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.TeamAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.TeamAssert then(org.assertj.examples.data.Team actual) { + return new org.assertj.examples.data.TeamAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.TolkienCharacterAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.TolkienCharacterAssert then(org.assertj.examples.data.TolkienCharacter actual) { + return new org.assertj.examples.data.TolkienCharacterAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug18.Dollar$Assert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug18.Dollar$Assert then(org.assertj.examples.data.bug18.Dollar$ actual) { + return new org.assertj.examples.data.bug18.Dollar$Assert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug26.WithGenericListTypeAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug26.WithGenericListTypeAssert then(org.assertj.examples.data.bug26.WithGenericListType actual) { + return new org.assertj.examples.data.bug26.WithGenericListTypeAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug27.MyIteratorWrapperAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug27.MyIteratorWrapperAssert then(org.assertj.examples.data.bug27.MyIteratorWrapper actual) { + return new org.assertj.examples.data.bug27.MyIteratorWrapperAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug27.MyModelClassAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug27.MyModelClassAssert then(org.assertj.examples.data.bug27.MyModelClass actual) { + return new org.assertj.examples.data.bug27.MyModelClassAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.bug27.MyModelClassMyBeanAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.bug27.MyModelClassMyBeanAssert then(org.assertj.examples.data.bug27.MyModelClass.MyBean actual) { + return new org.assertj.examples.data.bug27.MyModelClassMyBeanAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.movie.MovieAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.movie.MovieAssert then(org.assertj.examples.data.movie.Movie actual) { + return new org.assertj.examples.data.movie.MovieAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.movie.TeamAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.movie.TeamAssert then(org.assertj.examples.data.movie.Team actual) { + return new org.assertj.examples.data.movie.TeamAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.neo4j.DragonBallGraphAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.neo4j.DragonBallGraphAssert then(org.assertj.examples.data.neo4j.DragonBallGraph actual) { + return new org.assertj.examples.data.neo4j.DragonBallGraphAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.service.GameServiceAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.service.GameServiceAssert then(org.assertj.examples.data.service.GameService actual) { + return new org.assertj.examples.data.service.GameServiceAssert(actual); + } + + /** + * Creates a new instance of {@link org.assertj.examples.data.service.TeamManagerAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + */ + public static org.assertj.examples.data.service.TeamManagerAssert then(org.assertj.examples.data.service.TeamManager actual) { + return new org.assertj.examples.data.service.TeamManagerAssert(actual); + } + + /** + * Creates a new {@link BddAssertions}. + */ + protected BddAssertions() { + // empty + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/SoftAssertions.java b/assertions-examples/src/test/generated-assertions/org/assertj/SoftAssertions.java new file mode 100644 index 00000000..d9e95235 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/SoftAssertions.java @@ -0,0 +1,304 @@ +package org.assertj; + +import static org.assertj.core.groups.Properties.extractProperty; + +import java.util.List; +import org.assertj.core.internal.cglib.proxy.Enhancer; + +import org.assertj.core.api.ErrorCollector; +import org.assertj.core.api.SoftAssertionError; + +/** + * Entry point for assertions of different data types. Each method in this class is a static factory for the + * type-specific assertion objects. + */ +public class SoftAssertions { + + /** Collects error messages of all AssertionErrors thrown by the proxied method. */ + protected final ErrorCollector collector = new ErrorCollector(); + + /** Creates a new {@link SoftAssertions}. */ + public SoftAssertions() { + } + + /** + * Verifies that no proxied assertion methods have failed. + * + * @throws SoftAssertionError if any proxied assertion objects threw + */ + public void assertAll() { + List errors = collector.errors(); + if (!errors.isEmpty()) { + throw new SoftAssertionError(extractProperty("message", String.class).from(errors)); + } + } + + @SuppressWarnings("unchecked") + protected V proxy(Class assertClass, Class actualClass, T actual) { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(assertClass); + enhancer.setCallback(collector); + return (V) enhancer.create(new Class[] { actualClass }, new Object[] { actual }); + } + + /** + * Creates a new "soft" instance of {@link com.google.common.net.HostAndPortAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public com.google.common.net.HostAndPortAssert assertThat(com.google.common.net.HostAndPort actual) { + return proxy(com.google.common.net.HostAndPortAssert.class, com.google.common.net.HostAndPort.class, actual); + } + + /** + * Creates a new "soft" instance of {@link com.google.common.net.InetAddressesAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public com.google.common.net.InetAddressesAssert assertThat(com.google.common.net.InetAddresses actual) { + return proxy(com.google.common.net.InetAddressesAssert.class, com.google.common.net.InetAddresses.class, actual); + } + + /** + * Creates a new "soft" instance of {@link com.google.common.net.InternetDomainNameAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public com.google.common.net.InternetDomainNameAssert assertThat(com.google.common.net.InternetDomainName actual) { + return proxy(com.google.common.net.InternetDomainNameAssert.class, com.google.common.net.InternetDomainName.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.AlignmentAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.AlignmentAssert assertThat(org.assertj.examples.data.Alignment actual) { + return proxy(org.assertj.examples.data.AlignmentAssert.class, org.assertj.examples.data.Alignment.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.BasketBallPlayerAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.BasketBallPlayerAssert assertThat(org.assertj.examples.data.BasketBallPlayer actual) { + return proxy(org.assertj.examples.data.BasketBallPlayerAssert.class, org.assertj.examples.data.BasketBallPlayer.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.BookAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.BookAssert assertThat(org.assertj.examples.data.Book actual) { + return proxy(org.assertj.examples.data.BookAssert.class, org.assertj.examples.data.Book.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.BookTitleAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.BookTitleAssert assertThat(org.assertj.examples.data.Book.Title actual) { + return proxy(org.assertj.examples.data.BookTitleAssert.class, org.assertj.examples.data.Book.Title.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.EmployeeAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.EmployeeAssert assertThat(org.assertj.examples.data.Employee actual) { + return proxy(org.assertj.examples.data.EmployeeAssert.class, org.assertj.examples.data.Employee.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.MagicalAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.MagicalAssert assertThat(org.assertj.examples.data.Magical actual) { + return proxy(org.assertj.examples.data.MagicalAssert.class, org.assertj.examples.data.Magical.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.MansionAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.MansionAssert assertThat(org.assertj.examples.data.Mansion actual) { + return proxy(org.assertj.examples.data.MansionAssert.class, org.assertj.examples.data.Mansion.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.NameAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.NameAssert assertThat(org.assertj.examples.data.Name actual) { + return proxy(org.assertj.examples.data.NameAssert.class, org.assertj.examples.data.Name.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.PersonAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.PersonAssert assertThat(org.assertj.examples.data.Person actual) { + return proxy(org.assertj.examples.data.PersonAssert.class, org.assertj.examples.data.Person.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.RaceAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.RaceAssert assertThat(org.assertj.examples.data.Race actual) { + return proxy(org.assertj.examples.data.RaceAssert.class, org.assertj.examples.data.Race.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.RingAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.RingAssert assertThat(org.assertj.examples.data.Ring actual) { + return proxy(org.assertj.examples.data.RingAssert.class, org.assertj.examples.data.Ring.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.TeamAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.TeamAssert assertThat(org.assertj.examples.data.Team actual) { + return proxy(org.assertj.examples.data.TeamAssert.class, org.assertj.examples.data.Team.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.TolkienCharacterAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.TolkienCharacterAssert assertThat(org.assertj.examples.data.TolkienCharacter actual) { + return proxy(org.assertj.examples.data.TolkienCharacterAssert.class, org.assertj.examples.data.TolkienCharacter.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.bug18.Dollar$Assert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.bug18.Dollar$Assert assertThat(org.assertj.examples.data.bug18.Dollar$ actual) { + return proxy(org.assertj.examples.data.bug18.Dollar$Assert.class, org.assertj.examples.data.bug18.Dollar$.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.bug26.WithGenericListTypeAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.bug26.WithGenericListTypeAssert assertThat(org.assertj.examples.data.bug26.WithGenericListType actual) { + return proxy(org.assertj.examples.data.bug26.WithGenericListTypeAssert.class, org.assertj.examples.data.bug26.WithGenericListType.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.bug27.MyIteratorWrapperAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.bug27.MyIteratorWrapperAssert assertThat(org.assertj.examples.data.bug27.MyIteratorWrapper actual) { + return proxy(org.assertj.examples.data.bug27.MyIteratorWrapperAssert.class, org.assertj.examples.data.bug27.MyIteratorWrapper.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.bug27.MyModelClassAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.bug27.MyModelClassAssert assertThat(org.assertj.examples.data.bug27.MyModelClass actual) { + return proxy(org.assertj.examples.data.bug27.MyModelClassAssert.class, org.assertj.examples.data.bug27.MyModelClass.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.bug27.MyModelClassMyBeanAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.bug27.MyModelClassMyBeanAssert assertThat(org.assertj.examples.data.bug27.MyModelClass.MyBean actual) { + return proxy(org.assertj.examples.data.bug27.MyModelClassMyBeanAssert.class, org.assertj.examples.data.bug27.MyModelClass.MyBean.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.movie.MovieAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.movie.MovieAssert assertThat(org.assertj.examples.data.movie.Movie actual) { + return proxy(org.assertj.examples.data.movie.MovieAssert.class, org.assertj.examples.data.movie.Movie.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.movie.TeamAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.movie.TeamAssert assertThat(org.assertj.examples.data.movie.Team actual) { + return proxy(org.assertj.examples.data.movie.TeamAssert.class, org.assertj.examples.data.movie.Team.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.neo4j.DragonBallGraphAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.neo4j.DragonBallGraphAssert assertThat(org.assertj.examples.data.neo4j.DragonBallGraph actual) { + return proxy(org.assertj.examples.data.neo4j.DragonBallGraphAssert.class, org.assertj.examples.data.neo4j.DragonBallGraph.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.service.GameServiceAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.service.GameServiceAssert assertThat(org.assertj.examples.data.service.GameService actual) { + return proxy(org.assertj.examples.data.service.GameServiceAssert.class, org.assertj.examples.data.service.GameService.class, actual); + } + + /** + * Creates a new "soft" instance of {@link org.assertj.examples.data.service.TeamManagerAssert}. + * + * @param actual the actual value. + * @return the created "soft" assertion object. + */ + public org.assertj.examples.data.service.TeamManagerAssert assertThat(org.assertj.examples.data.service.TeamManager actual) { + return proxy(org.assertj.examples.data.service.TeamManagerAssert.class, org.assertj.examples.data.service.TeamManager.class, actual); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractAlignmentAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractAlignmentAssert.java new file mode 100644 index 00000000..01fe0149 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractAlignmentAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Alignment} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractAlignmentAssert, A extends Alignment> extends AbstractAssert { + + /** + * Creates a new {@link AbstractAlignmentAssert} to make assertions on actual Alignment. + * @param actual the Alignment we want to make assertions on. + */ + protected AbstractAlignmentAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBasketBallPlayerAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBasketBallPlayerAssert.java new file mode 100644 index 00000000..9387dcbb --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBasketBallPlayerAssert.java @@ -0,0 +1,309 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; +import org.assertj.core.api.Assertions; +import org.assertj.examples.exception.NameException; + + +/** + * Abstract base class for {@link BasketBallPlayer} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractBasketBallPlayerAssert, A extends BasketBallPlayer> extends AbstractAssert { + + /** + * Creates a new {@link AbstractBasketBallPlayerAssert} to make assertions on actual BasketBallPlayer. + * @param actual the BasketBallPlayer we want to make assertions on. + */ + protected AbstractBasketBallPlayerAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual BasketBallPlayer's assistsPerGame is equal to the given one. + * @param assistsPerGame the given assistsPerGame to compare the actual BasketBallPlayer's assistsPerGame to. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer's assistsPerGame is not equal to the given one. + */ + public S hasAssistsPerGame(int assistsPerGame) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected assistsPerGame of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // check + int actualAssistsPerGame = actual.getAssistsPerGame(); + if (actualAssistsPerGame != assistsPerGame) { + failWithMessage(assertjErrorMessage, actual, assistsPerGame, actualAssistsPerGame); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer's name is equal to the given one. + * @param name the given name to compare the actual BasketBallPlayer's name to. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer's name is not equal to the given one. + * @throws NameException if actual.getName() throws one. + */ + public S hasName(Name name) throws NameException { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected name of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + Name actualName = actual.getName(); + if (!org.assertj.core.util.Objects.areEqual(actualName, name)) { + failWithMessage(assertjErrorMessage, actual, name, actualName); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer's points contains the given int[] elements. + * @param points the given elements that should be contained in actual BasketBallPlayer's points. + * @return this assertion object. + * @throws AssertionError if the actual BasketBallPlayer's points does not contain all given int[] elements. + */ + public S hasPoints(int[]... points) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // check that given int[] varargs is not null. + if (points == null) throw new AssertionError("Expecting points parameter not to be null."); + + // check with standard error message, to set another message call: info.overridingErrorMessage("my error message"); + org.assertj.core.internal.Iterables.instance().assertContains(info, actual.getPoints(), points); + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer has no points. + * @return this assertion object. + * @throws AssertionError if the actual BasketBallPlayer's points is not empty. + */ + public S hasNoPoints() { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // we override the default error message with a more explicit one + String assertjErrorMessage = "\nExpected :\n <%s>\nnot to have points but had :\n <%s>"; + + // check + if (actual.getPoints().iterator().hasNext()) { + failWithMessage(assertjErrorMessage, actual, actual.getPoints()); + } + + // return the current assertion for method chaining + return myself; + } + + + /** + * Verifies that the actual BasketBallPlayer's pointsPerGame is equal to the given one. + * @param pointsPerGame the given pointsPerGame to compare the actual BasketBallPlayer's pointsPerGame to. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer's pointsPerGame is not equal to the given one. + */ + public S hasPointsPerGame(int pointsPerGame) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected pointsPerGame of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // check + int actualPointsPerGame = actual.getPointsPerGame(); + if (actualPointsPerGame != pointsPerGame) { + failWithMessage(assertjErrorMessage, actual, pointsPerGame, actualPointsPerGame); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer's reboundsPerGame is equal to the given one. + * @param reboundsPerGame the given reboundsPerGame to compare the actual BasketBallPlayer's reboundsPerGame to. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer's reboundsPerGame is not equal to the given one. + */ + public S hasReboundsPerGame(int reboundsPerGame) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected reboundsPerGame of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // check + int actualReboundsPerGame = actual.getReboundsPerGame(); + if (actualReboundsPerGame != reboundsPerGame) { + failWithMessage(assertjErrorMessage, actual, reboundsPerGame, actualReboundsPerGame); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer is rookie. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer is not rookie. + */ + public S isRookie() { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // check + if (!actual.isRookie()) { + failWithMessage("\nExpected actual BasketBallPlayer to be rookie but was not."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer is not rookie. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer is rookie. + */ + public S isNotRookie() { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // check + if (actual.isRookie()) { + failWithMessage("\nExpected actual BasketBallPlayer not to be rookie but was."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer's team is equal to the given one. + * @param team the given team to compare the actual BasketBallPlayer's team to. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer's team is not equal to the given one. + */ + public S hasTeam(String team) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected team of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualTeam = actual.getTeam(); + if (!org.assertj.core.util.Objects.areEqual(actualTeam, team)) { + failWithMessage(assertjErrorMessage, actual, team, actualTeam); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer's teamMates contains the given BasketBallPlayer elements. + * @param teamMates the given elements that should be contained in actual BasketBallPlayer's teamMates. + * @return this assertion object. + * @throws AssertionError if the actual BasketBallPlayer's teamMates does not contain all given BasketBallPlayer elements. + */ + public S hasTeamMates(BasketBallPlayer... teamMates) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // check that given BasketBallPlayer varargs is not null. + if (teamMates == null) throw new AssertionError("Expecting teamMates parameter not to be null."); + + // check with standard error message, to set another message call: info.overridingErrorMessage("my error message"); + org.assertj.core.internal.Iterables.instance().assertContains(info, actual.getTeamMates(), teamMates); + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer has no teamMates. + * @return this assertion object. + * @throws AssertionError if the actual BasketBallPlayer's teamMates is not empty. + */ + public S hasNoTeamMates() { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + // we override the default error message with a more explicit one + String assertjErrorMessage = "\nExpected :\n <%s>\nnot to have teamMates but had :\n <%s>"; + + // check + if (actual.getTeamMates().iterator().hasNext()) { + failWithMessage(assertjErrorMessage, actual, actual.getTeamMates()); + } + + // return the current assertion for method chaining + return myself; + } + + + /** + * Verifies that the actual BasketBallPlayer's weight is close to the given value by less than the given offset. + *

+ * If difference is equal to the offset value, assertion is considered successful. + * @param weight the value to compare the actual BasketBallPlayer's weight to. + * @param offset the given offset. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer's weight is not close enough to the given value. + */ + public S hasWeight(float weight, float offset) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + float actualWeight = actual.getWeight(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = String.format("\nExpected weight:\n <%s>\nto be close to:\n <%s>\nby less than <%s> but difference was <%s>", + actualWeight, weight, offset, Math.abs(weight - actualWeight)); + + // check + Assertions.assertThat(actualWeight).overridingErrorMessage(assertjErrorMessage).isCloseTo(weight, Assertions.within(offset)); + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual BasketBallPlayer's size is close to the given value by less than the given offset. + *

+ * If difference is equal to the offset value, assertion is considered successful. + * @param size the value to compare the actual BasketBallPlayer's size to. + * @param offset the given offset. + * @return this assertion object. + * @throws AssertionError - if the actual BasketBallPlayer's size is not close enough to the given value. + */ + public S hasSize(double size, double offset) { + // check that actual BasketBallPlayer we want to make assertions on is not null. + isNotNull(); + + double actualSize = actual.size; + + // overrides the default error message with a more explicit one + String assertjErrorMessage = String.format("\nExpected size:\n <%s>\nto be close to:\n <%s>\nby less than <%s> but difference was <%s>", + actualSize, size, offset, Math.abs(size - actualSize)); + + // check + Assertions.assertThat(actualSize).overridingErrorMessage(assertjErrorMessage).isCloseTo(size, Assertions.within(offset)); + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBookAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBookAssert.java new file mode 100644 index 00000000..2aba0c27 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBookAssert.java @@ -0,0 +1,42 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Book} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractBookAssert, A extends Book> extends AbstractAssert { + + /** + * Creates a new {@link AbstractBookAssert} to make assertions on actual Book. + * @param actual the Book we want to make assertions on. + */ + protected AbstractBookAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Book's title is equal to the given one. + * @param title the given title to compare the actual Book's title to. + * @return this assertion object. + * @throws AssertionError - if the actual Book's title is not equal to the given one. + */ + public S hasTitle(Book.Title title) { + // check that actual Book we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected title of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + Book.Title actualTitle = actual.getTitle(); + if (!org.assertj.core.util.Objects.areEqual(actualTitle, title)) { + failWithMessage(assertjErrorMessage, actual, title, actualTitle); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBookTitleAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBookTitleAssert.java new file mode 100644 index 00000000..5f814957 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractBookTitleAssert.java @@ -0,0 +1,42 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Book.Title} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractBookTitleAssert, A extends Book.Title> extends AbstractAssert { + + /** + * Creates a new {@link AbstractBookTitleAssert} to make assertions on actual Book.Title. + * @param actual the Book.Title we want to make assertions on. + */ + protected AbstractBookTitleAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Book.Title's title is equal to the given one. + * @param title the given title to compare the actual Book.Title's title to. + * @return this assertion object. + * @throws AssertionError - if the actual Book.Title's title is not equal to the given one. + */ + public S hasTitle(String title) { + // check that actual Book.Title we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected title of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualTitle = actual.getTitle(); + if (!org.assertj.core.util.Objects.areEqual(actualTitle, title)) { + failWithMessage(assertjErrorMessage, actual, title, actualTitle); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractEmployeeAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractEmployeeAssert.java new file mode 100644 index 00000000..999fbfea --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractEmployeeAssert.java @@ -0,0 +1,41 @@ +package org.assertj.examples.data; + + + +/** + * Abstract base class for {@link Employee} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractEmployeeAssert, A extends Employee> extends AbstractPersonAssert { + + /** + * Creates a new {@link AbstractEmployeeAssert} to make assertions on actual Employee. + * @param actual the Employee we want to make assertions on. + */ + protected AbstractEmployeeAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Employee's company is equal to the given one. + * @param company the given company to compare the actual Employee's company to. + * @return this assertion object. + * @throws AssertionError - if the actual Employee's company is not equal to the given one. + */ + public S hasCompany(String company) { + // check that actual Employee we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected company of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualCompany = actual.getCompany(); + if (!org.assertj.core.util.Objects.areEqual(actualCompany, company)) { + failWithMessage(assertjErrorMessage, actual, company, actualCompany); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractEmployeeTitleAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractEmployeeTitleAssert.java new file mode 100644 index 00000000..f369f99e --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractEmployeeTitleAssert.java @@ -0,0 +1,42 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Employee.Title} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractEmployeeTitleAssert, A extends Employee.Title> extends AbstractAssert { + + /** + * Creates a new {@link AbstractEmployeeTitleAssert} to make assertions on actual Employee.Title. + * @param actual the Employee.Title we want to make assertions on. + */ + protected AbstractEmployeeTitleAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Employee.Title's position is equal to the given one. + * @param position the given position to compare the actual Employee.Title's position to. + * @return this assertion object. + * @throws AssertionError - if the actual Employee.Title's position is not equal to the given one. + */ + public S hasPosition(String position) { + // check that actual Employee.Title we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected position of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualPosition = actual.getPosition(); + if (!org.assertj.core.util.Objects.areEqual(actualPosition, position)) { + failWithMessage(assertjErrorMessage, actual, position, actualPosition); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractMagicalAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractMagicalAssert.java new file mode 100644 index 00000000..214b072d --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractMagicalAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Magical} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractMagicalAssert, A extends Magical> extends AbstractAssert { + + /** + * Creates a new {@link AbstractMagicalAssert} to make assertions on actual Magical. + * @param actual the Magical we want to make assertions on. + */ + protected AbstractMagicalAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractMansionAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractMansionAssert.java new file mode 100644 index 00000000..df7aaa95 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractMansionAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Mansion} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractMansionAssert, A extends Mansion> extends AbstractAssert { + + /** + * Creates a new {@link AbstractMansionAssert} to make assertions on actual Mansion. + * @param actual the Mansion we want to make assertions on. + */ + protected AbstractMansionAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractNameAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractNameAssert.java new file mode 100644 index 00000000..5c77f5a2 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractNameAssert.java @@ -0,0 +1,65 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Name} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractNameAssert, A extends Name> extends AbstractAssert { + + /** + * Creates a new {@link AbstractNameAssert} to make assertions on actual Name. + * @param actual the Name we want to make assertions on. + */ + protected AbstractNameAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Name's first is equal to the given one. + * @param first the given first to compare the actual Name's first to. + * @return this assertion object. + * @throws AssertionError - if the actual Name's first is not equal to the given one. + */ + public S hasFirst(String first) { + // check that actual Name we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected first of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualFirst = actual.getFirst(); + if (!org.assertj.core.util.Objects.areEqual(actualFirst, first)) { + failWithMessage(assertjErrorMessage, actual, first, actualFirst); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Name's last is equal to the given one. + * @param last the given last to compare the actual Name's last to. + * @return this assertion object. + * @throws AssertionError - if the actual Name's last is not equal to the given one. + */ + public S hasLast(String last) { + // check that actual Name we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected last of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualLast = actual.getLast(); + if (!org.assertj.core.util.Objects.areEqual(actualLast, last)) { + failWithMessage(assertjErrorMessage, actual, last, actualLast); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractPersonAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractPersonAssert.java new file mode 100644 index 00000000..c44c928f --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractPersonAssert.java @@ -0,0 +1,65 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Person} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractPersonAssert, A extends Person> extends AbstractAssert { + + /** + * Creates a new {@link AbstractPersonAssert} to make assertions on actual Person. + * @param actual the Person we want to make assertions on. + */ + protected AbstractPersonAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Person's age is equal to the given one. + * @param age the given age to compare the actual Person's age to. + * @return this assertion object. + * @throws AssertionError - if the actual Person's age is not equal to the given one. + */ + public S hasAge(int age) { + // check that actual Person we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected age of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // check + int actualAge = actual.getAge(); + if (actualAge != age) { + failWithMessage(assertjErrorMessage, actual, age, actualAge); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Person's name is equal to the given one. + * @param name the given name to compare the actual Person's name to. + * @return this assertion object. + * @throws AssertionError - if the actual Person's name is not equal to the given one. + */ + public S hasName(String name) { + // check that actual Person we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected name of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualName = actual.getName(); + if (!org.assertj.core.util.Objects.areEqual(actualName, name)) { + failWithMessage(assertjErrorMessage, actual, name, actualName); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractRaceAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractRaceAssert.java new file mode 100644 index 00000000..ee8a23f6 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractRaceAssert.java @@ -0,0 +1,101 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Race} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractRaceAssert, A extends Race> extends AbstractAssert { + + /** + * Creates a new {@link AbstractRaceAssert} to make assertions on actual Race. + * @param actual the Race we want to make assertions on. + */ + protected AbstractRaceAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Race's alignment is equal to the given one. + * @param alignment the given alignment to compare the actual Race's alignment to. + * @return this assertion object. + * @throws AssertionError - if the actual Race's alignment is not equal to the given one. + */ + public S hasAlignment(Alignment alignment) { + // check that actual Race we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected alignment of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + Alignment actualAlignment = actual.getAlignment(); + if (!org.assertj.core.util.Objects.areEqual(actualAlignment, alignment)) { + failWithMessage(assertjErrorMessage, actual, alignment, actualAlignment); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Race's name is equal to the given one. + * @param name the given name to compare the actual Race's name to. + * @return this assertion object. + * @throws AssertionError - if the actual Race's name is not equal to the given one. + */ + public S hasName(String name) { + // check that actual Race we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected name of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualName = actual.getName(); + if (!org.assertj.core.util.Objects.areEqual(actualName, name)) { + failWithMessage(assertjErrorMessage, actual, name, actualName); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Race is immortal. + * @return this assertion object. + * @throws AssertionError - if the actual Race is not immortal. + */ + public S isImmortal() { + // check that actual Race we want to make assertions on is not null. + isNotNull(); + + // check + if (!actual.immortal) { + failWithMessage("\nExpected actual Race to be immortal but was not."); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Race is not immortal. + * @return this assertion object. + * @throws AssertionError - if the actual Race is immortal. + */ + public S isNotImmortal() { + // check that actual Race we want to make assertions on is not null. + isNotNull(); + + // check + if (actual.immortal) { + failWithMessage("\nExpected actual Race not to be immortal but was."); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractRingAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractRingAssert.java new file mode 100644 index 00000000..48fea9aa --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractRingAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Ring} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractRingAssert, A extends Ring> extends AbstractAssert { + + /** + * Creates a new {@link AbstractRingAssert} to make assertions on actual Ring. + * @param actual the Ring we want to make assertions on. + */ + protected AbstractRingAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractTeamAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractTeamAssert.java new file mode 100644 index 00000000..d0febf00 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractTeamAssert.java @@ -0,0 +1,61 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Team} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractTeamAssert, A extends Team> extends AbstractAssert { + + /** + * Creates a new {@link AbstractTeamAssert} to make assertions on actual Team. + * @param actual the Team we want to make assertions on. + */ + protected AbstractTeamAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Team's players contains the given BasketBallPlayer elements. + * @param players the given elements that should be contained in actual Team's players. + * @return this assertion object. + * @throws AssertionError if the actual Team's players does not contain all given BasketBallPlayer elements. + */ + public S hasPlayers(BasketBallPlayer... players) { + // check that actual Team we want to make assertions on is not null. + isNotNull(); + + // check that given BasketBallPlayer varargs is not null. + if (players == null) throw new AssertionError("Expecting players parameter not to be null."); + + // check with standard error message, to set another message call: info.overridingErrorMessage("my error message"); + org.assertj.core.internal.Iterables.instance().assertContains(info, actual.getPlayers(), players); + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Team has no players. + * @return this assertion object. + * @throws AssertionError if the actual Team's players is not empty. + */ + public S hasNoPlayers() { + // check that actual Team we want to make assertions on is not null. + isNotNull(); + + // we override the default error message with a more explicit one + String assertjErrorMessage = "\nExpected :\n <%s>\nnot to have players but had :\n <%s>"; + + // check + if (actual.getPlayers().iterator().hasNext()) { + failWithMessage(assertjErrorMessage, actual, actual.getPlayers()); + } + + // return the current assertion for method chaining + return myself; + } + + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractTolkienCharacterAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractTolkienCharacterAssert.java new file mode 100644 index 00000000..cd79e2c8 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AbstractTolkienCharacterAssert.java @@ -0,0 +1,88 @@ +package org.assertj.examples.data; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link TolkienCharacter} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractTolkienCharacterAssert, A extends TolkienCharacter> extends AbstractAssert { + + /** + * Creates a new {@link AbstractTolkienCharacterAssert} to make assertions on actual TolkienCharacter. + * @param actual the TolkienCharacter we want to make assertions on. + */ + protected AbstractTolkienCharacterAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual TolkienCharacter's name is equal to the given one. + * @param name the given name to compare the actual TolkienCharacter's name to. + * @return this assertion object. + * @throws AssertionError - if the actual TolkienCharacter's name is not equal to the given one. + */ + public S hasName(String name) { + // check that actual TolkienCharacter we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected name of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualName = actual.getName(); + if (!org.assertj.core.util.Objects.areEqual(actualName, name)) { + failWithMessage(assertjErrorMessage, actual, name, actualName); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual TolkienCharacter's race is equal to the given one. + * @param race the given race to compare the actual TolkienCharacter's race to. + * @return this assertion object. + * @throws AssertionError - if the actual TolkienCharacter's race is not equal to the given one. + */ + public S hasRace(Race race) { + // check that actual TolkienCharacter we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected race of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + Race actualRace = actual.getRace(); + if (!org.assertj.core.util.Objects.areEqual(actualRace, race)) { + failWithMessage(assertjErrorMessage, actual, race, actualRace); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual TolkienCharacter's age is equal to the given one. + * @param age the given age to compare the actual TolkienCharacter's age to. + * @return this assertion object. + * @throws AssertionError - if the actual TolkienCharacter's age is not equal to the given one. + */ + public S hasAge(int age) { + // check that actual TolkienCharacter we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected age of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // check + int actualAge = actual.age; + if (actualAge != age) { + failWithMessage(assertjErrorMessage, actual, age, actualAge); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AlignmentAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AlignmentAssert.java new file mode 100644 index 00000000..9b6b0ed5 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/AlignmentAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Alignment} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractAlignmentAssert} instead. + */ +public class AlignmentAssert extends AbstractAlignmentAssert { + + /** + * Creates a new {@link AlignmentAssert} to make assertions on actual Alignment. + * @param actual the Alignment we want to make assertions on. + */ + public AlignmentAssert(Alignment actual) { + super(actual, AlignmentAssert.class); + } + + /** + * An entry point for AlignmentAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myAlignment) and get specific assertion with code completion. + * @param actual the Alignment we want to make assertions on. + * @return a new {@link AlignmentAssert} + */ + public static AlignmentAssert assertThat(Alignment actual) { + return new AlignmentAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BasketBallPlayerAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BasketBallPlayerAssert.java new file mode 100644 index 00000000..97503e43 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BasketBallPlayerAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link BasketBallPlayer} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractBasketBallPlayerAssert} instead. + */ +public class BasketBallPlayerAssert extends AbstractBasketBallPlayerAssert { + + /** + * Creates a new {@link BasketBallPlayerAssert} to make assertions on actual BasketBallPlayer. + * @param actual the BasketBallPlayer we want to make assertions on. + */ + public BasketBallPlayerAssert(BasketBallPlayer actual) { + super(actual, BasketBallPlayerAssert.class); + } + + /** + * An entry point for BasketBallPlayerAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myBasketBallPlayer) and get specific assertion with code completion. + * @param actual the BasketBallPlayer we want to make assertions on. + * @return a new {@link BasketBallPlayerAssert} + */ + public static BasketBallPlayerAssert assertThat(BasketBallPlayer actual) { + return new BasketBallPlayerAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BookAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BookAssert.java new file mode 100644 index 00000000..3885d986 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BookAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Book} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractBookAssert} instead. + */ +public class BookAssert extends AbstractBookAssert { + + /** + * Creates a new {@link BookAssert} to make assertions on actual Book. + * @param actual the Book we want to make assertions on. + */ + public BookAssert(Book actual) { + super(actual, BookAssert.class); + } + + /** + * An entry point for BookAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myBook) and get specific assertion with code completion. + * @param actual the Book we want to make assertions on. + * @return a new {@link BookAssert} + */ + public static BookAssert assertThat(Book actual) { + return new BookAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BookTitleAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BookTitleAssert.java new file mode 100644 index 00000000..6db9c10b --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/BookTitleAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Book.Title} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractBookTitleAssert} instead. + */ +public class BookTitleAssert extends AbstractBookTitleAssert { + + /** + * Creates a new {@link BookTitleAssert} to make assertions on actual Book.Title. + * @param actual the Book.Title we want to make assertions on. + */ + public BookTitleAssert(Book.Title actual) { + super(actual, BookTitleAssert.class); + } + + /** + * An entry point for BookTitleAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myBook.Title) and get specific assertion with code completion. + * @param actual the Book.Title we want to make assertions on. + * @return a new {@link BookTitleAssert} + */ + public static BookTitleAssert assertThat(Book.Title actual) { + return new BookTitleAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/EmployeeAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/EmployeeAssert.java new file mode 100644 index 00000000..84ee6b12 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/EmployeeAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Employee} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractEmployeeAssert} instead. + */ +public class EmployeeAssert extends AbstractEmployeeAssert { + + /** + * Creates a new {@link EmployeeAssert} to make assertions on actual Employee. + * @param actual the Employee we want to make assertions on. + */ + public EmployeeAssert(Employee actual) { + super(actual, EmployeeAssert.class); + } + + /** + * An entry point for EmployeeAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myEmployee) and get specific assertion with code completion. + * @param actual the Employee we want to make assertions on. + * @return a new {@link EmployeeAssert} + */ + public static EmployeeAssert assertThat(Employee actual) { + return new EmployeeAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/EmployeeTitleAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/EmployeeTitleAssert.java new file mode 100644 index 00000000..93d14887 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/EmployeeTitleAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Employee.Title} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractEmployeeTitleAssert} instead. + */ +public class EmployeeTitleAssert extends AbstractEmployeeTitleAssert { + + /** + * Creates a new {@link EmployeeTitleAssert} to make assertions on actual Employee.Title. + * @param actual the Employee.Title we want to make assertions on. + */ + public EmployeeTitleAssert(Employee.Title actual) { + super(actual, EmployeeTitleAssert.class); + } + + /** + * An entry point for EmployeeTitleAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myEmployee.Title) and get specific assertion with code completion. + * @param actual the Employee.Title we want to make assertions on. + * @return a new {@link EmployeeTitleAssert} + */ + public static EmployeeTitleAssert assertThat(Employee.Title actual) { + return new EmployeeTitleAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/MagicalAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/MagicalAssert.java new file mode 100644 index 00000000..61c97355 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/MagicalAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Magical} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractMagicalAssert} instead. + */ +public class MagicalAssert extends AbstractMagicalAssert { + + /** + * Creates a new {@link MagicalAssert} to make assertions on actual Magical. + * @param actual the Magical we want to make assertions on. + */ + public MagicalAssert(Magical actual) { + super(actual, MagicalAssert.class); + } + + /** + * An entry point for MagicalAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myMagical) and get specific assertion with code completion. + * @param actual the Magical we want to make assertions on. + * @return a new {@link MagicalAssert} + */ + public static MagicalAssert assertThat(Magical actual) { + return new MagicalAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/MansionAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/MansionAssert.java new file mode 100644 index 00000000..e119a573 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/MansionAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Mansion} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractMansionAssert} instead. + */ +public class MansionAssert extends AbstractMansionAssert { + + /** + * Creates a new {@link MansionAssert} to make assertions on actual Mansion. + * @param actual the Mansion we want to make assertions on. + */ + public MansionAssert(Mansion actual) { + super(actual, MansionAssert.class); + } + + /** + * An entry point for MansionAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myMansion) and get specific assertion with code completion. + * @param actual the Mansion we want to make assertions on. + * @return a new {@link MansionAssert} + */ + public static MansionAssert assertThat(Mansion actual) { + return new MansionAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/NameAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/NameAssert.java new file mode 100644 index 00000000..95d9c4c3 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/NameAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Name} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractNameAssert} instead. + */ +public class NameAssert extends AbstractNameAssert { + + /** + * Creates a new {@link NameAssert} to make assertions on actual Name. + * @param actual the Name we want to make assertions on. + */ + public NameAssert(Name actual) { + super(actual, NameAssert.class); + } + + /** + * An entry point for NameAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myName) and get specific assertion with code completion. + * @param actual the Name we want to make assertions on. + * @return a new {@link NameAssert} + */ + public static NameAssert assertThat(Name actual) { + return new NameAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/PersonAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/PersonAssert.java new file mode 100644 index 00000000..8a3df173 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/PersonAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Person} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractPersonAssert} instead. + */ +public class PersonAssert extends AbstractPersonAssert { + + /** + * Creates a new {@link PersonAssert} to make assertions on actual Person. + * @param actual the Person we want to make assertions on. + */ + public PersonAssert(Person actual) { + super(actual, PersonAssert.class); + } + + /** + * An entry point for PersonAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myPerson) and get specific assertion with code completion. + * @param actual the Person we want to make assertions on. + * @return a new {@link PersonAssert} + */ + public static PersonAssert assertThat(Person actual) { + return new PersonAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/RaceAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/RaceAssert.java new file mode 100644 index 00000000..44e3a154 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/RaceAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Race} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractRaceAssert} instead. + */ +public class RaceAssert extends AbstractRaceAssert { + + /** + * Creates a new {@link RaceAssert} to make assertions on actual Race. + * @param actual the Race we want to make assertions on. + */ + public RaceAssert(Race actual) { + super(actual, RaceAssert.class); + } + + /** + * An entry point for RaceAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myRace) and get specific assertion with code completion. + * @param actual the Race we want to make assertions on. + * @return a new {@link RaceAssert} + */ + public static RaceAssert assertThat(Race actual) { + return new RaceAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/RingAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/RingAssert.java new file mode 100644 index 00000000..c83acf3b --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/RingAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Ring} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractRingAssert} instead. + */ +public class RingAssert extends AbstractRingAssert { + + /** + * Creates a new {@link RingAssert} to make assertions on actual Ring. + * @param actual the Ring we want to make assertions on. + */ + public RingAssert(Ring actual) { + super(actual, RingAssert.class); + } + + /** + * An entry point for RingAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myRing) and get specific assertion with code completion. + * @param actual the Ring we want to make assertions on. + * @return a new {@link RingAssert} + */ + public static RingAssert assertThat(Ring actual) { + return new RingAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/TeamAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/TeamAssert.java new file mode 100644 index 00000000..249876be --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/TeamAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link Team} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractTeamAssert} instead. + */ +public class TeamAssert extends AbstractTeamAssert { + + /** + * Creates a new {@link TeamAssert} to make assertions on actual Team. + * @param actual the Team we want to make assertions on. + */ + public TeamAssert(Team actual) { + super(actual, TeamAssert.class); + } + + /** + * An entry point for TeamAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myTeam) and get specific assertion with code completion. + * @param actual the Team we want to make assertions on. + * @return a new {@link TeamAssert} + */ + public static TeamAssert assertThat(Team actual) { + return new TeamAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/TolkienCharacterAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/TolkienCharacterAssert.java new file mode 100644 index 00000000..57022725 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/TolkienCharacterAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data; + + +/** + * {@link TolkienCharacter} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractTolkienCharacterAssert} instead. + */ +public class TolkienCharacterAssert extends AbstractTolkienCharacterAssert { + + /** + * Creates a new {@link TolkienCharacterAssert} to make assertions on actual TolkienCharacter. + * @param actual the TolkienCharacter we want to make assertions on. + */ + public TolkienCharacterAssert(TolkienCharacter actual) { + super(actual, TolkienCharacterAssert.class); + } + + /** + * An entry point for TolkienCharacterAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myTolkienCharacter) and get specific assertion with code completion. + * @param actual the TolkienCharacter we want to make assertions on. + * @return a new {@link TolkienCharacterAssert} + */ + public static TolkienCharacterAssert assertThat(TolkienCharacter actual) { + return new TolkienCharacterAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug18/AbstractDollar$Assert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug18/AbstractDollar$Assert.java new file mode 100644 index 00000000..a5bcb9b5 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug18/AbstractDollar$Assert.java @@ -0,0 +1,42 @@ +package org.assertj.examples.data.bug18; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Dollar$} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractDollar$Assert, A extends Dollar$> extends AbstractAssert { + + /** + * Creates a new {@link AbstractDollar$Assert} to make assertions on actual Dollar$. + * @param actual the Dollar$ we want to make assertions on. + */ + protected AbstractDollar$Assert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Dollar$'s test is equal to the given one. + * @param test the given test to compare the actual Dollar$'s test to. + * @return this assertion object. + * @throws AssertionError - if the actual Dollar$'s test is not equal to the given one. + */ + public S hasTest(String test) { + // check that actual Dollar$ we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected test of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualTest = actual.test; + if (!org.assertj.core.util.Objects.areEqual(actualTest, test)) { + failWithMessage(assertjErrorMessage, actual, test, actualTest); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug18/Dollar$Assert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug18/Dollar$Assert.java new file mode 100644 index 00000000..1fa24cb0 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug18/Dollar$Assert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.bug18; + + +/** + * {@link Dollar$} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractDollar$Assert} instead. + */ +public class Dollar$Assert extends AbstractDollar$Assert { + + /** + * Creates a new {@link Dollar$Assert} to make assertions on actual Dollar$. + * @param actual the Dollar$ we want to make assertions on. + */ + public Dollar$Assert(Dollar$ actual) { + super(actual, Dollar$Assert.class); + } + + /** + * An entry point for Dollar$Assert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myDollar$) and get specific assertion with code completion. + * @param actual the Dollar$ we want to make assertions on. + * @return a new {@link Dollar$Assert} + */ + public static Dollar$Assert assertThat(Dollar$ actual) { + return new Dollar$Assert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug26/AbstractWithGenericListTypeAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug26/AbstractWithGenericListTypeAssert.java new file mode 100644 index 00000000..c5d56482 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug26/AbstractWithGenericListTypeAssert.java @@ -0,0 +1,62 @@ +package org.assertj.examples.data.bug26; + +import org.assertj.core.api.AbstractAssert; +import org.assertj.examples.data.movie.Movie; + + +/** + * Abstract base class for {@link WithGenericListType} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractWithGenericListTypeAssert, A extends WithGenericListType> extends AbstractAssert { + + /** + * Creates a new {@link AbstractWithGenericListTypeAssert} to make assertions on actual WithGenericListType. + * @param actual the WithGenericListType we want to make assertions on. + */ + protected AbstractWithGenericListTypeAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual WithGenericListType's movies contains the given Movie elements. + * @param movies the given elements that should be contained in actual WithGenericListType's movies. + * @return this assertion object. + * @throws AssertionError if the actual WithGenericListType's movies does not contain all given Movie elements. + */ + public S hasMovies(Movie... movies) { + // check that actual WithGenericListType we want to make assertions on is not null. + isNotNull(); + + // check that given Movie varargs is not null. + if (movies == null) throw new AssertionError("Expecting movies parameter not to be null."); + + // check with standard error message, to set another message call: info.overridingErrorMessage("my error message"); + org.assertj.core.internal.Iterables.instance().assertContains(info, actual.movies, movies); + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual WithGenericListType has no movies. + * @return this assertion object. + * @throws AssertionError if the actual WithGenericListType's movies is not empty. + */ + public S hasNoMovies() { + // check that actual WithGenericListType we want to make assertions on is not null. + isNotNull(); + + // we override the default error message with a more explicit one + String assertjErrorMessage = "\nExpected :\n <%s>\nnot to have movies but had :\n <%s>"; + + // check + if (actual.movies.iterator().hasNext()) { + failWithMessage(assertjErrorMessage, actual, actual.movies); + } + + // return the current assertion for method chaining + return myself; + } + + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug26/WithGenericListTypeAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug26/WithGenericListTypeAssert.java new file mode 100644 index 00000000..473d2133 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug26/WithGenericListTypeAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.bug26; + + +/** + * {@link WithGenericListType} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractWithGenericListTypeAssert} instead. + */ +public class WithGenericListTypeAssert extends AbstractWithGenericListTypeAssert { + + /** + * Creates a new {@link WithGenericListTypeAssert} to make assertions on actual WithGenericListType. + * @param actual the WithGenericListType we want to make assertions on. + */ + public WithGenericListTypeAssert(WithGenericListType actual) { + super(actual, WithGenericListTypeAssert.class); + } + + /** + * An entry point for WithGenericListTypeAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myWithGenericListType) and get specific assertion with code completion. + * @param actual the WithGenericListType we want to make assertions on. + * @return a new {@link WithGenericListTypeAssert} + */ + public static WithGenericListTypeAssert assertThat(WithGenericListType actual) { + return new WithGenericListTypeAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyIteratorWrapperAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyIteratorWrapperAssert.java new file mode 100644 index 00000000..a88dad8a --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyIteratorWrapperAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data.bug27; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link MyIteratorWrapper} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractMyIteratorWrapperAssert, A extends MyIteratorWrapper> extends AbstractAssert { + + /** + * Creates a new {@link AbstractMyIteratorWrapperAssert} to make assertions on actual MyIteratorWrapper. + * @param actual the MyIteratorWrapper we want to make assertions on. + */ + protected AbstractMyIteratorWrapperAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyModelClassAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyModelClassAssert.java new file mode 100644 index 00000000..30a223ee --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyModelClassAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data.bug27; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link MyModelClass} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractMyModelClassAssert, A extends MyModelClass> extends AbstractAssert { + + /** + * Creates a new {@link AbstractMyModelClassAssert} to make assertions on actual MyModelClass. + * @param actual the MyModelClass we want to make assertions on. + */ + protected AbstractMyModelClassAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyModelClassMyBeanAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyModelClassMyBeanAssert.java new file mode 100644 index 00000000..bf36762f --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/AbstractMyModelClassMyBeanAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data.bug27; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link MyModelClass.MyBean} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractMyModelClassMyBeanAssert, A extends MyModelClass.MyBean> extends AbstractAssert { + + /** + * Creates a new {@link AbstractMyModelClassMyBeanAssert} to make assertions on actual MyModelClass.MyBean. + * @param actual the MyModelClass.MyBean we want to make assertions on. + */ + protected AbstractMyModelClassMyBeanAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyIteratorWrapperAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyIteratorWrapperAssert.java new file mode 100644 index 00000000..b875df1c --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyIteratorWrapperAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.bug27; + + +/** + * {@link MyIteratorWrapper} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractMyIteratorWrapperAssert} instead. + */ +public class MyIteratorWrapperAssert extends AbstractMyIteratorWrapperAssert { + + /** + * Creates a new {@link MyIteratorWrapperAssert} to make assertions on actual MyIteratorWrapper. + * @param actual the MyIteratorWrapper we want to make assertions on. + */ + public MyIteratorWrapperAssert(MyIteratorWrapper actual) { + super(actual, MyIteratorWrapperAssert.class); + } + + /** + * An entry point for MyIteratorWrapperAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myMyIteratorWrapper) and get specific assertion with code completion. + * @param actual the MyIteratorWrapper we want to make assertions on. + * @return a new {@link MyIteratorWrapperAssert} + */ + public static MyIteratorWrapperAssert assertThat(MyIteratorWrapper actual) { + return new MyIteratorWrapperAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyModelClassAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyModelClassAssert.java new file mode 100644 index 00000000..b8fd9f2a --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyModelClassAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.bug27; + + +/** + * {@link MyModelClass} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractMyModelClassAssert} instead. + */ +public class MyModelClassAssert extends AbstractMyModelClassAssert { + + /** + * Creates a new {@link MyModelClassAssert} to make assertions on actual MyModelClass. + * @param actual the MyModelClass we want to make assertions on. + */ + public MyModelClassAssert(MyModelClass actual) { + super(actual, MyModelClassAssert.class); + } + + /** + * An entry point for MyModelClassAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myMyModelClass) and get specific assertion with code completion. + * @param actual the MyModelClass we want to make assertions on. + * @return a new {@link MyModelClassAssert} + */ + public static MyModelClassAssert assertThat(MyModelClass actual) { + return new MyModelClassAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyModelClassMyBeanAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyModelClassMyBeanAssert.java new file mode 100644 index 00000000..10aa52e2 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/bug27/MyModelClassMyBeanAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.bug27; + + +/** + * {@link MyModelClass.MyBean} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractMyModelClassMyBeanAssert} instead. + */ +public class MyModelClassMyBeanAssert extends AbstractMyModelClassMyBeanAssert { + + /** + * Creates a new {@link MyModelClassMyBeanAssert} to make assertions on actual MyModelClass.MyBean. + * @param actual the MyModelClass.MyBean we want to make assertions on. + */ + public MyModelClassMyBeanAssert(MyModelClass.MyBean actual) { + super(actual, MyModelClassMyBeanAssert.class); + } + + /** + * An entry point for MyModelClassMyBeanAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myMyModelClass.MyBean) and get specific assertion with code completion. + * @param actual the MyModelClass.MyBean we want to make assertions on. + * @return a new {@link MyModelClassMyBeanAssert} + */ + public static MyModelClassMyBeanAssert assertThat(MyModelClass.MyBean actual) { + return new MyModelClassMyBeanAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/AbstractMovieAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/AbstractMovieAssert.java new file mode 100644 index 00000000..84cefd76 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/AbstractMovieAssert.java @@ -0,0 +1,66 @@ +package org.assertj.examples.data.movie; + +import java.util.Date; +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Movie} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractMovieAssert, A extends Movie> extends AbstractAssert { + + /** + * Creates a new {@link AbstractMovieAssert} to make assertions on actual Movie. + * @param actual the Movie we want to make assertions on. + */ + protected AbstractMovieAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Movie's releaseDate is equal to the given one. + * @param releaseDate the given releaseDate to compare the actual Movie's releaseDate to. + * @return this assertion object. + * @throws AssertionError - if the actual Movie's releaseDate is not equal to the given one. + */ + public S hasReleaseDate(Date releaseDate) { + // check that actual Movie we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected releaseDate of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + Date actualReleaseDate = actual.getReleaseDate(); + if (!org.assertj.core.util.Objects.areEqual(actualReleaseDate, releaseDate)) { + failWithMessage(assertjErrorMessage, actual, releaseDate, actualReleaseDate); + } + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Movie's title is equal to the given one. + * @param title the given title to compare the actual Movie's title to. + * @return this assertion object. + * @throws AssertionError - if the actual Movie's title is not equal to the given one. + */ + public S hasTitle(String title) { + // check that actual Movie we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpected title of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + String actualTitle = actual.getTitle(); + if (!org.assertj.core.util.Objects.areEqual(actualTitle, title)) { + failWithMessage(assertjErrorMessage, actual, title, actualTitle); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/AbstractTeamAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/AbstractTeamAssert.java new file mode 100644 index 00000000..891d43cf --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/AbstractTeamAssert.java @@ -0,0 +1,61 @@ +package org.assertj.examples.data.movie; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link Team} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractTeamAssert, A extends Team> extends AbstractAssert { + + /** + * Creates a new {@link AbstractTeamAssert} to make assertions on actual Team. + * @param actual the Team we want to make assertions on. + */ + protected AbstractTeamAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual Team's actors contains the given String elements. + * @param actors the given elements that should be contained in actual Team's actors. + * @return this assertion object. + * @throws AssertionError if the actual Team's actors does not contain all given String elements. + */ + public S hasActors(String... actors) { + // check that actual Team we want to make assertions on is not null. + isNotNull(); + + // check that given String varargs is not null. + if (actors == null) throw new AssertionError("Expecting actors parameter not to be null."); + + // check with standard error message, to set another message call: info.overridingErrorMessage("my error message"); + org.assertj.core.internal.Iterables.instance().assertContains(info, actual.getActors(), actors); + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual Team has no actors. + * @return this assertion object. + * @throws AssertionError if the actual Team's actors is not empty. + */ + public S hasNoActors() { + // check that actual Team we want to make assertions on is not null. + isNotNull(); + + // we override the default error message with a more explicit one + String assertjErrorMessage = "\nExpected :\n <%s>\nnot to have actors but had :\n <%s>"; + + // check + if (actual.getActors().iterator().hasNext()) { + failWithMessage(assertjErrorMessage, actual, actual.getActors()); + } + + // return the current assertion for method chaining + return myself; + } + + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/MovieAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/MovieAssert.java new file mode 100644 index 00000000..371ab109 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/MovieAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.movie; + + +/** + * {@link Movie} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractMovieAssert} instead. + */ +public class MovieAssert extends AbstractMovieAssert { + + /** + * Creates a new {@link MovieAssert} to make assertions on actual Movie. + * @param actual the Movie we want to make assertions on. + */ + public MovieAssert(Movie actual) { + super(actual, MovieAssert.class); + } + + /** + * An entry point for MovieAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myMovie) and get specific assertion with code completion. + * @param actual the Movie we want to make assertions on. + * @return a new {@link MovieAssert} + */ + public static MovieAssert assertThat(Movie actual) { + return new MovieAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/TeamAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/TeamAssert.java new file mode 100644 index 00000000..b9295bec --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/movie/TeamAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.movie; + + +/** + * {@link Team} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractTeamAssert} instead. + */ +public class TeamAssert extends AbstractTeamAssert { + + /** + * Creates a new {@link TeamAssert} to make assertions on actual Team. + * @param actual the Team we want to make assertions on. + */ + public TeamAssert(Team actual) { + super(actual, TeamAssert.class); + } + + /** + * An entry point for TeamAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myTeam) and get specific assertion with code completion. + * @param actual the Team we want to make assertions on. + * @return a new {@link TeamAssert} + */ + public static TeamAssert assertThat(Team actual) { + return new TeamAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/neo4j/AbstractDragonBallGraphAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/neo4j/AbstractDragonBallGraphAssert.java new file mode 100644 index 00000000..e7e3b585 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/neo4j/AbstractDragonBallGraphAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data.neo4j; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link DragonBallGraph} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractDragonBallGraphAssert, A extends DragonBallGraph> extends AbstractAssert { + + /** + * Creates a new {@link AbstractDragonBallGraphAssert} to make assertions on actual DragonBallGraph. + * @param actual the DragonBallGraph we want to make assertions on. + */ + protected AbstractDragonBallGraphAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/neo4j/DragonBallGraphAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/neo4j/DragonBallGraphAssert.java new file mode 100644 index 00000000..ddf679fb --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/neo4j/DragonBallGraphAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.neo4j; + + +/** + * {@link DragonBallGraph} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractDragonBallGraphAssert} instead. + */ +public class DragonBallGraphAssert extends AbstractDragonBallGraphAssert { + + /** + * Creates a new {@link DragonBallGraphAssert} to make assertions on actual DragonBallGraph. + * @param actual the DragonBallGraph we want to make assertions on. + */ + public DragonBallGraphAssert(DragonBallGraph actual) { + super(actual, DragonBallGraphAssert.class); + } + + /** + * An entry point for DragonBallGraphAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myDragonBallGraph) and get specific assertion with code completion. + * @param actual the DragonBallGraph we want to make assertions on. + * @return a new {@link DragonBallGraphAssert} + */ + public static DragonBallGraphAssert assertThat(DragonBallGraph actual) { + return new DragonBallGraphAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/AbstractGameServiceAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/AbstractGameServiceAssert.java new file mode 100644 index 00000000..17bfc971 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/AbstractGameServiceAssert.java @@ -0,0 +1,19 @@ +package org.assertj.examples.data.service; + +import org.assertj.core.api.AbstractAssert; + + +/** + * Abstract base class for {@link GameService} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractGameServiceAssert, A extends GameService> extends AbstractAssert { + + /** + * Creates a new {@link AbstractGameServiceAssert} to make assertions on actual GameService. + * @param actual the GameService we want to make assertions on. + */ + protected AbstractGameServiceAssert(A actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/AbstractTeamManagerAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/AbstractTeamManagerAssert.java new file mode 100644 index 00000000..a8e89573 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/AbstractTeamManagerAssert.java @@ -0,0 +1,62 @@ +package org.assertj.examples.data.service; + +import org.assertj.core.api.AbstractAssert; +import org.assertj.examples.data.BasketBallPlayer; + + +/** + * Abstract base class for {@link TeamManager} specific assertions - Generated by CustomAssertionGenerator. + */ +public abstract class AbstractTeamManagerAssert, A extends TeamManager> extends AbstractAssert { + + /** + * Creates a new {@link AbstractTeamManagerAssert} to make assertions on actual TeamManager. + * @param actual the TeamManager we want to make assertions on. + */ + protected AbstractTeamManagerAssert(A actual, Class selfType) { + super(actual, selfType); + } + + /** + * Verifies that the actual TeamManager's players contains the given BasketBallPlayer elements. + * @param players the given elements that should be contained in actual TeamManager's players. + * @return this assertion object. + * @throws AssertionError if the actual TeamManager's players does not contain all given BasketBallPlayer elements. + */ + public S hasPlayers(BasketBallPlayer... players) { + // check that actual TeamManager we want to make assertions on is not null. + isNotNull(); + + // check that given BasketBallPlayer varargs is not null. + if (players == null) throw new AssertionError("Expecting players parameter not to be null."); + + // check with standard error message, to set another message call: info.overridingErrorMessage("my error message"); + org.assertj.core.internal.Iterables.instance().assertContains(info, actual.getPlayers(), players); + + // return the current assertion for method chaining + return myself; + } + + /** + * Verifies that the actual TeamManager has no players. + * @return this assertion object. + * @throws AssertionError if the actual TeamManager's players is not empty. + */ + public S hasNoPlayers() { + // check that actual TeamManager we want to make assertions on is not null. + isNotNull(); + + // we override the default error message with a more explicit one + String assertjErrorMessage = "\nExpected :\n <%s>\nnot to have players but had :\n <%s>"; + + // check + if (actual.getPlayers().iterator().hasNext()) { + failWithMessage(assertjErrorMessage, actual, actual.getPlayers()); + } + + // return the current assertion for method chaining + return myself; + } + + +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/GameServiceAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/GameServiceAssert.java new file mode 100644 index 00000000..2ba558ca --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/GameServiceAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.service; + + +/** + * {@link GameService} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractGameServiceAssert} instead. + */ +public class GameServiceAssert extends AbstractGameServiceAssert { + + /** + * Creates a new {@link GameServiceAssert} to make assertions on actual GameService. + * @param actual the GameService we want to make assertions on. + */ + public GameServiceAssert(GameService actual) { + super(actual, GameServiceAssert.class); + } + + /** + * An entry point for GameServiceAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myGameService) and get specific assertion with code completion. + * @param actual the GameService we want to make assertions on. + * @return a new {@link GameServiceAssert} + */ + public static GameServiceAssert assertThat(GameService actual) { + return new GameServiceAssert(actual); + } +} diff --git a/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/TeamManagerAssert.java b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/TeamManagerAssert.java new file mode 100644 index 00000000..e46bf814 --- /dev/null +++ b/assertions-examples/src/test/generated-assertions/org/assertj/examples/data/service/TeamManagerAssert.java @@ -0,0 +1,29 @@ +package org.assertj.examples.data.service; + + +/** + * {@link TeamManager} specific assertions - Generated by CustomAssertionGenerator. + * + * Although this class is not final to allow Soft assertions proxy, if you wish to extend it, + * extend {@link AbstractTeamManagerAssert} instead. + */ +public class TeamManagerAssert extends AbstractTeamManagerAssert { + + /** + * Creates a new {@link TeamManagerAssert} to make assertions on actual TeamManager. + * @param actual the TeamManager we want to make assertions on. + */ + public TeamManagerAssert(TeamManager actual) { + super(actual, TeamManagerAssert.class); + } + + /** + * An entry point for TeamManagerAssert to follow AssertJ standard assertThat() statements.
+ * With a static import, one can write directly: assertThat(myTeamManager) and get specific assertion with code completion. + * @param actual the TeamManager we want to make assertions on. + * @return a new {@link TeamManagerAssert} + */ + public static TeamManagerAssert assertThat(TeamManager actual) { + return new TeamManagerAssert(actual); + } +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/AbstractAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/AbstractAssertionsExamples.java index 836bbf32..5fcf8763 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/AbstractAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/AbstractAssertionsExamples.java @@ -110,6 +110,7 @@ protected static void logAssertionErrorMessage(String assertionContext, Assertio protected static BasketBallPlayer durant; protected static BasketBallPlayer noah; protected static BasketBallPlayer tonyParker; + protected static BasketBallPlayer dwayne; protected static List basketBallPlayers; protected static PotentialMvpCondition potentialMvp; protected static Condition doubleDoubleStats; @@ -128,6 +129,10 @@ public static void setUpOnce() { james.setAssistsPerGame(6); james.setPointsPerGame(27); james.setReboundsPerGame(8); + dwayne = new BasketBallPlayer(new Name("Dwayne", "Wade"), "Miami Heat"); + dwayne.setAssistsPerGame(16); + dwayne.setPointsPerGame(55); + dwayne.setReboundsPerGame(16); durant = new BasketBallPlayer(new Name("Kevin", "Durant"), "OKC"); durant.setAssistsPerGame(4); durant.setPointsPerGame(30); @@ -136,7 +141,14 @@ public static void setUpOnce() { noah.setAssistsPerGame(4); noah.setPointsPerGame(10); noah.setReboundsPerGame(11); - basketBallPlayers = newArrayList(rose, james, durant, noah); + + noah.getTeamMates().add(rose); + rose.getTeamMates().add(noah); + + dwayne.getTeamMates().add(james); + james.getTeamMates().add(dwayne); + + basketBallPlayers = newArrayList(rose, james, dwayne, durant, noah); potentialMvp = new PotentialMvpCondition(); doubleDoubleStats = new Condition("double double stats") { @Override diff --git a/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java index 9a677dd4..27eccb42 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java @@ -14,6 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.extractProperty; +import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; +import static org.assertj.core.api.Assertions.setAllowExtractingPrivateFields; import static org.assertj.core.api.Assertions.filter; import static org.assertj.core.data.Index.atIndex; import static org.assertj.core.util.Arrays.array; @@ -30,14 +32,16 @@ import static org.assertj.examples.data.Ring.vilya; import java.awt.Rectangle; +import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Comparator; +import org.junit.Test; +import org.assertj.core.util.introspection.IntrospectionError; import org.assertj.examples.data.Race; import org.assertj.examples.data.Ring; import org.assertj.examples.data.TolkienCharacter; import org.assertj.examples.data.movie.Movie; -import org.junit.Test; /** * Array assertions examples. @@ -316,4 +320,54 @@ public void hasSameSizeAs_assertion_examples() { assertThat(array(vilya, nenya, narya)).hasSameSizeAs(array(nenya, nenya, nenya)); } + @Test + public void use_hexadecimal_representation_in_error_messages() throws UnsupportedEncodingException { + try { + assertThat(new Byte[]{0x10,0x20}).inHexadecimal().contains(new Byte[]{0x30}); + } catch (AssertionError e) { + logAssertionErrorMessage("asHexadecimal for byte array", e); + } + try { + assertThat("zólc".getBytes()).inHexadecimal().contains("żółć".getBytes("ISO-8859-2")); + } catch (AssertionError e) { + logAssertionErrorMessage("asHexadecimal for byte array", e); + } + } + + @Test + public void use_unicode_representation_in_error_messages() throws UnsupportedEncodingException { + try { + assertThat("a6c".toCharArray()).inUnicode().isEqualTo("abó".toCharArray()); + } catch (AssertionError e) { + logAssertionErrorMessage("inUnicode for char array", e); + } + } + + @Test + public void iterable_assertions_on_extracted_private_fields_values_example() { + + // extract private fields + final Object[] trilogyArray = trilogy.toArray(); + assertThat(trilogyArray).extracting("duration").containsExactly("178 min", "179 min", "201 min"); + + // disable private field extraction + setAllowExtractingPrivateFields(false); + + try { + assertThat(trilogyArray).extracting("duration"); + failBecauseExceptionWasNotThrown(IntrospectionError.class); + } catch (Exception ignore) { + } finally { + // back to default value + setAllowExtractingPrivateFields(true); + } + } + + @Test + public void array_assertions_testing_elements_type() throws Exception { + Number[] numbers = { 2, 6L, 8.0 }; + assertThat(numbers).hasAtLeastOneElementOfType(Long.class); + assertThat(numbers).hasOnlyElementsOfType(Number.class); + } + } diff --git a/assertions-examples/src/test/java/org/assertj/examples/AssertDelegateTargetExample.java b/assertions-examples/src/test/java/org/assertj/examples/AssertDelegateTargetExample.java new file mode 100644 index 00000000..76bfbf23 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/AssertDelegateTargetExample.java @@ -0,0 +1,59 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples; + +import static org.assertj.core.api.Assertions.*; + +import javax.swing.JButton; + +import org.junit.Test; + +import org.assertj.core.api.AssertDelegateTarget; + +public class AssertDelegateTargetExample { + + // given a class + public class MyButton extends JButton { + private static final long serialVersionUID = 1L; + private boolean blinking; + + public boolean isBlinking() { return this.blinking; } + + public void setBlinking(boolean blink) { this.blinking = blink; } + + } + + // and its corresponding assertion class implementing AssertDelegateTarget + private static class MyButtonAssert implements AssertDelegateTarget { + private MyButton button; + + MyButtonAssert(MyButton button) { + this.button = button; + } + + // assertions related to MyButton + void isBlinking() { assertThat(button.isBlinking()).isTrue(); } + void isNotBlinking() { assertThat(button.isBlinking()).isFalse(); } + } + + // as it implements AssertDelegateTarget, MyButtonAssert assertions can be used through assertThat for better readability + @Test + public void AssertDelegateTarget_example() { + MyButton button = new MyButton(); + MyButtonAssert buttonAssert = new MyButtonAssert(button); + // you can encapsulate MyButtonAssert assertions methods within assertThat + assertThat(buttonAssert).isNotBlinking(); // same as : buttonAssert.isNotBlinking(); + button.setBlinking(true); + assertThat(buttonAssert).isBlinking(); // same as : buttonAssert.isBlinking(); + } +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/BDDAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/BDDAssertionsExamples.java index 88440963..45836a86 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/BDDAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/BDDAssertionsExamples.java @@ -19,16 +19,17 @@ import java.util.ArrayList; import java.util.List; -import org.assertj.examples.data.BasketBallPlayer; -import org.assertj.examples.data.Mansion; -import org.assertj.examples.data.service.GameService; -import org.assertj.examples.data.service.TeamManager; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.assertj.examples.data.BasketBallPlayer; +import org.assertj.examples.data.Mansion; +import org.assertj.examples.data.service.GameService; +import org.assertj.examples.data.service.TeamManager; + /** * BDD Style Assertions examples *

diff --git a/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java index c82aed7c..260ac37f 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java @@ -199,6 +199,8 @@ public void basic_assertions_with_lenient_equals_examples() { // frodo and sam both are hobbits, so they are lenient equals on race assertThat(frodo).isEqualToComparingOnlyGivenFields(sam, "race"); + // nested fields are supported + assertThat(frodo).isEqualToComparingOnlyGivenFields(sam, "race.name"); // but not when accepting name and race try { @@ -214,7 +216,7 @@ public void basic_assertions_with_lenient_equals_examples() { try { assertThat(frodo).isEqualToComparingOnlyGivenFields(sam, "hairColor"); } catch (IntrospectionError e) { - assertThat(e).hasMessage("No field 'hairColor' in class org.assertj.examples.data.TolkienCharacter"); + logger.info("isEqualToComparingOnlyGivenFields InstrospectionError message : {}", e.getMessage()); } } diff --git a/assertions-examples/src/test/java/org/assertj/examples/ComparableAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/ComparableAssertionsExamples.java new file mode 100644 index 00000000..4802724c --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/ComparableAssertionsExamples.java @@ -0,0 +1,62 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +/** + * Comparable assertions specific examples + * + * @author Joel Costigliola + */ +public class ComparableAssertionsExamples extends AbstractAssertionsExamples { + + @Test + public void comparable_assertions_examples() { + + Rating goodRating = new Rating(8); + Rating badRating = new Rating(4); + assertThat(goodRating).isGreaterThan(badRating); + assertThat(goodRating).isGreaterThanOrEqualTo(badRating); + assertThat(badRating).isLessThan(goodRating); + assertThat(badRating).isLessThanOrEqualTo(goodRating); + try { + assertThat(badRating).isGreaterThan(goodRating); + } catch (AssertionError e) { + logAssertionErrorMessage("isGreaterThan for generic", e); + } + + } + + private static class Rating implements Comparable { + + private int note; + + public Rating(int note) { + this.note = note; + } + + @Override + public int compareTo(Rating o) { + return note - o.note; + } + + @Override + public String toString() { + return String.valueOf(note); + } + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/FilterExamples.java b/assertions-examples/src/test/java/org/assertj/examples/FilterExamples.java index 7e81517f..632eb12c 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/FilterExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/FilterExamples.java @@ -42,26 +42,26 @@ public void filter_with_examples() { // you can apply different comparison assertThat(filter(fellowshipOfTheRing).with("race").notIn(HOBBIT, MAN).get()).containsOnly(gandalf, gimli, legolas); assertThat(filter(fellowshipOfTheRing).with("race").in(MAIA, MAN).get()).containsOnly(gandalf, boromir, aragorn); - assertThat(filter(fellowshipOfTheRing).with("race").notEqualsTo(HOBBIT).get()).contains(gandalf, boromir, aragorn, gimli, - legolas); - // you can chain multiple filter criteria + assertThat(filter(fellowshipOfTheRing).with("race").notEqualsTo(HOBBIT).get()).contains(gandalf, boromir, aragorn, + gimli, legolas); + // you can chain multiple filter criteria assertThat(filter(fellowshipOfTheRing).with("race").equalsTo(MAN).and("name").notEqualsTo("Boromir").get()).contains(aragorn); } @Test public void filter_on_condition_examples() { // having(condition) example - Condition mvpStats= new Condition() { + Condition mvpStats = new Condition() { @Override public boolean matches(BasketBallPlayer player) { return player.getPointsPerGame() > 20 && (player.getAssistsPerGame() >= 8 || player.getReboundsPerGame() >= 8); } }; - assertThat(filter(basketBallPlayers).having(mvpStats).get()).containsOnly(rose, james); - + assertThat(filter(basketBallPlayers).having(mvpStats).get()).containsOnly(rose, james, dwayne); + // being(condition) example : same condition can be applied but is renamed to be more readable - Condition potentialMvp= mvpStats; - assertThat(filter(basketBallPlayers).being(potentialMvp).get()).containsOnly(rose, james); + Condition potentialMvp = mvpStats; + assertThat(filter(basketBallPlayers).being(potentialMvp).get()).containsOnly(rose, james, dwayne); } } diff --git a/assertions-examples/src/test/java/org/assertj/examples/GeneratedBddAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/GeneratedBddAssertionsExamples.java new file mode 100644 index 00000000..a673ebad --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/GeneratedBddAssertionsExamples.java @@ -0,0 +1,31 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples; + +import static org.assertj.BddAssertions.then; + +import org.junit.Test; + +import org.assertj.examples.data.Name; +import org.assertj.examples.exception.NameException; + +public class GeneratedBddAssertionsExamples extends AbstractAssertionsExamples { + + @Test + public void generated_bdd_assertions_example() throws NameException { + // use the generated BDD assertions + // Given Derrick Rose basket ball player + then(rose).hasName(new Name("Derrick", "Rose")).hasTeamMates(noah); + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/GeneratedSoftAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/GeneratedSoftAssertionsExamples.java new file mode 100644 index 00000000..f4eecbba --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/GeneratedSoftAssertionsExamples.java @@ -0,0 +1,42 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples; + +import org.junit.Test; + +import org.assertj.core.api.SoftAssertionError; +import org.assertj.examples.data.Name; +import org.assertj.SoftAssertions; +import org.assertj.examples.exception.NameException; + +public class GeneratedSoftAssertionsExamples extends AbstractAssertionsExamples { + + @Test + public void generated_soft_assertions_example() throws NameException { + // use the generated soft assertions + SoftAssertions softly = new SoftAssertions(); + softly.assertThat(rose).hasName(new Name("Derrick", "Rose")).hasNoTeamMates(); + } + + @Test + public void generated_soft_assertions_errors_example() throws NameException { + // use the generated soft assertions + SoftAssertions softly = new SoftAssertions(); + try { + softly.assertThat(rose).hasName(new Name("Michael", "Jordan")).hasTeam("Lakers"); + softly.assertAll(); + } catch (SoftAssertionError e) { + logAssertionErrorMessage("GeneratedSoftAssertions errors example", e); + } + } +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/GeneratedStandardAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/GeneratedStandardAssertionsExamples.java new file mode 100644 index 00000000..2e812f76 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/GeneratedStandardAssertionsExamples.java @@ -0,0 +1,45 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples; + +import static com.google.common.collect.Lists.newArrayList; +import static org.assertj.Assertions.assertThat; + +import org.assertj.examples.data.Name; +import org.assertj.examples.data.Team; +import org.assertj.examples.data.bug26.WithGenericListType; +import org.assertj.examples.exception.NameException; +import org.junit.Test; + +public class GeneratedStandardAssertionsExamples extends AbstractAssertionsExamples { + + @Test + public void generated_bdd_assertions_example() throws NameException { + // use the generated assertions + assertThat(rose).hasName(new Name("Derrick", "Rose")).hasTeamMates(noah); + + // + Team bulls = new Team(newArrayList(rose, noah)); + assertThat(bulls).hasPlayers(rose, noah); + + // use other Team class + org.assertj.examples.data.movie.Team lotr = new org.assertj.examples.data.movie.Team(newArrayList("vigo mortensen", "elijah wood")); + assertThat(lotr).hasActors("vigo mortensen", "elijah wood"); + + WithGenericListType test = new WithGenericListType(); + assertThat(test).hasNoMovies(); + test.movies = newArrayList(theFellowshipOfTheRing); + assertThat(test).hasMovies(theFellowshipOfTheRing); + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java index 25aae1c8..4c40bf62 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java @@ -14,6 +14,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.extractProperty; +import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; +import static org.assertj.core.api.Assertions.setAllowExtractingPrivateFields; import static org.assertj.core.api.Assertions.tuple; import static org.assertj.core.util.Lists.newArrayList; import static org.assertj.examples.data.Race.ELF; @@ -25,6 +27,8 @@ import static org.assertj.examples.data.Ring.nenya; import static org.assertj.examples.data.Ring.oneRing; import static org.assertj.examples.data.Ring.vilya; +import static org.assertj.examples.extractor.BasketballExtractors.*; +import static org.assertj.examples.extractor.TolkienCharactersExtractors.*; import java.util.ArrayList; import java.util.Collection; @@ -33,7 +37,10 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.assertj.core.util.introspection.IntrospectionError; +import org.assertj.examples.data.Employee; import org.assertj.examples.data.Ring; +import org.assertj.examples.data.TolkienCharacter; import org.junit.Test; /** @@ -46,249 +53,439 @@ public class IterableAssertionsExamples extends AbstractAssertionsExamples { @Test public void iterable_basic_assertions_examples() { - // would work the same way with Iterable, - Iterable elvesRings = newArrayList(vilya, nenya, narya); - assertThat(elvesRings).isNotEmpty().hasSize(3); - assertThat(elvesRings).hasSameSizeAs(trilogy); - assertThat(elvesRings).contains(nenya).doesNotContain(oneRing); - - // with containsOnly, all the elements must be present (but the order is not important) - assertThat(elvesRings).containsOnly(nenya, vilya, narya); - assertThat(elvesRings).doesNotContainNull().doesNotHaveDuplicates(); - try { - assertThat(elvesRings).containsOnly(nenya, vilya, oneRing); - } catch (AssertionError e) { - logAssertionErrorMessage("containsOnly", e); - } - - // special check for null, empty collection or both - assertThat(newArrayList(frodo, null, sam)).containsNull(); - List newArrayList = newArrayList(); - assertThat(newArrayList).isEmpty(); - assertThat(newArrayList).contains(); - assertThat(newArrayList).isNullOrEmpty(); - newArrayList = null; - assertThat(newArrayList).isNullOrEmpty(); - - // you can also check the start or end of your collection/iterable - Iterable allRings = newArrayList(oneRing, vilya, nenya, narya, dwarfRing, manRing); - assertThat(allRings).startsWith(oneRing, vilya).endsWith(dwarfRing, manRing); - assertThat(allRings).containsSequence(nenya, narya, dwarfRing); - assertThat(allRings).containsAll(elvesRings); - - // to show an error message - try { - assertThat(elvesRings).containsAll(allRings); - } catch (AssertionError e) { - logAssertionErrorMessage("containsAll", e); - } - - List testedList = newArrayList(1); - List referenceList = newArrayList(1, 2, 3); - assertThat(referenceList).containsSequence(testedList.toArray(new Integer[testedList.size()])); - - List list = newArrayList("--option", "a=b", "--option", "c=d"); - assertThat(list).containsSequence("--option", "c=d"); + // would work the same way with Iterable, + Iterable elvesRings = newArrayList(vilya, nenya, narya); + assertThat(elvesRings).isNotEmpty().hasSize(3); + assertThat(elvesRings).hasSameSizeAs(trilogy); + assertThat(elvesRings).contains(nenya).doesNotContain(oneRing); + + // with containsOnly, all the elements must be present (but the order is not important) + assertThat(elvesRings).containsOnly(nenya, vilya, narya) + .containsOnly(vilya, nenya, narya) + .containsOnlyElementsOf(newArrayList(nenya, narya, vilya, nenya)) + .hasSameElementsAs(newArrayList(nenya, narya, vilya, nenya)); + assertThat(elvesRings).doesNotContainNull().doesNotHaveDuplicates(); + + Iterable duplicatedElvesRings = newArrayList(vilya, nenya, narya, vilya, nenya, narya); + assertThat(elvesRings).hasSameElementsAs(duplicatedElvesRings) + .containsOnlyElementsOf(duplicatedElvesRings); + + try { + assertThat(elvesRings).containsOnlyElementsOf(newArrayList(vilya, nenya, vilya, oneRing)); + assertThat(elvesRings).containsOnly(nenya, vilya, oneRing); + } catch (AssertionError e) { + logAssertionErrorMessage("containsOnly", e); + } + + // special check for null, empty collection or both + assertThat(newArrayList(frodo, null, sam)).containsNull(); + List newArrayList = newArrayList(); + assertThat(newArrayList).isEmpty(); + assertThat(newArrayList).contains(); + assertThat(newArrayList).isNullOrEmpty(); + newArrayList = null; + assertThat(newArrayList).isNullOrEmpty(); + + // you can also check the start or end of your collection/iterable + Iterable allRings = newArrayList(oneRing, vilya, nenya, narya, dwarfRing, manRing); + assertThat(allRings).startsWith(oneRing, vilya).endsWith(dwarfRing, manRing); + assertThat(allRings).containsSequence(nenya, narya, dwarfRing); + assertThat(allRings).containsAll(elvesRings); + + // to show an error message + try { + assertThat(elvesRings).containsAll(allRings); + } catch (AssertionError e) { + logAssertionErrorMessage("containsAll", e); + } + + List testedList = newArrayList(1); + List referenceList = newArrayList(1, 2, 3); + assertThat(referenceList).containsSequence(testedList.toArray(new Integer[testedList.size()])); + + List list = newArrayList("--option", "a=b", "--option", "c=d"); + assertThat(list).containsSequence("--option", "c=d"); } @Test public void iterable_basic_contains_exactly_assertions_examples() { - Iterable elvesRings = newArrayList(vilya, nenya, narya); - assertThat(elvesRings).containsExactly(vilya, nenya, narya); - - // It works with collections that have a consistent iteration order - SortedSet elvesRingsSet = new TreeSet(); - elvesRingsSet.add(vilya); - elvesRingsSet.add(nenya); - elvesRingsSet.add(narya); - assertThat(elvesRingsSet).containsExactly(vilya, nenya, narya); - - // Expected values can be given by another Iterable. - assertThat(elvesRings).containsExactlyElementsOf(elvesRingsSet); - - try { - // putting a different order would make the assertion fail : - assertThat(elvesRings).containsExactly(nenya, vilya, narya); - } catch (AssertionError e) { - logger.info(e.getMessage()); - logAssertionErrorMessage("containsExactly", e); - } - - try { - List z = newArrayList("a", "a", "a"); - assertThat(z).containsExactly("a", "a"); - } catch (AssertionError e) { - logAssertionErrorMessage("containsExactly with same elements appearing several time", e); - } - - try { - // putting a different order would make the assertion fail : - assertThat(newArrayList(narya, vilya, nenya)).containsExactlyElementsOf(elvesRingsSet); - } catch (AssertionError e) { - logger.info(e.getMessage()); - logAssertionErrorMessage("containsExactlyElementsOf with elements in different order", e); - } + Iterable elvesRings = newArrayList(vilya, nenya, narya); + assertThat(elvesRings).containsExactly(vilya, nenya, narya); + + // It works with collections that have a consistent iteration order + SortedSet elvesRingsSet = new TreeSet(); + elvesRingsSet.add(vilya); + elvesRingsSet.add(nenya); + elvesRingsSet.add(narya); + assertThat(elvesRingsSet).containsExactly(vilya, nenya, narya); + + // Expected values can be given by another Iterable. + assertThat(elvesRings).containsExactlyElementsOf(elvesRingsSet); + + try { + // putting a different order would make the assertion fail : + assertThat(elvesRings).containsExactly(nenya, vilya, narya); + } catch (AssertionError e) { + logger.info(e.getMessage()); + logAssertionErrorMessage("containsExactly", e); + } + + try { + List z = newArrayList("a", "a", "a"); + assertThat(z).containsExactly("a", "a"); + } catch (AssertionError e) { + logAssertionErrorMessage("containsExactly with same elements appearing several time", e); + } + + try { + // putting a different order would make the assertion fail : + assertThat(newArrayList(narya, vilya, nenya)).containsExactlyElementsOf(elvesRingsSet); + } catch (AssertionError e) { + logger.info(e.getMessage()); + logAssertionErrorMessage("containsExactlyElementsOf with elements in different order", e); + } } @Test public void iterable_assertions_with_custom_comparator_examples() { - // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron ... - assertThat(fellowshipOfTheRing).contains(gandalf).doesNotContain(sauron); - // ... but if we compare only race name Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf. - assertThat(fellowshipOfTheRing).usingElementComparator(raceNameComparator).contains(sauron); - - // note that error message mentions the comparator used to better understand the failure - // the message indicates that Sauron were found because he is a Maia like Gandalf. - try { - assertThat(newArrayList(gandalf, sam)).usingElementComparator(raceNameComparator).doesNotContain(sauron); - } catch (AssertionError e) { - logAssertionErrorMessage("doesNotContain with custom element comparator", e); - } - - // duplicates assertion honors custom comparator - assertThat(fellowshipOfTheRing).doesNotHaveDuplicates(); - assertThat(newArrayList(sam, gandalf)).usingElementComparator(raceNameComparator).doesNotHaveDuplicates(); - try { - assertThat(newArrayList(sam, gandalf, frodo)).usingElementComparator(raceNameComparator).doesNotHaveDuplicates(); - } catch (AssertionError e) { - logAssertionErrorMessage("doesNotHaveDuplicates with custom element comparator", e); - } + // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron ... + assertThat(fellowshipOfTheRing).contains(gandalf).doesNotContain(sauron); + // ... but if we compare only race name Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf. + assertThat(fellowshipOfTheRing).usingElementComparator(raceNameComparator).contains(sauron); + + // note that error message mentions the comparator used to better understand the failure + // the message indicates that Sauron were found because he is a Maia like Gandalf. + try { + assertThat(newArrayList(gandalf, sam)).usingElementComparator(raceNameComparator).doesNotContain(sauron); + } catch (AssertionError e) { + logAssertionErrorMessage("doesNotContain with custom element comparator", e); + } + + // duplicates assertion honors custom comparator + assertThat(fellowshipOfTheRing).doesNotHaveDuplicates(); + assertThat(newArrayList(sam, gandalf)).usingElementComparator(raceNameComparator) + .doesNotHaveDuplicates() + .isEqualTo(newArrayList(frodo, gandalf)); + try { + assertThat(newArrayList(sam, gandalf, frodo)).usingElementComparator(raceNameComparator).doesNotHaveDuplicates(); + } catch (AssertionError e) { + logAssertionErrorMessage("doesNotHaveDuplicates with custom element comparator", e); + } } @Test public void iterable_assertions_on_extracted_values_example() { - // extract 'name' property values - assertThat(fellowshipOfTheRing).extracting("name").contains("Boromir", "Gandalf", "Frodo", "Legolas") - .doesNotContain("Sauron", "Elrond"); + // extract 'name' property values + assertThat(fellowshipOfTheRing).extracting("name").contains("Boromir", "Gandalf", "Frodo", "Legolas") + .doesNotContain("Sauron", "Elrond"); - // extract 'age' field values - assertThat(fellowshipOfTheRing).extracting("age").contains(33, 38, 36); + // extract 'age' field values + assertThat(fellowshipOfTheRing).extracting("age").contains(33, 38, 36); - // extracting works also with user's types (here Race) - assertThat(fellowshipOfTheRing).extracting("race").contains(HOBBIT, ELF).doesNotContain(ORC); + // extracting works also with user's types (here Race) + assertThat(fellowshipOfTheRing).extracting("race").contains(HOBBIT, ELF).doesNotContain(ORC); - // extract nested property values on Race - assertThat(fellowshipOfTheRing).extracting("race.name").contains("Hobbit", "Elf").doesNotContain("Orc"); + // extract nested property values on Race + assertThat(fellowshipOfTheRing).extracting("race.name").contains("Hobbit", "Elf").doesNotContain("Orc"); - // same assertions but extracting properties fluently done outside assertions + // same assertions but extracting properties fluently done outside assertions - // extract simple property values having a java standard type - assertThat(extractProperty("name", String.class).from(fellowshipOfTheRing)).contains("Boromir", "Gandalf", "Frodo") - .doesNotContain("Sauron", "Elrond"); + // extract simple property values having a java standard type + assertThat(extractProperty("name", String.class).from(fellowshipOfTheRing)).contains("Boromir", "Gandalf", "Frodo") + .doesNotContain("Sauron", "Elrond"); - // same extraction with an alternate syntax - assertThat(extractProperty("name").ofType(String.class).from(fellowshipOfTheRing)).contains("Boromir", "Gandalf", - "Frodo", "Legolas") - .doesNotContain("Sauron", "Elrond"); + // same extraction with an alternate syntax + assertThat(extractProperty("name").ofType(String.class).from(fellowshipOfTheRing)).contains("Boromir", "Gandalf", + "Frodo", "Legolas") + .doesNotContain("Sauron", + "Elrond"); - // extracting property works also with user's types (here Race) - assertThat(extractProperty("race").from(fellowshipOfTheRing)).contains(HOBBIT, ELF).doesNotContain(ORC); + // extracting property works also with user's types (here Race) + assertThat(extractProperty("race").from(fellowshipOfTheRing)).contains(HOBBIT, ELF).doesNotContain(ORC); - // extract nested property on Race - assertThat(extractProperty("race.name").from(fellowshipOfTheRing)).contains("Hobbit", "Elf").doesNotContain("Orc"); + // extract nested property on Race + assertThat(extractProperty("race.name").from(fellowshipOfTheRing)).contains("Hobbit", "Elf").doesNotContain("Orc"); } @Test - public void iterable_assertions_on_several_extracted_values() { + public void iterable_assertions_on_extracted_private_fields_values_example() { + + // extract private fields + assertThat(trilogy).extracting("duration").containsExactly("178 min", "179 min", "201 min"); + + // disable private field extraction + setAllowExtractingPrivateFields(false); + + try { + assertThat(trilogy).extracting("duration"); + failBecauseExceptionWasNotThrown(IntrospectionError.class); + } catch (Exception ignore) { + } finally { + // back to default value + setAllowExtractingPrivateFields(true); + } + } - // extract 'name' and 'age' values. - assertThat(fellowshipOfTheRing).extracting("name", "age").contains(tuple("Boromir", 37), tuple("Sam", 38), - tuple("Legolas", 1000)); + @Test + public void iterable_assertions_on_several_extracted_values() { - // extract 'name', 'age' and Race name values. - assertThat(fellowshipOfTheRing).extracting("name", "age", "race.name").contains(tuple("Boromir", 37, "Man"), - tuple("Sam", 38, "Hobbit"), - tuple("Legolas", 1000, "Elf")); + // extract 'name' and 'age' values. + assertThat(fellowshipOfTheRing).extracting("name", "age").contains(tuple("Boromir", 37), tuple("Sam", 38), + tuple("Legolas", 1000)); + + // extract 'name', 'age' and Race name values. + assertThat(fellowshipOfTheRing).extracting("name", "age", "race.name").contains(tuple("Boromir", 37, "Man"), + tuple("Sam", 38, "Hobbit"), + tuple("Legolas", 1000, "Elf")); + // extract 'name', 'age' and Race name values. + TolkienCharacter unknown = new TolkienCharacter("unknown", 100, null); + assertThat(newArrayList(sam, unknown)).extracting("name", "age", "race.name").contains(tuple("Sam", 38, "Hobbit"), + tuple("unknown", 100, null)); } @Test public void iterable_is_subset_of_assertion_example() { - Collection elvesRings = newArrayList(vilya, nenya, narya); - assertThat(elvesRings).isSubsetOf(ringsOfPower); + Collection elvesRings = newArrayList(vilya, nenya, narya); + assertThat(elvesRings).isSubsetOf(ringsOfPower); } @Test public void iterable_type_safe_assertion_example() { - // just to show that containsAll can accept subtype of is not bounded to Object only - Collection elvesRings = newArrayList(vilya, nenya, narya); - Collection powerfulRings = new ArrayList(); - powerfulRings.add(oneRing); - powerfulRings.add(vilya); - powerfulRings.add(nenya); - powerfulRings.add(narya); - assertThat(powerfulRings).containsAll(elvesRings); + // just to show that containsAll can accept subtype of is not bounded to Object only + Collection elvesRings = newArrayList(vilya, nenya, narya); + Collection powerfulRings = new ArrayList(); + powerfulRings.add(oneRing); + powerfulRings.add(vilya); + powerfulRings.add(nenya); + powerfulRings.add(narya); + assertThat(powerfulRings).containsAll(elvesRings); } @Test public void iterator_assertion_example() { - // Iterable assertions also works if you give an Iterator as input. - Iterator elvesRings = newArrayList(vilya, nenya, narya).iterator(); - assertThat(elvesRings).isSubsetOf(ringsOfPower); + // Iterable assertions also works if you give an Iterator as input. + Iterator elvesRingsIterator = newArrayList(vilya, nenya, narya).iterator(); + // elvesRingsIterator is only consumed when needed which is not the case with null/notNull assertion + assertThat(elvesRingsIterator).isNotNull(); + assertThat(elvesRingsIterator.hasNext()).as("iterator is not consumed").isTrue(); + // elvesRingsIterator is consumed when needed but only once, you can then chain assertion + assertThat(elvesRingsIterator).isSubsetOf(ringsOfPower).contains(nenya, narya); + // elvesRingsIterator is consumed ... + assertThat(elvesRingsIterator.hasNext()).as("iterator is consumed").isFalse(); } @Test public void doesNotContainAnyElementsOf_assertion_example() { - // this assertion succeed : - List actual = newArrayList("GIT", "CVS", "SOURCESAFE"); - List values = newArrayList("git", "cvs", "subversion"); - assertThat(actual).doesNotContainAnyElementsOf(values); - - // This one failed : - actual = newArrayList("GIT", "cvs", "SOURCESAFE"); - values = newArrayList("git", "cvs", "subversion"); - try { - assertThat(actual).doesNotContainAnyElementsOf(values); - } catch (AssertionError e) { - logAssertionErrorMessage("doesNotContainAnyElementsOf", e); - } + // this assertion succeed : + List actual = newArrayList("GIT", "CVS", "SOURCESAFE"); + List values = newArrayList("git", "cvs", "subversion"); + assertThat(actual).doesNotContainAnyElementsOf(values); + + // This one failed : + actual = newArrayList("GIT", "cvs", "SOURCESAFE"); + values = newArrayList("git", "cvs", "subversion"); + try { + assertThat(actual).doesNotContainAnyElementsOf(values); + } catch (AssertionError e) { + logAssertionErrorMessage("doesNotContainAnyElementsOf", e); + } } @Test public void containsOnlyOnce_assertion_examples() { - // int - assertThat(newArrayList("Winter", "is", "coming")).containsOnlyOnce("Winter"); - assertThat(newArrayList("Winter", "is", "coming")).containsOnlyOnce("coming", "Winter"); - try { - assertThat(newArrayList("Aria", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark"); - } catch (AssertionError e) { - logAssertionErrorMessage("containsOnlyOnce for Iterable", e); - } - - try { - assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("Lannister"); - } catch (AssertionError e) { - logAssertionErrorMessage("containsOnlyOnce for Iterable", e); - } - - try { - assertThat(newArrayList("Aria", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark", - "Lannister", "Aria"); - } catch (AssertionError e) { - logAssertionErrorMessage("containsOnlyOnce for Iterable", e); - } + // int + assertThat(newArrayList("Winter", "is", "coming")).containsOnlyOnce("Winter"); + assertThat(newArrayList("Winter", "is", "coming")).containsOnlyOnce("coming", "Winter"); + try { + assertThat(newArrayList("Aria", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark"); + } catch (AssertionError e) { + logAssertionErrorMessage("containsOnlyOnce for Iterable", e); + } + + try { + assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("Lannister"); + } catch (AssertionError e) { + logAssertionErrorMessage("containsOnlyOnce for Iterable", e); + } + + try { + assertThat(newArrayList("Aria", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark", + "Lannister", "Aria"); + } catch (AssertionError e) { + logAssertionErrorMessage("containsOnlyOnce for Iterable", e); + } } @Test public void containsSubSequence_assertion_examples() { - assertThat(newArrayList("Batman", "is", "weaker", "than", "Superman", "but", "he", "is", "less", "annoying")) + assertThat(newArrayList("Batman", "is", "weaker", "than", "Superman", "but", "he", "is", "less", "annoying")) .containsSubsequence("Superman", "is", "annoying"); - assertThat(newArrayList("Breaking", "objects", "is", "pretty", "bad")).containsSubsequence("Breaking", "bad"); - try { - assertThat(newArrayList("A", "B", "C", "D")).containsSubsequence("B", "A", "C"); - } catch (AssertionError e) { - logAssertionErrorMessage("containsSubsequence for Iterable", e); - } + assertThat(newArrayList("Breaking", "objects", "is", "pretty", "bad")).containsSubsequence("Breaking", "bad"); + try { + assertThat(newArrayList("A", "B", "C", "D")).containsSubsequence("B", "A", "C"); + } catch (AssertionError e) { + logAssertionErrorMessage("containsSubsequence for Iterable", e); + } } @Test public void iterable_assertions_on_extracted_method_result_example() { - // extract results of calls to 'toString' method - assertThat(fellowshipOfTheRing).extractingResultOf("toString").contains("Frodo 33 years old Hobbit", - "Aragorn 87 years old Man"); + // extract results of calls to 'toString' method + assertThat(fellowshipOfTheRing).extractingResultOf("toString").contains("Frodo 33 years old Hobbit", + "Aragorn 87 years old Man"); } + @Test + public void iterable_assertions_comparing_elements_field_by_field_example() { + // this is useful if elements don't have a good equals method implementation. + Employee bill = new Employee("Bill", 60, "Micro$oft"); + final List micro$oftEmployees = newArrayList(bill); + Employee appleBill = new Employee("Bill", 60, "Apple"); + + // this assertion should fail as the company differs but it passes since Employee equals ignores company fields. + assertThat(micro$oftEmployees).contains(appleBill); + + // let's make the assertion fails by comparing all Employee's fields instead of using equals. + try { + assertThat(micro$oftEmployees).usingFieldByFieldElementComparator().contains(appleBill); + } catch (AssertionError e) { + logAssertionErrorMessage("contains for Iterable using field by field element comparator", e); + } + // if we don't compare company, appleBill is equivalent to bill. + assertThat(micro$oftEmployees).usingElementComparatorIgnoringFields("company").contains(appleBill); + + // if we compare only name and company, youngBill is equivalent to bill ... + Employee youngBill = new Employee("Bill", 25, "Micro$oft"); + assertThat(micro$oftEmployees).usingElementComparatorOnFields("company").contains(youngBill); + // ... but not if we compare only age. + try { + assertThat(micro$oftEmployees).usingElementComparatorOnFields("age").contains(youngBill); + } catch (AssertionError e) { + logAssertionErrorMessage("contains for Iterable usingElementComparatorOnFields", e); + } + + // another example with usingElementComparatorOnFields + TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); + TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT); + + // frodo and sam both are hobbits, so they are equals when comparing only race ... + assertThat(newArrayList(frodo)).usingElementComparatorOnFields("race").contains(sam); + assertThat(newArrayList(frodo)).usingElementComparatorOnFields("race").isEqualTo(newArrayList(sam)); + // ... but not when comparing both name and race + try { + assertThat(newArrayList(frodo)).usingElementComparatorOnFields("name", "race").contains(sam); + } catch (AssertionError e) { + logAssertionErrorMessage("contains for Iterable usingElementComparatorOnFields", e); + } + } + + @Test + public void use_hexadecimal_representation_in_error_messages() { + final List bytes = newArrayList((byte) 0x10, (byte) 0x20); + try { + assertThat(bytes).inHexadecimal().contains((byte) 0x30); + } catch (AssertionError e) { + logAssertionErrorMessage("asHexadecimal for byte list", e); + } + } + + @Test + public void use_binary_representation_in_error_messages() { + final List bytes = newArrayList((byte) 0x10, (byte) 0x20); + try { + assertThat(bytes).inBinary().contains((byte) 0x30); + } catch (AssertionError e) { + logAssertionErrorMessage("asBinary for byte list", e); + } + } + + @Test + public void iterable_assertions_on_extracted_value_examples() throws Exception { + // extract 'age' field values + assertThat(fellowshipOfTheRing).extracting(age()).contains(33, 38, 36); + + // extracting works also with user's types (here Race) + assertThat(fellowshipOfTheRing).extracting(race()).contains(HOBBIT, ELF).doesNotContain(ORC); + + // extract 'name' and 'age' values. + assertThat(fellowshipOfTheRing).extracting(ageAndRace()).contains(tuple(33, HOBBIT), tuple(38, HOBBIT), + tuple(1000, ELF)); + } + + @Test + public void iterable_assertions_on_flat_extracted_values_examples() throws Exception { + assertThat(newArrayList(noah, james)).flatExtracting(teammates()).contains(dwayne, rose); + } + + @Test + public void iterable_assertions_testing_elements_type() throws Exception { + List numbers = newArrayList(1L, 2L); + assertThat(numbers).hasOnlyElementsOfType(Number.class); + assertThat(numbers).hasOnlyElementsOfType(Long.class); + + @SuppressWarnings("unchecked") + List mixed = newArrayList("string", 1L); + assertThat(mixed).hasAtLeastOneElementOfType(String.class); + } + + @Test + public void test_issue_245() throws Exception { + Foo foo1 = new Foo("id", 1); + foo1._f2 = "foo1"; + Foo foo2 = new Foo("id", 2); + foo2._f2 = "foo1"; + List list1 = newArrayList(foo1); + List list2 = newArrayList(foo2); + assertThat(list1).usingElementComparatorOnFields("_f2").isEqualTo(list2); + assertThat(list1).usingElementComparatorOnFields("id").isEqualTo(list2); + assertThat(list1).usingElementComparatorIgnoringFields("bar").isEqualTo(list2); + try { + assertThat(list1).usingFieldByFieldElementComparator().isEqualTo(list2); + } catch (AssertionError e) { + logAssertionErrorMessage("asBinary for byte list", e); + } + } + + @Test + public void test_issue_236() throws Exception { + List list1 = newArrayList(new Foo("id", 1)); + List list2 = newArrayList(new Foo("id", 2)); + assertThat(list1).usingElementComparatorOnFields("id").isEqualTo(list2); + assertThat(list1).usingElementComparatorIgnoringFields("bar").isEqualTo(list2); + try { + assertThat(list1).usingFieldByFieldElementComparator().isEqualTo(list2); + } catch (AssertionError e) { + logAssertionErrorMessage("asBinary for byte list", e); + } + } + + public static class Foo { + private String id; + private int bar; + public String _f2; + + public String getId() { + return id; + } + + public int getBar() { + return bar; + } + + public Foo(String id, int bar) { + super(); + this.id = id; + this.bar = bar; + } + + @Override + public String toString() { + return "Foo [id=" + id + ", bar=" + bar + "]"; + } + } + } diff --git a/assertions-examples/src/test/java/org/assertj/examples/JUnitSoftAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/JUnitSoftAssertionsExamples.java index 6c3c3222..6f826408 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/JUnitSoftAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/JUnitSoftAssertionsExamples.java @@ -12,12 +12,13 @@ */ package org.assertj.examples; -import org.assertj.core.api.JUnitSoftAssertions; -import org.assertj.examples.data.Mansion; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; +import org.assertj.core.api.JUnitSoftAssertions; +import org.assertj.examples.data.Mansion; + public class JUnitSoftAssertionsExamples extends AbstractAssertionsExamples { // replace the need to call softly.assertAll(); as with SoftAssertions @@ -31,7 +32,7 @@ public void successful_soft_assertions_example() { softly.assertThat(mansion.guests()).as("Living Guests").isEqualTo(6); softly.assertThat(mansion.kitchen()).as("Kitchen").isEqualTo("clean"); softly.assertThat(mansion.library()).as("Library").isEqualTo("messy"); - softly.assertThat(mansion.revolverAmmo()).as("Revolver Ammo").isEqualTo(6); + softly.assertThat(mansion.revolverAmmo()).as("Revolver Ammo").isEqualTo(6); softly.assertThat(mansion.candlestick()).as("Candlestick").isEqualTo("bent"); softly.assertThat(mansion.colonel()).as("Colonel").isEqualTo("well kempt"); softly.assertThat(mansion.professor()).as("Professor").isEqualTo("bloodied and disheveled"); diff --git a/assertions-examples/src/test/java/org/assertj/examples/ListSpecificAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/ListSpecificAssertionsExamples.java index e1b59042..420b7e1c 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/ListSpecificAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/ListSpecificAssertionsExamples.java @@ -52,8 +52,11 @@ public void newArrayList_is_sorted_assertion_example() { // You can check that a newArrayList is sorted Collections.sort(fellowshipOfTheRing, ageComparator); - assertThat(fellowshipOfTheRing).isSortedAccordingTo(ageComparator); + assertThat(fellowshipOfTheRing).contains(frodo).isSortedAccordingTo(ageComparator); assertThat(fellowshipOfTheRing).usingElementComparator(ageComparator).isSorted(); + + // You can use iterable assertion and after that list specific ones + assertThat(fellowshipOfTheRing).contains(frodo).contains(frodo, atIndex(1)); // enum order = order of declaration = ring power assertThat(newArrayList(oneRing, vilya, nenya, narya, dwarfRing, manRing)).isSorted(); diff --git a/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java index 1f9a70b0..c090d3fc 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java @@ -14,10 +14,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.assertj.examples.data.Ring.dwarfRing; import static org.assertj.examples.data.Ring.manRing; import static org.assertj.examples.data.Ring.narya; import static org.assertj.examples.data.Ring.nenya; import static org.assertj.examples.data.Ring.oneRing; +import static org.assertj.examples.data.Ring.vilya; import java.util.LinkedHashMap; import java.util.Map; @@ -48,14 +50,21 @@ public void map_assertions_examples() { // Assertion on key assertThat(ringBearers).containsKey(nenya); assertThat(ringBearers).containsKeys(nenya, narya); + assertThat(ringBearers).containsOnlyKeys(nenya, narya, vilya, oneRing); assertThat(ringBearers).doesNotContainKey(manRing); + try { + assertThat(ringBearers).containsOnlyKeys(nenya, narya, dwarfRing); + } catch (AssertionError e) { + logAssertionErrorMessage("containsOnlyKeys with not found and not expected keys.", e); + } + // Assertion on value assertThat(ringBearers).containsValue(frodo); assertThat(ringBearers).doesNotContainValue(sam); + assertThat(ringBearers).hasSameSizeAs(ringBearers); ringBearers.clear(); - assertThat(ringBearers).isEmpty(); assertThat(ringBearers).contains(); } diff --git a/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java index 11d9ae2f..ecb9c6a7 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.within; import java.math.BigDecimal; -import java.util.Comparator; import org.assertj.examples.comparator.AbsValueComparator; import org.junit.Test; @@ -67,7 +66,6 @@ public void number_assertions_with_custom_comparison_examples() { assertThat(new int[] { -1, 2, 3 }).usingElementComparator(absValueComparator).contains(1, 2, -3); } - @Test public void assertion_error_with_message_differentiating_double_and_float() { @@ -101,17 +99,9 @@ public void big_decimals_assertions_examples() { // With BigDecimal, 8.0 is not equals to 8.00 but it is if you use compareTo() assertThat(new BigDecimal("8.0")).isEqualByComparingTo(new BigDecimal("8.00")); - // The following won't work because it relies on equals methods - // assertThat(new BigDecimal("8.0")).isGreaterThanOrEqualTo(new BigDecimal("8.00")); - // To have a consistent comparison ignoring BigDecimal scale, switch of comparison strategy : - Comparator bigDecimalComparator = new Comparator() { - public int compare(BigDecimal bigDecimal1, BigDecimal bigDecimal2) { - return bigDecimal1.compareTo(bigDecimal2); - } - }; - assertThat(new BigDecimal("8.0")).usingComparator(bigDecimalComparator) - .isEqualTo(new BigDecimal("8.00")) - .isGreaterThanOrEqualTo(new BigDecimal("8.00")); + // isGreaterThanOrEqualTo uses compareTo semantics + assertThat(new BigDecimal("8.0")).isGreaterThanOrEqualTo(new BigDecimal("8.00")); + assertThat(new BigDecimal("8.1")).isGreaterThanOrEqualTo(new BigDecimal("8.10")); } @Test diff --git a/assertions-examples/src/test/java/org/assertj/examples/condition/UsingConditionExamples.java b/assertions-examples/src/test/java/org/assertj/examples/condition/UsingConditionExamples.java index 4067c241..96718730 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/condition/UsingConditionExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/condition/UsingConditionExamples.java @@ -16,12 +16,15 @@ import static org.assertj.core.condition.AllOf.allOf; import static org.assertj.core.condition.AnyOf.anyOf; import static org.assertj.core.condition.Not.not; +import static org.assertj.core.util.Lists.newArrayList; import static org.assertj.core.util.Sets.newLinkedHashSet; +import java.util.List; import java.util.Set; import org.assertj.core.api.Condition; import org.assertj.examples.AbstractAssertionsExamples; +import org.assertj.examples.data.BasketBallPlayer; import org.junit.Test; public class UsingConditionExamples extends AbstractAssertionsExamples { @@ -33,6 +36,8 @@ public void is_condition_example() { assertThat(rose).is(potentialMvp); assertThat(james).is(potentialMvp); assertThat(noah).isNot(potentialMvp); + List bullsPlayers = newArrayList(noah, rose); + assertThat(bullsPlayers).haveAtLeastOne(potentialMvp); } @Test @@ -71,11 +76,13 @@ public void condition_example_on_multiple_elements() { assertThat(newLinkedHashSet("Luke", "Yoda")).have(jediPower); assertThat(newLinkedHashSet("Leia", "Solo")).doNotHave(jediPower); - // areAtLeast + // areAtLeast & areNotAtLeast + assertThat(newLinkedHashSet("Luke", "Yoda", "Leia")).areAtLeastOne(jedi); assertThat(newLinkedHashSet("Luke", "Yoda", "Leia")).areAtLeast(2, jedi); assertThat(newLinkedHashSet("Luke", "Yoda", "Obiwan")).areAtLeast(2, jedi); - // haveAtLeast + // haveAtLeast & doNotHaveAtLeast + assertThat(newLinkedHashSet("Luke", "Leia")).haveAtLeastOne(jediPower); assertThat(newLinkedHashSet("Luke", "Yoda", "Leia")).haveAtLeast(2, jediPower); assertThat(newLinkedHashSet("Luke", "Yoda", "Obiwan")).haveAtLeast(2, jediPower); diff --git a/assertions-examples/src/test/java/org/assertj/examples/custom/CustomAssertExamples.java b/assertions-examples/src/test/java/org/assertj/examples/custom/CustomAssertExamples.java index 8995af76..6cfe504e 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/custom/CustomAssertExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/custom/CustomAssertExamples.java @@ -16,12 +16,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.examples.custom.MyProjectAssertions.assertThat; +import java.math.BigDecimal; import java.util.List; +import org.junit.Test; import org.assertj.core.api.SoftAssertionError; import org.assertj.examples.AbstractAssertionsExamples; import org.assertj.examples.data.TolkienCharacter; -import org.junit.Test; /** * @@ -110,4 +111,9 @@ public void soft_custom_assertions_example() { } } + @Test + public void extending_core_assertions() { + assertThat(BigDecimal.ONE).isOne().isNotZero().isOne(); + } + } diff --git a/assertions-examples/src/test/java/org/assertj/examples/custom/JUnitSoftAssertionsWithCustomAssertExamples.java b/assertions-examples/src/test/java/org/assertj/examples/custom/JUnitSoftAssertionsWithCustomAssertExamples.java index 407a2801..cb57c675 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/custom/JUnitSoftAssertionsWithCustomAssertExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/custom/JUnitSoftAssertionsWithCustomAssertExamples.java @@ -38,7 +38,7 @@ public void failing_junit_soft_custom_assertions_example() { // basic object to test String name = "Michael Jordan - Bulls"; // custom object to test - Employee kent = new Employee("Kent Beck"); + Employee kent = new Employee("Kent Beck"); kent.jobTitle = "TDD evangelist"; // use our own soft assertions based on JUnit rule diff --git a/assertions-examples/src/test/java/org/assertj/examples/custom/MyAbstractBigDecimalAssert.java b/assertions-examples/src/test/java/org/assertj/examples/custom/MyAbstractBigDecimalAssert.java new file mode 100644 index 00000000..46d0bed4 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/custom/MyAbstractBigDecimalAssert.java @@ -0,0 +1,36 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.custom; + +import java.math.BigDecimal; + +import org.assertj.core.api.AbstractBigDecimalAssert; + +// public class MyBigDecimalAssert extends BigDecimalAssert { +public class MyAbstractBigDecimalAssert> extends AbstractBigDecimalAssert { + + protected MyAbstractBigDecimalAssert(BigDecimal actual, Class selfType) { + super(actual, selfType); + } + + public S isOne() { + // check condition + if (actual != null && actual.compareTo(BigDecimal.ONE) != 0) { + failWithMessage("Expected BigDecimal to be one but was <%s>", actual); + } + + // return the current assertion for method chaining + return myself; + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/custom/MyBigDecimalAssert.java b/assertions-examples/src/test/java/org/assertj/examples/custom/MyBigDecimalAssert.java new file mode 100644 index 00000000..38f71218 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/custom/MyBigDecimalAssert.java @@ -0,0 +1,23 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.custom; + +import java.math.BigDecimal; + +public class MyBigDecimalAssert extends MyAbstractBigDecimalAssert { + + protected MyBigDecimalAssert(BigDecimal actual) { + super(actual, MyBigDecimalAssert.class); + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/custom/MyProjectAssertions.java b/assertions-examples/src/test/java/org/assertj/examples/custom/MyProjectAssertions.java index 7a39bab1..407807ad 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/custom/MyProjectAssertions.java +++ b/assertions-examples/src/test/java/org/assertj/examples/custom/MyProjectAssertions.java @@ -12,6 +12,8 @@ */ package org.assertj.examples.custom; +import java.math.BigDecimal; + import org.assertj.core.api.Assertions; import org.assertj.examples.data.TolkienCharacter; @@ -41,4 +43,8 @@ public static EmployeeOfTheMonthAssert assertThat(EmployeeOfTheMonth actual) { return new EmployeeOfTheMonthAssert(actual); } + public static MyBigDecimalAssert assertThat(BigDecimal actual) { + return new MyBigDecimalAssert(actual); + } + } diff --git a/assertions-examples/src/test/java/org/assertj/examples/data/.gitignore b/assertions-examples/src/test/java/org/assertj/examples/data/.gitignore index e792585e..3b9ee392 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/data/.gitignore +++ b/assertions-examples/src/test/java/org/assertj/examples/data/.gitignore @@ -15,6 +15,8 @@ /TolkienCharacterAssert.java /AbstractAlignmentAssert.java /AbstractBasketBallPlayerAssert.java +/AbstractBookAssert.java +/AbstractBookTitleAssert.java /AbstractEmployeeAssert.java /AbstractEmployeeTitleAssert.java /AbstractMagicalAssert.java @@ -25,3 +27,5 @@ /AbstractRingAssert.java /AbstractTeamAssert.java /AbstractTolkienCharacterAssert.java +/BookAssert.java +/BookTitleAssert.java diff --git a/assertions-examples/src/test/java/org/assertj/examples/data/BasketBallAssertExamples.java b/assertions-examples/src/test/java/org/assertj/examples/data/BasketBallAssertExamples.java index aefbfb93..470f4133 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/data/BasketBallAssertExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/data/BasketBallAssertExamples.java @@ -1,13 +1,13 @@ /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * Copyright 2012-2014 the original author or authors. */ package org.assertj.examples.data; @@ -33,6 +33,13 @@ public class BasketBallAssertExamples extends AbstractAssertionsExamples { @Test public void basketBallPlayer_assertion_rethrow_getter_exception() throws NameException { // since BasketBallPlayer.getName throws NameException so does BasketBallPlayerAssert.hasName - BasketBallPlayerAssert.assertThat(rose).hasName(new Name("Derrick", "Rose")).hasNoTeamMates(); + BasketBallPlayerAssert.assertThat(rose).hasName(new Name("Derrick", "Rose")).hasTeamMates(noah); + } + + @Test + public void basketBallPlayer_real_number_assertion() throws NameException { + rose.size = 6.3; + rose.setWeight(189.5f); + BasketBallPlayerAssert.assertThat(rose).hasSize(6.2, 0.1).hasWeight(189, 0.51f); } } diff --git a/assertions-examples/src/test/java/org/assertj/examples/extractor/BasketBallTeammatesExtractor.java b/assertions-examples/src/test/java/org/assertj/examples/extractor/BasketBallTeammatesExtractor.java new file mode 100644 index 00000000..a4e00c34 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/extractor/BasketBallTeammatesExtractor.java @@ -0,0 +1,27 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.extractor; + +import java.util.List; + +import org.assertj.core.api.iterable.Extractor; +import org.assertj.examples.data.BasketBallPlayer; + +class BasketBallTeammatesExtractor implements Extractor> { + + @Override + public List extract(BasketBallPlayer input) { + return input.getTeamMates(); + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/extractor/BasketballExtractors.java b/assertions-examples/src/test/java/org/assertj/examples/extractor/BasketballExtractors.java new file mode 100644 index 00000000..4f36176d --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/extractor/BasketballExtractors.java @@ -0,0 +1,31 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.extractor; + +import java.util.List; + +import org.assertj.core.api.iterable.Extractor; +import org.assertj.examples.data.BasketBallPlayer; + + +public class BasketballExtractors { + BasketballExtractors() { + + } + + public static Extractor> teammates() { + return new BasketBallTeammatesExtractor(); + + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterAgeAndRaceExtractor.java b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterAgeAndRaceExtractor.java new file mode 100644 index 00000000..77beccef --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterAgeAndRaceExtractor.java @@ -0,0 +1,26 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.extractor; + +import org.assertj.core.api.iterable.Extractor; +import org.assertj.core.groups.Tuple; +import org.assertj.examples.data.TolkienCharacter; + +class TolkienCharacterAgeAndRaceExtractor implements Extractor { + + @Override + public Tuple extract(TolkienCharacter input) { + return new Tuple(input.age, input.getRace()); + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterAgeExtractor.java b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterAgeExtractor.java new file mode 100644 index 00000000..20b94ca8 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterAgeExtractor.java @@ -0,0 +1,25 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.extractor; + +import org.assertj.core.api.iterable.Extractor; +import org.assertj.examples.data.TolkienCharacter; + +class TolkienCharacterAgeExtractor implements Extractor { + + @Override + public Integer extract(TolkienCharacter input) { + return input.age; + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterRaceExtractor.java b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterRaceExtractor.java new file mode 100644 index 00000000..a7510ab0 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharacterRaceExtractor.java @@ -0,0 +1,26 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.extractor; + +import org.assertj.core.api.iterable.Extractor; +import org.assertj.examples.data.Race; +import org.assertj.examples.data.TolkienCharacter; + +class TolkienCharacterRaceExtractor implements Extractor { + + @Override + public Race extract(TolkienCharacter input) { + return input.getRace(); + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharactersExtractors.java b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharactersExtractors.java new file mode 100644 index 00000000..641c3568 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/extractor/TolkienCharactersExtractors.java @@ -0,0 +1,36 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.extractor; + +import org.assertj.core.api.iterable.Extractor; +import org.assertj.core.groups.Tuple; +import org.assertj.examples.data.Race; +import org.assertj.examples.data.TolkienCharacter; + +public class TolkienCharactersExtractors { + TolkienCharactersExtractors() { + + } + + public static Extractor race() { + return new TolkienCharacterRaceExtractor(); + } + + public static Extractor age() { + return new TolkienCharacterAgeExtractor(); + } + + public static Extractor ageAndRace() { + return new TolkienCharacterAgeAndRaceExtractor(); + } +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/rpg/Item.java b/assertions-examples/src/test/java/org/assertj/examples/rpg/Item.java new file mode 100644 index 00000000..068be2c0 --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/rpg/Item.java @@ -0,0 +1,27 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.rpg; + +public class Item { + + private boolean magic; + + public Item(boolean magic) { + this.magic = magic; + } + + public boolean isMagic() { + return magic; + } + +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/rpg/MyAssertions.java b/assertions-examples/src/test/java/org/assertj/examples/rpg/MyAssertions.java new file mode 100644 index 00000000..3827b7da --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/rpg/MyAssertions.java @@ -0,0 +1,17 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.rpg; + +public class MyAssertions { + // empty : just used to test that generator does not generate assertions for Assertions classes +} diff --git a/assertions-examples/src/test/java/org/assertj/examples/rpg/Wand.java b/assertions-examples/src/test/java/org/assertj/examples/rpg/Wand.java new file mode 100644 index 00000000..e0b1f93e --- /dev/null +++ b/assertions-examples/src/test/java/org/assertj/examples/rpg/Wand.java @@ -0,0 +1,22 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2014 the original author or authors. + */ +package org.assertj.examples.rpg; + +public class Wand extends Item { + + public Wand() { + super(true); + } + + +}