@Test
  public void testSetListRemoveCP() throws Exception {
    TableDescriptor desc =
      TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
    // Check that any coprocessor is present.
    assertTrue(desc.getCoprocessorDescriptors().isEmpty());

    // simple CP
    String className1 = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
    String className2 = "org.apache.hadoop.hbase.coprocessor.SampleRegionWALObserver";
    // Add the 1 coprocessor and check if present.
    desc = TableDescriptorBuilder.newBuilder(desc).setCoprocessor(className1).build();
    assertTrue(desc.getCoprocessorDescriptors().size() == 1);
    assertTrue(desc.getCoprocessorDescriptors().stream().map(CoprocessorDescriptor::getClassName)
      .anyMatch(name -> name.equals(className1)));
    // Add the 2nd coprocessor and check if present.
    // remove it and check that it is gone
    desc = TableDescriptorBuilder.newBuilder(desc)

      .setCoprocessor(className2).build();
    assertTrue(desc.getCoprocessorDescriptors().size() == 2);
    assertTrue(desc.getCoprocessorDescriptors().stream().map(CoprocessorDescriptor::getClassName)
      .anyMatch(name -> name.equals(className2)));
    // Remove one and check
    desc = TableDescriptorBuilder.newBuilder(desc)

      .removeCoprocessor(className1).build();
    assertTrue(desc.getCoprocessorDescriptors().size() == 1);
    assertFalse(desc.getCoprocessorDescriptors().stream().map(CoprocessorDescriptor::getClassName)
      .anyMatch(name -> name.equals(className1)));
    assertTrue(desc.getCoprocessorDescriptors().stream().map(CoprocessorDescriptor::getClassName)
      .anyMatch(name -> name.equals(className2)));
    // Remove the last and check
    desc = TableDescriptorBuilder.newBuilder(desc)

      .removeCoprocessor(className2).build();
    assertTrue(desc.getCoprocessorDescriptors().isEmpty());
    assertFalse(desc.getCoprocessorDescriptors().stream().map(CoprocessorDescriptor::getClassName)
      .anyMatch(name -> name.equals(className1)));
    assertFalse(desc.getCoprocessorDescriptors().stream().map(CoprocessorDescriptor::getClassName)
      .anyMatch(name -> name.equals(className2)));
  }
Test cps in the table description.
@throws Exception if setting a coprocessor fails
hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableDescriptorBuilder.java