@Test
 public void testBaseAddObject() throws Exception {
   try {
     _pool = makeEmptyPool(3);
   } catch (UnsupportedOperationException e) {
     return; // skip this test if unsupported
   }
   try {
     assertEquals(0, _pool.getNumIdle());
     assertEquals(0, _pool.getNumActive());
     _pool.addObject();
     assertEquals(1, _pool.getNumIdle());
     assertEquals(0, _pool.getNumActive());
     Object obj = _pool.borrowObject();
     assertEquals(getNthObject(0), obj);
     assertEquals(0, _pool.getNumIdle());
     assertEquals(1, _pool.getNumActive());
     _pool.returnObject(obj);
     assertEquals(1, _pool.getNumIdle());
     assertEquals(0, _pool.getNumActive());
   } catch (UnsupportedOperationException e) {
     return; // skip this test if one of those calls is unsupported
   } finally {
     _pool.close();
   }
 }
 @Test
 public void testBaseInvalidateObject() throws Exception {
   try {
     _pool = makeEmptyPool(3);
   } catch (UnsupportedOperationException e) {
     return; // skip this test if unsupported
   }
   assertEquals(0, _pool.getNumActive());
   assertEquals(0, _pool.getNumIdle());
   Object obj0 = _pool.borrowObject();
   Object obj1 = _pool.borrowObject();
   assertEquals(2, _pool.getNumActive());
   assertEquals(0, _pool.getNumIdle());
   _pool.invalidateObject(obj0);
   assertEquals(1, _pool.getNumActive());
   assertEquals(0, _pool.getNumIdle());
   _pool.invalidateObject(obj1);
   assertEquals(0, _pool.getNumActive());
   assertEquals(0, _pool.getNumIdle());
   _pool.close();
 }
  // tests
  @Test
  public void testUnsupportedOperations() throws Exception {
    if (!getClass().equals(TestBaseObjectPool.class)) {
      return; // skip redundant tests
    }
    ObjectPool<Object> pool =
        new BaseObjectPool<Object>() {
          @Override
          public Object borrowObject() {
            return null;
          }

          @Override
          public void returnObject(Object obj) {}

          @Override
          public void invalidateObject(Object obj) {}
        };

    assertTrue("Negative expected.", pool.getNumIdle() < 0);
    assertTrue("Negative expected.", pool.getNumActive() < 0);

    try {
      pool.clear();
      fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // expected
    }

    try {
      pool.addObject();
      fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // expected
    }
  }