mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 08:59:01 +00:00
add java 11 support (o) (#1222)
This commit is contained in:
@@ -44,17 +44,17 @@ public class OliphauntPoolTest {
|
||||
@Test
|
||||
public void testSubsequentCheckinCheckout() {
|
||||
assertTimeout(ofMillis(5000), () -> {
|
||||
final OliphauntPool pool = new OliphauntPool();
|
||||
final var pool = new OliphauntPool();
|
||||
assertEquals("Pool available=0 inUse=0", pool.toString());
|
||||
|
||||
final Oliphaunt expectedOliphaunt = pool.checkOut();
|
||||
final var expectedOliphaunt = pool.checkOut();
|
||||
assertEquals("Pool available=0 inUse=1", pool.toString());
|
||||
|
||||
pool.checkIn(expectedOliphaunt);
|
||||
assertEquals("Pool available=1 inUse=0", pool.toString());
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
final Oliphaunt oliphaunt = pool.checkOut();
|
||||
final var oliphaunt = pool.checkOut();
|
||||
assertEquals("Pool available=0 inUse=1", pool.toString());
|
||||
assertSame(expectedOliphaunt, oliphaunt);
|
||||
assertEquals(expectedOliphaunt.getId(), oliphaunt.getId());
|
||||
@@ -73,13 +73,13 @@ public class OliphauntPoolTest {
|
||||
@Test
|
||||
public void testConcurrentCheckinCheckout() {
|
||||
assertTimeout(ofMillis(5000), () -> {
|
||||
final OliphauntPool pool = new OliphauntPool();
|
||||
final var pool = new OliphauntPool();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=0");
|
||||
|
||||
final Oliphaunt firstOliphaunt = pool.checkOut();
|
||||
final var firstOliphaunt = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=1");
|
||||
|
||||
final Oliphaunt secondOliphaunt = pool.checkOut();
|
||||
final var secondOliphaunt = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
|
||||
assertNotSame(firstOliphaunt, secondOliphaunt);
|
||||
@@ -89,7 +89,7 @@ public class OliphauntPoolTest {
|
||||
pool.checkIn(secondOliphaunt);
|
||||
assertEquals(pool.toString(), "Pool available=1 inUse=1");
|
||||
|
||||
final Oliphaunt oliphaunt3 = pool.checkOut();
|
||||
final var oliphaunt3 = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
assertSame(secondOliphaunt, oliphaunt3);
|
||||
|
||||
@@ -97,7 +97,7 @@ public class OliphauntPoolTest {
|
||||
pool.checkIn(firstOliphaunt);
|
||||
assertEquals(pool.toString(), "Pool available=1 inUse=1");
|
||||
|
||||
final Oliphaunt oliphaunt4 = pool.checkOut();
|
||||
final var oliphaunt4 = pool.checkOut();
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
assertSame(firstOliphaunt, oliphaunt4);
|
||||
|
||||
@@ -110,7 +110,7 @@ public class OliphauntPoolTest {
|
||||
|
||||
// The order of the returned instances is not determined, so just put them in a list
|
||||
// and verify if both expected instances are in there.
|
||||
final List<Oliphaunt> oliphaunts = List.of(pool.checkOut(), pool.checkOut());
|
||||
final var oliphaunts = List.of(pool.checkOut(), pool.checkOut());
|
||||
assertEquals(pool.toString(), "Pool available=0 inUse=2");
|
||||
assertTrue(oliphaunts.contains(firstOliphaunt));
|
||||
assertTrue(oliphaunts.contains(secondOliphaunt));
|
||||
|
||||
Reference in New Issue
Block a user