/** Test if int value are ok. */
 @Test(dataProvider = "persistentSearchChangeTypeData")
 public void checkIntValueTest(Map<Integer, String> expectedValues) throws Exception {
   for (Integer i : expectedValues.keySet()) {
     PersistentSearchChangeType val = PersistentSearchChangeType.valueOf(i);
     String expected = expectedValues.get(i);
     assertEquals(val.toString(), expected);
   }
 }
 /** Create correct values. */
 @DataProvider(name = "persistentSearchChangeTypeData")
 public Object[][] createPersistentSearchChangeTypeData() {
   Map<Integer, String> values = new HashMap<>();
   values.put(1, "add");
   values.put(2, "delete");
   values.put(4, "modify");
   values.put(8, "modDN");
   return new Object[][] {{values}};
 }
  /** Test If we have only the required values. */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkRequiredValuesTest(Map<Integer, String> exceptedValues) throws Exception {
    // Retrieve the values
    PersistentSearchChangeType[] vals = PersistentSearchChangeType.values();

    // Check if we have the correct number
    assertEquals(vals.length, exceptedValues.size());

    // Check if we have the correct int value
    for (PersistentSearchChangeType val : vals) {
      assertTrue(exceptedValues.containsKey(val.intValue()));
    }
  }
  /** Test int to type. */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkIntToTypeTest(Map<Integer, String> exceptedValues) throws Exception {
    Set<Integer> keys = exceptedValues.keySet();

    Set<PersistentSearchChangeType> expectedTypes = new HashSet<>(4);

    for (int i = 1; i <= 15; i++) {
      expectedTypes.clear();
      for (int key : keys) {
        if ((i & key) != 0) {
          expectedTypes.add(PersistentSearchChangeType.valueOf(key));
        }
      }
      Set<PersistentSearchChangeType> returnTypes = PersistentSearchChangeType.intToTypes(i);
      assertEquals(expectedTypes.size(), returnTypes.size());
      for (PersistentSearchChangeType type : expectedTypes) {
        assertTrue(returnTypes.contains(type));
      }
    }

    // We should have an exception
    try {
      PersistentSearchChangeType.intToTypes(0);
      fail();
    } catch (LDAPException expected) {
      assertEquals(
          expected.getMessage(),
          "The provided integer value indicated that there were no persistent search change types, which is not allowed");
    }

    // We should have an exception
    int i = 16;
    try {
      PersistentSearchChangeType.intToTypes(i);
      fail();
    } catch (LDAPException expected) {
      assertEquals(
          expected.getMessage(),
          "The provided integer value "
              + i
              + " was outside the range of acceptable values for an encoded change type set");
    }
  }
 /** Test invalid int values. */
 @Test(dataProvider = "persistentSearchChangeTypeData")
 public void checkInvalidIntTest(Map<Integer, String> exceptedValues) throws Exception {
   Set<Integer> keys = exceptedValues.keySet();
   for (int i = -10; i < 10; i++) {
     if (keys.contains(i)) {
       continue;
     }
     try {
       PersistentSearchChangeType.valueOf(i);
       fail();
     } catch (LDAPException e) {
       assertThat(e.getMessage())
           .contains(
               "The provided integer value "
                   + i
                   + " does not correspond to any persistent search change type");
     }
   }
 }