Home | History | Annotate | Download | only in inject
      1 /**
      2  * Copyright (C) 2008 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 
     18 package com.google.inject;
     19 
     20 import static com.google.inject.Asserts.assertSimilarWhenReserialized;
     21 
     22 import junit.framework.AssertionFailedError;
     23 import junit.framework.TestCase;
     24 
     25 import java.io.IOException;
     26 import java.io.Serializable;
     27 import java.util.List;
     28 
     29 /**
     30  * @author jessewilson (at) google.com (Jesse Wilson)
     31  */
     32 public class SerializationTest extends TestCase {
     33 
     34   public void testAbstractModuleIsSerializable() throws IOException {
     35     Asserts.reserialize(new MyAbstractModule());
     36   }
     37   static class MyAbstractModule extends AbstractModule implements Serializable {
     38     protected void configure() {}
     39   }
     40 
     41   public void testCreationExceptionIsSerializable() throws IOException {
     42     assertSimilarWhenReserialized(createCreationException());
     43   }
     44 
     45   private CreationException createCreationException() {
     46     try {
     47       Guice.createInjector(new AbstractModule() {
     48         protected void configure() {
     49           bind(List.class);
     50         }
     51       });
     52       throw new AssertionFailedError();
     53     } catch (CreationException e) {
     54       return e;
     55     }
     56   }
     57 
     58   static class A {
     59     @Inject B b;
     60   }
     61 
     62   static class B {}
     63 }
     64