Kotlin class assertion generation problem
まだ誰も着手していません。
評価
調査の方向性
Klass.kt と JavaClass.java にある Kotlin の再現コードから始め、次に AbstractKlassAssert を生成するジェネレーターの経路を調べます。生成されたアサーションメソッドが一度だけ出力され、結果として生成される Java クラスがコンパイルできることを確認します。
索引モデルが issue の本文から書いたものです。
説明
There is a small problem:
Generator is creating assertion methods twice in Abstract***Assert classes for code where Kotlin class with lateinit collection field is generified with complex java class. Generated code cannot compile
Example to reproduce the problem:
Klass.kt:
class Klass {
lateinit var collection: Collection<JavaClass>
}
JavaClass.java:
public class JavaClass {}
Result:
/**
* Abstract base class for {@link Klass} specific assertions - Generated by CustomAssertionGenerator.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
public abstract class AbstractKlassAssert<S extends AbstractKlassAssert<S, A>, A extends Klass> extends AbstractObjectAssert<S, A> {
/**
* Creates a new <code>{@link AbstractKlassAssert}</code> to make assertions on actual Klass.
* @param actual the Klass we want to make assertions on.
*/
protected AbstractKlassAssert(A actual, Class<S> selfType) {
super(actual, selfType);
}
/**
* Verifies that the actual Klass's collection contains the given JavaClass elements.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasCollection(JavaClass... collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass varargs is not null.
if (collection == null) failWithMessage("Expecting collection parameter not to be null.");
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContains(info, actual.getCollection(), collection);
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection contains the given JavaClass elements in Collection.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasCollection(java.util.Collection<? extends JavaClass> collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass collection is not null.
if (collection == null) {
failWithMessage("Expecting collection parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContains(info, actual.getCollection(), collection.toArray());
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection contains <b>only</b> the given JavaClass elements and nothing else in whatever order.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasOnlyCollection(JavaClass... collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass varargs is not null.
if (collection == null) failWithMessage("Expecting collection parameter not to be null.");
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.getCollection(), collection);
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection contains <b>only</b> the given JavaClass elements in Collection and nothing else in whatever order.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasOnlyCollection(java.util.Collection<? extends JavaClass> collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass collection is not null.
if (collection == null) {
failWithMessage("Expecting collection parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.getCollection(), collection.toArray());
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection does not contain the given JavaClass elements.
*
* @param collection the given elements that should not be in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection contains any given JavaClass elements.
*/
public S doesNotHaveCollection(JavaClass... collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass varargs is not null.
if (collection == null) failWithMessage("Expecting collection parameter not to be null.");
// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.getCollection(), collection);
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection does not contain the given JavaClass elements in Collection.
*
* @param collection the given elements that should not be in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection contains any given JavaClass elements.
*/
public S doesNotHaveCollection(java.util.Collection<? extends JavaClass> collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass collection is not null.
if (collection == null) {
failWithMessage("Expecting collection parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}
// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.getCollection(), collection.toArray());
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass has no collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection is not empty.
*/
public S hasNoCollection() {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// we override the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting :\n <%s>\nnot to have collection but had :\n <%s>";
// check
if (actual.getCollection().iterator().hasNext()) {
failWithMessage(assertjErrorMessage, actual, actual.getCollection());
}
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection contains the given JavaClass elements.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasCollection(JavaClass... collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass varargs is not null.
if (collection == null) failWithMessage("Expecting collection parameter not to be null.");
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContains(info, actual.collection, collection);
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection contains the given JavaClass elements in Collection.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasCollection(java.util.Collection<? extends JavaClass> collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass collection is not null.
if (collection == null) {
failWithMessage("Expecting collection parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContains(info, actual.collection, collection.toArray());
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection contains <b>only</b> the given JavaClass elements and nothing else in whatever order.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasOnlyCollection(JavaClass... collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass varargs is not null.
if (collection == null) failWithMessage("Expecting collection parameter not to be null.");
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.collection, collection);
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection contains <b>only</b> the given JavaClass elements in Collection and nothing else in whatever order.
* @param collection the given elements that should be contained in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection does not contain all given JavaClass elements.
*/
public S hasOnlyCollection(java.util.Collection<? extends JavaClass> collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass collection is not null.
if (collection == null) {
failWithMessage("Expecting collection parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}
// check with standard error message, to set another message call: info.overridingErrorMessage("my error message");
Iterables.instance().assertContainsOnly(info, actual.collection, collection.toArray());
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection does not contain the given JavaClass elements.
*
* @param collection the given elements that should not be in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection contains any given JavaClass elements.
*/
public S doesNotHaveCollection(JavaClass... collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass varargs is not null.
if (collection == null) failWithMessage("Expecting collection parameter not to be null.");
// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.collection, collection);
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass's collection does not contain the given JavaClass elements in Collection.
*
* @param collection the given elements that should not be in actual Klass's collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection contains any given JavaClass elements.
*/
public S doesNotHaveCollection(java.util.Collection<? extends JavaClass> collection) {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// check that given JavaClass collection is not null.
if (collection == null) {
failWithMessage("Expecting collection parameter not to be null.");
return myself; // to fool Eclipse "Null pointer access" warning on toArray.
}
// check with standard error message (use overridingErrorMessage before contains to set your own message).
Iterables.instance().assertDoesNotContain(info, actual.collection, collection.toArray());
// return the current assertion for method chaining
return myself;
}
/**
* Verifies that the actual Klass has no collection.
* @return this assertion object.
* @throws AssertionError if the actual Klass's collection is not empty.
*/
public S hasNoCollection() {
// check that actual Klass we want to make assertions on is not null.
isNotNull();
// we override the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting :\n <%s>\nnot to have collection but had :\n <%s>";
// check
if (actual.collection.iterator().hasNext()) {
failWithMessage(assertjErrorMessage, actual, actual.collection);
}
// return the current assertion for method chaining
return myself;
}
}
- 主要言語
- Java
- スター
- 72
- フォーク
- 47
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
assertj/assertj-generator のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
assertj/assertj-generator#278 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
assertj/assertj-generator#220 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
assertj/assertj-generator#219 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
assertj/assertj-generator#204 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
assertj/assertj-generator#197 · コメント 7 件 ·
assertj/assertj-generator の issue をすべて見る
似ている issue
-
area-deployment area-integrations triage:bot-seen
難易度 2/5 半日 初心者へのやさしさ 86/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
apache/flink-agents#1156 ·
-
[source-shopify] FAILED bulk operation without partialDataUrl is silently treated as successful オープンarea/connectors autoteam community connectors/source/shopify needs-triage team/use type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100