Skip to content

Commit

Permalink
Use Objects.equals()
Browse files Browse the repository at this point in the history
Use Anonymous type
Use method reference instead Lambda
Replace Loop  with Collection.removeIf()
  • Loading branch information
arturobernalg committed May 27, 2021
1 parent 1077d2b commit fa1012f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/test/java/org/apache/commons/pool2/MethodCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Collections;
import java.util.Arrays;
import java.util.Objects;

/**
* Holds method names, parameters, and return values for tracing method calls.
Expand Down Expand Up @@ -64,13 +65,13 @@ public boolean equals(final Object o) {

final MethodCall that = (MethodCall)o;

if (name != null ? !name.equals(that.name) : that.name != null) {
if (!Objects.equals(name, that.name)) {
return false;
}
if (params != null ? !params.equals(that.params) : that.params != null) {
if (!Objects.equals(params, that.params)) {
return false;
}
return returned != null ? returned.equals(that.returned) : that.returned == null;
return Objects.equals(returned, that.returned);
}

public String getName() {
Expand Down
8 changes: 1 addition & 7 deletions src/test/java/org/apache/commons/pool2/TestObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ private static void clear(final MethodCallPoolableObjectFactory factory, final L
}

static void removeDestroyObjectCall(final List<MethodCall> calls) {
final Iterator<MethodCall> iter = calls.iterator();
while (iter.hasNext()) {
final MethodCall call = iter.next();
if ("destroyObject".equals(call.getName())) {
iter.remove();
}
}
calls.removeIf(call -> "destroyObject".equals(call.getName()));
}

private static void reset(final ObjectPool<Object> pool, final MethodCallPoolableObjectFactory factory, final List<MethodCall> expectedMethods) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2562,14 +2562,7 @@ public void testReturnObject() throws Exception {
assertEquals(1, genericObjectPool.getNumActive());
assertEquals(0, genericObjectPool.getNumIdle());

final Thread t = new Thread() {

@Override
public void run() {
genericObjectPool.close();
}

};
final Thread t = new Thread(() -> genericObjectPool.close());
t.start();

genericObjectPool.returnObject(active);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testAccessAfterInvalidate() throws Exception {
assertNotNull(obj);

assertThrows(IllegalStateException.class,
() -> obj.getData() );
obj::getData);

}

Expand All @@ -147,7 +147,7 @@ public void testAccessAfterReturn() throws Exception {

assertNotNull(obj);
assertThrows(IllegalStateException.class,
() -> obj.getData());
obj::getData);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void testAccessAfterInvalidate() throws Exception {
assertNotNull(obj);

assertThrows(IllegalStateException.class,
() -> obj.getData());
obj::getData);

}

Expand All @@ -141,7 +141,7 @@ public void testAccessAfterReturn() throws Exception {
assertNotNull(obj);

assertThrows(IllegalStateException.class,
() -> obj.getData());
obj::getData);
}


Expand Down

0 comments on commit fa1012f

Please sign in to comment.