On 09.12.22 11:51, Damir Murat wrote:
[...]
simple assert
statement like
assert firstName != null
Groovy generates something like
ValueRecorder var1 = new ValueRecorder();
try {
String var10000 = this.firstName;
var1.record(var10000, 8);
var1.record(var10000, 8);
if (var10000 != null) {
var1.clear();
} else {
ScriptBytecodeAdapter.assertFailed(AssertionRenderer.render("assert
firstName != null", var1), (Object)null);
}
} catch (Throwable var3) {
var1.clear();
throw var3;
}
I would have assumed you mean something like this:
String var10000 = this.firstName;
var1.record(var10000, 8);
var1.record(var10000, 8);
if (!(var10000 != null)) {
exception = SBA.failure(AssertionRenderer.render("assert firstName !=
null", var1), (Object)null);
}
var1.clear();
if (exception != null) throw exception
and I would have asked why this does not also have a branch coverage
problem. But you suggest instead this:
try {
var10000 = this.firstName;
var1.record(var10000, 8);
var1.record(var10000, 8);
if (var10000 != null) {
var1.clear();
} else {
Throwable throwable = fetchAssertFailed(AssertionRenderer.render("assert
firstName != null", var1), (Object)null);
throw throwable
}
} catch (Throwable var3) {
var1.clear();
throw var3;
}
and I see that this variant avoids the additional if-branch, nice.
bye Jochen