@Test
  public void testInvalidConfigurations() {
    AttributesFactory factory;

    ExpirationAttributes invalidate =
        new ExpirationAttributes(1, ExpirationAction.LOCAL_INVALIDATE);
    ExpirationAttributes destroy = new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY);

    // DataPolicy.REPLICATE is incompatible with
    // ExpirationAction.LOCAL_INVALIDATE
    factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setEntryIdleTimeout(invalidate);
    factory.setStatisticsEnabled(true);
    {
      RegionAttributes ra = factory.create();
      assertEquals(DataPolicy.PRELOADED, ra.getDataPolicy());
      assertEquals(new SubscriptionAttributes(InterestPolicy.ALL), ra.getSubscriptionAttributes());
    }

    // DataPolicy.REPLICATE is incompatible with
    // ExpirationAction.LOCAL_DESTROY.
    factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setEntryIdleTimeout(destroy);
    factory.setStatisticsEnabled(true);
    {
      RegionAttributes ra = factory.create();
      assertEquals(DataPolicy.PRELOADED, ra.getDataPolicy());
      assertEquals(new SubscriptionAttributes(InterestPolicy.ALL), ra.getSubscriptionAttributes());
    }

    // MirrorType KEYS is incompatible with
    // ExpirationAction.LOCAL_INVALIDATE
    factory = new AttributesFactory();
    factory.setMirrorType(MirrorType.KEYS);
    factory.setEntryIdleTimeout(destroy);
    factory.setStatisticsEnabled(true);
    {
      RegionAttributes ra = factory.create();
      assertEquals(DataPolicy.PRELOADED, ra.getDataPolicy());
      assertEquals(new SubscriptionAttributes(InterestPolicy.ALL), ra.getSubscriptionAttributes());
    }

    // MirrorType.KEYS are incompatible with
    // ExpirationAction.LOCAL_DESTROY.
    factory = new AttributesFactory();
    factory.setMirrorType(MirrorType.KEYS);
    factory.setEntryIdleTimeout(destroy);
    factory.setStatisticsEnabled(true);
    {
      RegionAttributes ra = factory.create();
      assertEquals(DataPolicy.PRELOADED, ra.getDataPolicy());
      assertEquals(new SubscriptionAttributes(InterestPolicy.ALL), ra.getSubscriptionAttributes());
    }

    // Entry idle expiration requires that
    // statistics are enabled
    factory = new AttributesFactory();
    factory.setEntryIdleTimeout(destroy);
    factory.setStatisticsEnabled(false);
    try {
      factory.create();
      fail("Should have thrown an IllegalStateException");

    } catch (Exception ex) {
      assertTrue(ex instanceof IllegalStateException);
      // pass...
    }

    // Entry ttl expiration requires that
    // statistics are enabled
    factory = new AttributesFactory();
    factory.setEntryTimeToLive(destroy);
    factory.setStatisticsEnabled(false);
    try {
      factory.create();
      fail("Should have thrown an IllegalStateException");

    } catch (Exception ex) {
      assertTrue(ex instanceof IllegalStateException);
      // pass...
    }

    // MembershipAttributes (required roles)
    // requires distributed scope
    factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    MembershipAttributes ra = new MembershipAttributes(new String[] {"A"});
    factory.setMembershipAttributes(ra);
    try {
      factory.create();
      fail("Should have thrown an IllegalStateException");

    } catch (Exception ex) {
      assertTrue(ex instanceof IllegalStateException);
      // pass...
    }

    // Used mixed mode API for disk store and DWA
    factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    factory.setDiskStoreName("ds1");
    DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
    try {
      factory.setDiskWriteAttributes(dwaf.create());
      fail("Should have thrown an IllegalStateException");
    } catch (Exception ex) {
      assertTrue(ex instanceof IllegalStateException);
      // pass...
    }

    // Used mixed mode API for disk store and DWA
    factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    DiskWriteAttributesFactory dwaf2 = new DiskWriteAttributesFactory();
    factory.setDiskWriteAttributes(dwaf2.create());
    try {
      factory.setDiskStoreName("ds1");
      fail("Should have thrown an IllegalStateException");
    } catch (Exception ex) {
      assertTrue(ex instanceof IllegalStateException);
      // pass...
    }

    // Used mixed mode API for disk store and DWA
    factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    File[] dirs1 = new File[] {new File("").getAbsoluteFile()};
    factory.setDiskStoreName("ds1");

    try {
      factory.setDiskDirs(dirs1);
      fail("Should have thrown an IllegalStateException");
    } catch (Exception ex) {
      assertTrue(ex instanceof IllegalStateException);
      // pass...
    }

    // Used mixed mode API for disk store and DWA
    factory = new AttributesFactory();
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    File[] dirs2 = new File[] {new File("").getAbsoluteFile()};
    factory.setDiskDirs(dirs2);
    try {
      factory.setDiskStoreName("ds1");
      fail("Should have thrown an IllegalStateException");
    } catch (Exception ex) {
      assertTrue(ex instanceof IllegalStateException);
      // pass...
    }

    // Cloning cannot be disabled when a compressor is set
    factory = new AttributesFactory();
    factory.setCompressor(SnappyCompressor.getDefaultInstance());
    factory.setCloningEnabled(false);
    try {
      RegionAttributes ccra = factory.create();
      fail("Should have thrown an IllegalStateException");
    } catch (IllegalStateException expected) {
      // Expected
    }
  }
Tests the {@link AttributesFactory#create} throws the appropriate exception with
poorly-configured factory.
geode-core/src/test/java/org/apache/geode/cache/AttributesFactoryJUnitTest.java