Skip to content

Commit

Permalink
#9 Fix broken tests due to the recently introduced onClose().
Browse files Browse the repository at this point in the history
  • Loading branch information
vy committed Dec 3, 2019
1 parent 1e213b1 commit 21f716b
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/test/java/com/vlkan/rfos/RotatingFileOutputStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,26 @@ private void test_write_insensitive_policy(boolean compress) throws Exception {
Mockito.verify(policy, Mockito.never()).acceptWrite(Mockito.anyLong());

// Trigger rotation.
LOGGER.trace("triggering rotation");
stream.rotate(policy, now);

// Close the stream.
LOGGER.trace("closing stream");
stream.close();

// Verify the rotation trigger.
inOrder
.verify(callback)
.onTrigger(Mockito.same(policy), Mockito.same(now));

// Verify the rotation file close.
inOrder
.verify(callback)
.onClose(
Mockito.same(policy),
Mockito.same(now),
Mockito.any(OutputStream.class));

// Verify the rotation file open.
inOrder
.verify(callback)
Expand All @@ -137,6 +150,16 @@ private void test_write_insensitive_policy(boolean compress) throws Exception {
assertThat(rotatedFileLength).isEqualTo(expectedRotatedFileLength);
assertThat(file.length()).isEqualTo(0);

// Verify the stream close. (We cannot use InOrder here since we don't
// know whether the rotation background task or the user-invoked close()
// will finish earlier.)
Mockito
.verify(callback)
.onClose(
Mockito.isNull(),
Mockito.any(Instant.class),
Mockito.any(OutputStream.class));

// Verify no more interactions.
Mockito.verifyNoMoreInteractions(callback);
Mockito.verifyNoMoreInteractions(policy);
Expand Down Expand Up @@ -209,6 +232,14 @@ public void test_write_sensitive_policy() throws Exception {
Mockito.same(policy),
Mockito.any(Instant.class));

// Verify the rotation file close.
callbackInOrder
.verify(callback)
.onClose(
Mockito.same(policy),
Mockito.any(Instant.class),
Mockito.any(OutputStream.class));

// Verify the rotation file open.
callbackInOrder
.verify(callback)
Expand Down Expand Up @@ -375,7 +406,7 @@ public void test_adding_file_header() throws IOException {
stream.write(payload2);

// Close the stream.
LOGGER.trace("closing");
LOGGER.trace("closing stream");
stream.close();

// Verify the rotation trigger.
Expand Down

0 comments on commit 21f716b

Please sign in to comment.