Skip to content

Commit

Permalink
errorprone :: test updates (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb authored Jun 4, 2024
1 parent 7a100db commit a42e517
Show file tree
Hide file tree
Showing 27 changed files with 116 additions and 112 deletions.
4 changes: 2 additions & 2 deletions src/test/java/emissary/EmissaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void addReturnCodeToOutContent(String retOutput) {

@Command()
static class JunkCommand implements EmissaryCommand {
final Logger LOG = LoggerFactory.getLogger(JunkCommand.class);
static final Logger LOG = LoggerFactory.getLogger(JunkCommand.class);

@Override
public String getCommandName() {
Expand Down Expand Up @@ -227,7 +227,7 @@ public void outputBanner() {
@Command()
static class AnotherBaseCommand extends BaseCommand {
// need to extend BaseCommand to get verbose options
final Logger LOG = LoggerFactory.getLogger(AnotherBaseCommand.class);
static final Logger LOG = LoggerFactory.getLogger(AnotherBaseCommand.class);

@Override
public String getCommandName() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/core/BaseDataObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ void testCanRetrieveChannelFactoryFromByteArray() throws IOException {

@Test
void testBothDataFieldsHaveValue()
throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
throws IOException, NoSuchFieldException, IllegalAccessException {
final BaseDataObject bdo = new BaseDataObject();
final String testData = "This is a test";
bdo.setChannelFactory(SeekableByteChannelHelper.memory(testData.getBytes()));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/emissary/core/ExtendedDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ExtendedDataObject extends BaseDataObject implements Serializable,

private static final Logger logger = LoggerFactory.getLogger(ExtendedDataObject.class);

protected String[] NEW_FILETYPE_EMPTY = {"FOO", "BAR", "QUUX", "UNKNOWN"};
protected static final String[] NEW_FILETYPE_EMPTY = {"FOO", "BAR", "QUUX", "UNKNOWN"};

protected int intVar = -1;
protected long longVar = 100L;
Expand All @@ -29,7 +29,7 @@ public class ExtendedDataObject extends BaseDataObject implements Serializable,
public ExtendedDataObject() {
super();
this.theData = null;
FILETYPE_EMPTY = this.NEW_FILETYPE_EMPTY;
FILETYPE_EMPTY = NEW_FILETYPE_EMPTY;
this.intVar = 37;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/core/FactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public String getKey() {
}

static class DemoClassThatThrowsThrowableFromConstructor {
public DemoClassThatThrowsThrowableFromConstructor() throws Throwable {
public DemoClassThatThrowsThrowableFromConstructor() {
throw new AssertionError("Bogus");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/emissary/core/HDMobileAgentBugIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ void testTearDown() {
validate.shutDown();
}

private IServiceProviderPlace addDir(String key, String clsName) {
private static IServiceProviderPlace addDir(String key, String clsName) {
return PlaceStarter.createPlace(key, null, clsName, null, new EmissaryNode());
}

private IServiceProviderPlace addPlace(String key, String clsName) {
private static IServiceProviderPlace addPlace(String key, String clsName) {
return PlaceStarter.createPlace(key, null, clsName, null);
}

private IBaseDataObject generateIbdo(int index, String form) {
private static IBaseDataObject generateIbdo(int index, String form) {
IBaseDataObject ibdo = DataObjectFactory.getInstance(new byte[] {}, "testing_file" + Family.getSep(index), form, "TST");
ibdo.pushCurrentForm("FRM-PROCESSED-alternative");
ibdo.appendTransformHistory("*.FAKE_ANALYZE.ANALYZE.http://localhost:8543/VisitedHereFirstPlace");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import static org.junit.jupiter.api.Assertions.fail;

class InterruptibleCharSequenceTest extends UnitTest {
public static String BACKTRACKER = "^(((((a+)*)*)*)*)*$";
public static String INPUT = "aaaaab";
public static final String BACKTRACKER = "^(((((a+)*)*)*)*)*$";
public static final String INPUT = "aaaaab";

// Enable to test overhead. This method does not perform any assertions.
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testImmutability() throws IOException {
final SeekableByteChannel sbc = sbcf.create();
final ByteBuffer buff = ByteBuffer.wrap("New data".getBytes());
assertThrows(NonWritableChannelException.class, () -> sbc.write(buff), "Can't write to byte channel as it's immutable");
assertThrows(NonWritableChannelException.class, () -> sbc.truncate(5l), "Can't truncate byte channel as it's immutable");
assertThrows(NonWritableChannelException.class, () -> sbc.truncate(5L), "Can't truncate byte channel as it's immutable");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void testImmutability() throws IOException {
final SeekableByteChannel sbc = sbcf.create();
final ByteBuffer buff = ByteBuffer.wrap("New data".getBytes());
assertThrows(NonWritableChannelException.class, () -> sbc.write(buff), "Can't write to byte channel as it's immutable");
assertThrows(NonWritableChannelException.class, () -> sbc.truncate(5l), "Can't truncate byte channel as it's immutable");
assertThrows(NonWritableChannelException.class, () -> sbc.truncate(5L), "Can't truncate byte channel as it's immutable");
assertThrows(ClassCastException.class, () -> ((SeekableInMemoryByteChannel) sbc).array(),
"Can't get different variant of SBC as we've abstracted it away");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ public SeekableByteChannel create() {
final int myInstanceNumber = instanceNumber.getAndIncrement();

@Override
protected void closeImpl() throws IOException {
protected void closeImpl() {
isClosedList.set(myInstanceNumber, true);
}

@Override
protected int readImpl(ByteBuffer byteBuffer) throws IOException {
protected int readImpl(ByteBuffer byteBuffer) {
return 0;
}

@Override
protected long sizeImpl() throws IOException {
protected long sizeImpl() {
return 1;
}
};
Expand Down
38 changes: 19 additions & 19 deletions src/test/java/emissary/core/sentinel/protocols/ProtocolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ void protocolValidJson() {
@Nested
class RunTest extends UnitTest {

final String TO_UPPER_LOWER_PATTERN = "To(?:Lower|Upper)Place";
final String TO_LOWER_PLACE = "ToLowerPlace";
final String TO_UPPER_PLACE = "ToUpperPlace";
final int DEFAULT_POOL_SIZE = 5;
final String toUpperLowerPattern = "To(?:Lower|Upper)Place";
final String toLowerPlace = "ToLowerPlace";
final String toUpperPlace = "ToUpperPlace";
final int defaultPoolSize = 5;

Action action;
AgentPool pool;
Expand All @@ -170,57 +170,57 @@ public void setUp() throws Exception {
void protocol1() {
Protocol protocol = new Protocol();
protocol.action = action;
protocol.rules.put("TEST_RULE1", new AllMaxTime("rule1", TO_UPPER_LOWER_PATTERN, 5, 1.0));
protocol.rules.put("TEST_RULE2", new AnyMaxTime("rule2", TO_UPPER_LOWER_PATTERN, 30, 0.2));
protocol.rules.put("TEST_RULE1", new AllMaxTime("rule1", toUpperLowerPattern, 5, 1.0));
protocol.rules.put("TEST_RULE2", new AnyMaxTime("rule2", toUpperLowerPattern, 30, 0.2));

testProtocol(protocol, DEFAULT_POOL_SIZE, 1);
testProtocol(protocol, defaultPoolSize, 1);
}

@Test
void protocol2() {
Protocol protocol = new Protocol();
protocol.action = action;
protocol.rules.put("TEST_RULE1", new AllMaxTime("rule1", TO_UPPER_LOWER_PATTERN, 5, 1.0));
protocol.rules.put("TEST_RULE2", new AnyMaxTime("rule2", TO_UPPER_LOWER_PATTERN, 40, 0.2));
protocol.rules.put("TEST_RULE1", new AllMaxTime("rule1", toUpperLowerPattern, 5, 1.0));
protocol.rules.put("TEST_RULE2", new AnyMaxTime("rule2", toUpperLowerPattern, 40, 0.2));

testProtocol(protocol, DEFAULT_POOL_SIZE, 0);
testProtocol(protocol, defaultPoolSize, 0);
}

@Test
void protocol3() {
Protocol protocol = new Protocol();
protocol.action = action;
protocol.rules.put("TEST_RULE", new AnyMaxTime("LongRunning", TO_UPPER_LOWER_PATTERN, 30, 0.01));
protocol.rules.put("TEST_RULE", new AnyMaxTime("LongRunning", toUpperLowerPattern, 30, 0.01));

testProtocol(protocol, DEFAULT_POOL_SIZE, 1);
testProtocol(protocol, defaultPoolSize, 1);
}

@Test
void protocol4() {
Protocol protocol = new Protocol();
protocol.action = action;
protocol.rules.put("TEST_RULE", new AnyMaxTime("LongRunning", TO_LOWER_PLACE, 30, 0.01));
protocol.rules.put("TEST_RULE", new AnyMaxTime("LongRunning", toLowerPlace, 30, 0.01));

testProtocol(protocol, DEFAULT_POOL_SIZE, 0);
testProtocol(protocol, defaultPoolSize, 0);
}

@Test
void protocol5() {
Protocol protocol = new Protocol();
protocol.action = action;
protocol.rules.put("TEST_RULE", new AnyMaxTime("LongRunning", TO_UPPER_PLACE, 30, 0.01));
protocol.rules.put("TEST_RULE", new AnyMaxTime("LongRunning", toUpperPlace, 30, 0.01));

testProtocol(protocol, DEFAULT_POOL_SIZE, 1);
testProtocol(protocol, defaultPoolSize, 1);
}

@Test
void protocol6() {
Protocol protocol = new Protocol();
protocol.action = action;
protocol.rules.put("TEST_RULE1", new AllMaxTime("rule1", TO_UPPER_LOWER_PATTERN, 5, 1.0));
protocol.rules.put("TEST_RULE2", new AnyMaxTime("rule2", TO_UPPER_LOWER_PATTERN, 30, 0.2));
protocol.rules.put("TEST_RULE1", new AllMaxTime("rule1", toUpperLowerPattern, 5, 1.0));
protocol.rules.put("TEST_RULE2", new AnyMaxTime("rule2", toUpperLowerPattern, 30, 0.2));

testProtocol(protocol, DEFAULT_POOL_SIZE + 1, 0);
testProtocol(protocol, defaultPoolSize + 1, 0);
}

void testProtocol(Protocol protocol, int poolSize, int expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ void notOverTimeLimit() {
@Nested
class ConditionTest extends UnitTest {

final String TO_UPPER_LOWER_PATTERN = "To(?:Lower|Upper)Place";
final String TO_LOWER_PLACE = "ToLowerPlace";
final String TO_UPPER_PLACE = "ToUpperPlace";
final int DEFAULT_POOL_SIZE = 5;
final int DEFAULT_TIME_LIMIT = 5;
final String toUpperLowerPattern = "To(?:Lower|Upper)Place";
final String toLowerPlace = "ToLowerPlace";
final String toUpperPlace = "ToUpperPlace";
final int defaultPoolSize = 5;
final int defaultTimeLimit = 5;

AgentPool pool;
List<Protocol.PlaceAgentStats> stats;
Expand All @@ -85,42 +85,42 @@ public void setUp() throws Exception {

@Test
void condition1() {
assertTrue(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT, 1.0, DEFAULT_POOL_SIZE));
assertTrue(testRule(toUpperLowerPattern, defaultTimeLimit, 1.0, defaultPoolSize));
}

@Test
void condition2() {
assertFalse(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT, 1.0, DEFAULT_POOL_SIZE + 1));
assertFalse(testRule(toUpperLowerPattern, defaultTimeLimit, 1.0, defaultPoolSize + 1));
}

@Test
void condition3() {
assertTrue(testRule(TO_LOWER_PLACE, DEFAULT_TIME_LIMIT, 0.5, DEFAULT_POOL_SIZE));
assertTrue(testRule(toLowerPlace, defaultTimeLimit, 0.5, defaultPoolSize));
}

@Test
void condition4() {
assertFalse(testRule(TO_UPPER_PLACE, DEFAULT_TIME_LIMIT, 0.75, DEFAULT_POOL_SIZE));
assertFalse(testRule(toUpperPlace, defaultTimeLimit, 0.75, defaultPoolSize));
}

@Test
void condition5() {
assertFalse(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT + 1, 1.0, DEFAULT_POOL_SIZE));
assertFalse(testRule(toUpperLowerPattern, defaultTimeLimit + 1, 1.0, defaultPoolSize));
}

@Test
void condition6() {
assertFalse(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT + 1, 0.75, DEFAULT_POOL_SIZE));
assertFalse(testRule(toUpperLowerPattern, defaultTimeLimit + 1, 0.75, defaultPoolSize));
}

@Test
void condition7() {
assertTrue(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT, 0.5, DEFAULT_POOL_SIZE));
assertTrue(testRule(toUpperLowerPattern, defaultTimeLimit, 0.5, defaultPoolSize));
}

@Test
void condition8() {
assertFalse(testRule(TO_LOWER_PLACE, DEFAULT_TIME_LIMIT, 1.0, DEFAULT_POOL_SIZE));
assertFalse(testRule(toLowerPlace, defaultTimeLimit, 1.0, defaultPoolSize));
}

boolean testRule(String matcher, int time, double threshold, int poolSize) {
Expand All @@ -134,13 +134,13 @@ boolean testRule(String matcher, int time, double threshold, int poolSize) {

List<Protocol.PlaceAgentStats> stats() {
Protocol.PlaceAgentStats lowerStats = new Protocol.PlaceAgentStats("ToLowerPlace");
lowerStats.update(DEFAULT_TIME_LIMIT); // MobileAgent-01
lowerStats.update(DEFAULT_TIME_LIMIT + 1); // MobileAgent-02
lowerStats.update(DEFAULT_TIME_LIMIT + 4); // MobileAgent-03
lowerStats.update(defaultTimeLimit); // MobileAgent-01
lowerStats.update(defaultTimeLimit + 1); // MobileAgent-02
lowerStats.update(defaultTimeLimit + 4); // MobileAgent-03

Protocol.PlaceAgentStats upperStats = new Protocol.PlaceAgentStats("ToUpperPlace");
upperStats.update(DEFAULT_TIME_LIMIT); // MobileAgent-04
upperStats.update(DEFAULT_TIME_LIMIT + 3); // MobileAgent-05
upperStats.update(defaultTimeLimit); // MobileAgent-04
upperStats.update(defaultTimeLimit + 3); // MobileAgent-05

return List.of(lowerStats, upperStats);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ void notOverTimeLimit() {
@Nested
class ConditionTest extends UnitTest {

final String TO_UPPER_LOWER_PATTERN = "To(?:Lower|Upper)Place";
final String TO_LOWER_PLACE = "ToLowerPlace";
final String TO_UPPER_PLACE = "ToUpperPlace";
final int DEFAULT_POOL_SIZE = 5;
final int DEFAULT_TIME_LIMIT = 5;
final String toUpperLowerPattern = "To(?:Lower|Upper)Place";
final String toLowerPlace = "ToLowerPlace";
final String toUpperPlace = "ToUpperPlace";
final int defaultPoolSize = 5;
final int defaultTimeLimit = 5;

AgentPool pool;
List<Protocol.PlaceAgentStats> stats;
Expand All @@ -85,47 +85,47 @@ public void setUp() throws Exception {

@Test
void condition1() {
assertTrue(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT, 1.0, DEFAULT_POOL_SIZE));
assertTrue(testRule(toUpperLowerPattern, defaultTimeLimit, 1.0, defaultPoolSize));
}

@Test
void condition2() {
assertFalse(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT, 1.0, DEFAULT_POOL_SIZE + 1));
assertFalse(testRule(toUpperLowerPattern, defaultTimeLimit, 1.0, defaultPoolSize + 1));
}

@Test
void condition3() {
assertFalse(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT + 1, 1.0, DEFAULT_POOL_SIZE));
assertFalse(testRule(toUpperLowerPattern, defaultTimeLimit + 1, 1.0, defaultPoolSize));
}

@Test
void condition4() {
assertFalse(testRule(TO_UPPER_LOWER_PATTERN, DEFAULT_TIME_LIMIT + 1, 1.0, DEFAULT_POOL_SIZE + 1));
assertFalse(testRule(toUpperLowerPattern, defaultTimeLimit + 1, 1.0, defaultPoolSize + 1));
}

@Test
void condition5() {
assertTrue(testRule(TO_LOWER_PLACE, DEFAULT_TIME_LIMIT - 1, 0.5, DEFAULT_POOL_SIZE));
assertTrue(testRule(toLowerPlace, defaultTimeLimit - 1, 0.5, defaultPoolSize));
}

@Test
void condition6() {
assertFalse(testRule(TO_LOWER_PLACE, DEFAULT_TIME_LIMIT, 0.5, DEFAULT_POOL_SIZE));
assertFalse(testRule(toLowerPlace, defaultTimeLimit, 0.5, defaultPoolSize));
}

@Test
void condition7() {
assertFalse(testRule(TO_LOWER_PLACE, DEFAULT_TIME_LIMIT - 1, 0.75, DEFAULT_POOL_SIZE));
assertFalse(testRule(toLowerPlace, defaultTimeLimit - 1, 0.75, defaultPoolSize));
}

@Test
void condition8() {
assertTrue(testRule(TO_UPPER_PLACE, DEFAULT_TIME_LIMIT, 0.2, DEFAULT_POOL_SIZE));
assertTrue(testRule(toUpperPlace, defaultTimeLimit, 0.2, defaultPoolSize));
}

@Test
void condition9() {
assertFalse(testRule(TO_UPPER_PLACE, DEFAULT_TIME_LIMIT, 0.5, DEFAULT_POOL_SIZE));
assertFalse(testRule(toUpperPlace, defaultTimeLimit, 0.5, defaultPoolSize));
}

boolean testRule(String matcher, int time, double threshold, int poolSize) {
Expand All @@ -139,13 +139,13 @@ boolean testRule(String matcher, int time, double threshold, int poolSize) {

List<Protocol.PlaceAgentStats> stats() {
Protocol.PlaceAgentStats lowerStats = new Protocol.PlaceAgentStats("ToLowerPlace");
lowerStats.update(DEFAULT_TIME_LIMIT - 4); // MobileAgent-01
lowerStats.update(DEFAULT_TIME_LIMIT - 2); // MobileAgent-02
lowerStats.update(DEFAULT_TIME_LIMIT - 1); // MobileAgent-03
lowerStats.update(defaultTimeLimit - 4); // MobileAgent-01
lowerStats.update(defaultTimeLimit - 2); // MobileAgent-02
lowerStats.update(defaultTimeLimit - 1); // MobileAgent-03

Protocol.PlaceAgentStats upperStats = new Protocol.PlaceAgentStats("ToUpperPlace");
upperStats.update(DEFAULT_TIME_LIMIT - 3); // MobileAgent-04
upperStats.update(DEFAULT_TIME_LIMIT); // MobileAgent-05
upperStats.update(defaultTimeLimit - 3); // MobileAgent-04
upperStats.update(defaultTimeLimit); // MobileAgent-05

return List.of(lowerStats, upperStats);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/kff/KffMemcachedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void testHitWithStoreIdDupe() throws Exception {
assertTrue(mcdFilter.check(TEST_ID_WITH_SPACES, createSums(mcdFilter)), "Filter should hit");
}

private ChecksumResults createSums(KffMemcached mcd) throws NoSuchAlgorithmException {
private static ChecksumResults createSums(KffMemcached mcd) throws NoSuchAlgorithmException {
List<String> kffalgs = new ArrayList<>();
kffalgs.add(mcd.getPreferredAlgorithm());
return new ChecksumCalculator(kffalgs).digest(TEST_PAYLOAD.getBytes());
Expand Down
Loading

0 comments on commit a42e517

Please sign in to comment.