Skip to content

Commit

Permalink
Update test classes to use JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
rasantel committed Nov 20, 2023
1 parent fdbb293 commit 048f656
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package com.hierynomus.sshj.connection.channel.forwarded;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -28,8 +27,8 @@
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder.Forward;
import net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,7 +37,7 @@ public class RemotePFPerformanceTest {
private static final Logger log = LoggerFactory.getLogger(RemotePFPerformanceTest.class);

@Test
@Ignore
@Disabled
public void startPF() throws IOException, InterruptedException {
DefaultConfig config = new DefaultConfig();
config.setMaxCircularBufferSize(16 * 1024 * 1026);
Expand Down
42 changes: 20 additions & 22 deletions src/test/java/net/schmizz/sshj/common/CircularBufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
*/
package net.schmizz.sshj.common;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.*;

import net.schmizz.sshj.common.CircularBuffer.CircularBufferException;
import net.schmizz.sshj.common.CircularBuffer.PlainCircularBuffer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CircularBufferTest {

Expand All @@ -47,8 +45,8 @@ public void shouldStoreDataCorrectlyWithoutResizing() throws CircularBufferExcep
buffer.readRawBytes(dataToRead, 320, 80);
buffer.readRawBytes(dataToRead, 400, 100);

Assert.assertEquals(256, buffer.length());
Assert.assertArrayEquals(dataToWrite, dataToRead);
assertEquals(256, buffer.length());
assertArrayEquals(dataToWrite, dataToRead);
}

@Test
Expand All @@ -74,8 +72,8 @@ public void shouldStoreDataCorrectlyWithResizing() throws CircularBufferExceptio

buffer.readRawBytes(dataToRead, 400, 100);

Assert.assertEquals(256, buffer.length());
Assert.assertArrayEquals(dataToWrite, dataToRead);
assertEquals(256, buffer.length());
assertArrayEquals(dataToWrite, dataToRead);
}

@Test
Expand Down Expand Up @@ -159,7 +157,7 @@ public void shouldAllowWritingMaxRemainingCapacityAfterWrappingAround() throws C
assertEquals(64, buffer.length());
}

@Test(expected = CircularBufferException.class)
@Test
public void shouldOverflowWhenWritingOverMaxRemainingCapacity() throws CircularBufferException {
PlainCircularBuffer buffer = new PlainCircularBuffer(64, 64);

Expand All @@ -171,30 +169,30 @@ public void shouldOverflowWhenWritingOverMaxRemainingCapacity() throws CircularB
assertEquals(buffer.length() - 1 - initiallyWritten, maxRemainingCapacity);

byte[] dataToWrite = getData(maxRemainingCapacity + 1);
buffer.putRawBytes(dataToWrite, 0, dataToWrite.length);
assertThrows(CircularBufferException.class, () -> buffer.putRawBytes(dataToWrite, 0, dataToWrite.length));
}

@Test(expected = CircularBufferException.class)
public void shouldThrowWhenReadingEmptyBuffer() throws CircularBufferException {
@Test
public void shouldThrowWhenReadingEmptyBuffer() {
PlainCircularBuffer buffer = new PlainCircularBuffer(64, Integer.MAX_VALUE);
buffer.readRawBytes(new byte[1], 0, 1);
assertThrows(CircularBufferException.class, () -> buffer.readRawBytes(new byte[1], 0, 1));
}

@Test(expected = CircularBufferException.class)
@Test
public void shouldThrowWhenReadingMoreThanAvailable() throws CircularBufferException {
PlainCircularBuffer buffer = new PlainCircularBuffer(64, Integer.MAX_VALUE);
buffer.putRawBytes(new byte[1], 0, 1);
buffer.readRawBytes(new byte[2], 0, 2);
assertThrows(CircularBufferException.class, () -> buffer.readRawBytes(new byte[2], 0, 2));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void shouldThrowOnAboveMaximumInitialSize() {
new PlainCircularBuffer(65, 64);
assertThrows(IllegalArgumentException.class, () -> new PlainCircularBuffer(65, 64));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void shouldThrowOnMaximumInitialSize() {
new PlainCircularBuffer(Integer.MAX_VALUE, 64);
assertThrows(IllegalArgumentException.class, () -> new PlainCircularBuffer(Integer.MAX_VALUE, 64));
}

@Test
Expand All @@ -205,11 +203,11 @@ public void shouldAllowFullCapacity() throws CircularBufferException {
assertEquals(maxSize - 1, buffer.maxPossibleRemainingCapacity());
}

@Test(expected = CircularBufferException.class)
public void shouldThrowOnTooLargeRequestedCapacity() throws CircularBufferException {
@Test
public void shouldThrowOnTooLargeRequestedCapacity() {
int maxSize = 1024;
PlainCircularBuffer buffer = new PlainCircularBuffer(256, maxSize);
buffer.ensureCapacity(maxSize);
assertThrows(CircularBufferException.class, () -> buffer.ensureCapacity(maxSize));
}

private static byte[] getData(int length) {
Expand Down

0 comments on commit 048f656

Please sign in to comment.