-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid conditional statement inside expectation block #123
Comments
Yes, and this is as intended, to avoid tests getting too complicated when recording expectations. A full test was not shown, but it looks to me that recording the specific expectations directly would be better in this case. |
Ok, wasn't aware that this is an intended change. |
I have a question related to this topic, since we came down the same route. We used to have fixtures, and were using the loop inside the Expectations block to check for each set of data. As a side note, we also tried to integrate jmockit with feed4junit, but without success ; each is somehow loosing access to the @source element. |
Yes, there are other ways to write the test. If you can show an example test that used a loop, I can show how it can be rewritten. |
Had the same problem and used a Delegate to fix it. |
@rliesenfeld , can you please look at this test code and suggest "how to rewrite without a loop"? Test setup is as follows: we create The expectation is Well, I can unroll those for-loops manually, however it would look like a workaround rather than "suggested way of writing test". The test did work as expected in jmockit 1.5 @Test
public void testFileRotatedWithDeletion(
@Mocked final DumpFileLog dumpFileLog,
@Mocked final FileDeleter fileDeleter
) {
final List<DumpFile> expected = new LinkedList<DumpFile>();
for (int i = 0; i < 10; i++) {
DumpFile file = new DumpFile(
String.format(root + "2015/03/11/1426083986775/calls/" + NUMBER_FORMAT.format(i + 1) + ".gz")
, 10000L
, 0L
);
expected.add(file);
}
new Expectations() {
{
new FileDeleter(); // one instance is expected
new DumpFileLog(new File(root, DumpFileLog.DEFAULT_NAME)); // one instance is expected
dumpFileLog.parseIfPresent();
result = new LinkedList<DumpFile>();
for (int i = 0; i < 5; i++) {
DumpFile file = expected.get(i);
dumpFileLog.writeAddition(file);
}
int lag = 5;
for (int i = lag; i < 10; i++) {
DumpFile addedFile = expected.get(i);
dumpFileLog.writeAddition(addedFile);
DumpFile deletedFile = expected.get(i - lag);
fileDeleter.deleteFile(deletedFile);
result = true;
dumpFileLog.writeDeletion(deletedFile);
}
}
};
DumpFileManager dumpFileManager = new DumpFileManager(
0L /* no age limits */
, 50000L /* 20K */
, root
, false /* read from file */
);
FileRotatedListener listener = dumpFileManager.getFileRotatedListener();
for (DumpFile dumpFile : expected) {
listener.fileRotated(dumpFile, null);
}
} |
This change prevents me to upgrade from Mockito 1.12. Please tell me how I could remove the conditional.
|
Simple enough:
|
How didn't find it? Thank you. |
@rliesenfeld can you reply to @vlsi ?
|
Can somebody explain how to achieve the above expectations? Basically, a sub-block of expectation has to be repeated N number of times. |
@dayanand-ar What you're looking for is the "withCapture(List)" argument matching method. |
Thanks @rliesenfeld. |
Hi,
I'm getting IllegalArgumentException "Invalid conditional statement inside expectation block" when having an if statement inside my expectation block.
It was working in v1.9 and when upgrading to 1.14, it throws me this Exception.
The text was updated successfully, but these errors were encountered: