public static String getMbeanNameName(final ObjectName objectName) {
    Matcher matcher = MBEAN_NAME_PATTERN.matcher(objectName.toString());
    if (matcher.matches()) {
      return matcher.group(2);
    } else {
      throw new IllegalArgumentException(
          objectName + " is not a valid Hadoop mbean");
    }
  }
@Test
  public void testGetMbeanNameName() {
    HashMap<String, String> properties = new HashMap<>();

    ObjectName mBeanName = MBeans.getMBeanName("Service",
        "Name", properties);

    Assert.assertEquals("Service",
        MBeans.getMbeanNameService(mBeanName));

    properties.put("key", "value");
    mBeanName = MBeans.getMBeanName(
        "Service",
        "Name",
        properties);

    Assert.assertEquals("Service",
        MBeans.getMbeanNameService(mBeanName));

  }