public void testLowLevelMaterializerFailOnIncompatible() throws Exception {
   AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
   DeserializationConfig config = new ObjectMapper().getDeserializationConfig();
   try {
     mat.materializeClass(config, config.constructType(InvalidBean.class));
     fail("Expected exception for incompatible property types");
   } catch (IllegalArgumentException e) {
     verifyException(e, "incompatible types");
   }
 }
 public void testLowLevelMaterializerFailOnUnrecognized() throws Exception {
   AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
   //  by default early failure is disabled, enable:
   mat.enable(AbstractTypeMaterializer.Feature.FAIL_ON_UNMATERIALIZED_METHOD);
   DeserializationConfig config = new ObjectMapper().getDeserializationConfig();
   try {
     mat.materializeClass(config, config.constructType(PartialBean.class));
     fail("Expected exception for unrecognized method");
   } catch (IllegalArgumentException e) {
     verifyException(e, "Unrecognized abstract method 'foobar'");
   }
 }
 /**
  * Test to verify that materializer will by default create exception-throwing methods for
  * "unknown" abstract methods
  */
 public void testPartialBean() throws Exception {
   ObjectMapper mapper = new ObjectMapper();
   AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
   // ensure that we will only get deferred error methods
   mat.disable(AbstractTypeMaterializer.Feature.FAIL_ON_UNMATERIALIZED_METHOD);
   mapper.registerModule(new MrBeanModule(mat));
   PartialBean bean = mapper.readValue("{\"ok\":true}", PartialBean.class);
   assertNotNull(bean);
   assertTrue(bean.isOk());
   // and then exception
   try {
     bean.foobar();
   } catch (UnsupportedOperationException e) {
     verifyException(e, "Unimplemented method 'foobar'");
   }
 }
  /** First test verifies that bean builder works as expected */
  public void testLowLevelMaterializer() throws Exception {
    AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
    DeserializationConfig config = new ObjectMapper().getDeserializationConfig();
    Class<?> impl = mat.materializeClass(config, config.constructType(Bean.class));
    assertNotNull(impl);
    assertTrue(Bean.class.isAssignableFrom(impl));
    // also, let's instantiate to make sure:
    Object ob = impl.newInstance();
    // and just for good measure do actual cast
    Bean bean = (Bean) ob;
    // call something to ensure generation worked...
    assertNull(bean.getA());

    // Also: let's verify that we can handle dup calls:
    Class<?> impl2 = mat.materializeClass(config, config.constructType(Bean.class));
    assertNotNull(impl2);
    assertSame(impl, impl2);
  }