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 package com.google.inject; 18 19 import static com.google.inject.Asserts.assertSimilarWhenReserialized; 20 21 import java.io.IOException; 22 import java.io.Serializable; 23 import java.util.List; 24 import junit.framework.AssertionFailedError; 25 import junit.framework.TestCase; 26 27 /** @author jessewilson@google.com (Jesse Wilson) */ 28 public class SerializationTest extends TestCase { 29 testAbstractModuleIsSerializable()30 public void testAbstractModuleIsSerializable() throws IOException { 31 Asserts.reserialize(new MyAbstractModule()); 32 } 33 34 static class MyAbstractModule extends AbstractModule implements Serializable { 35 } 36 testCreationExceptionIsSerializable()37 public void testCreationExceptionIsSerializable() throws IOException { 38 assertSimilarWhenReserialized(createCreationException()); 39 } 40 createCreationException()41 private CreationException createCreationException() { 42 try { 43 Guice.createInjector( 44 new AbstractModule() { 45 @Override 46 protected void configure() { 47 bind(List.class); 48 } 49 }); 50 throw new AssertionFailedError(); 51 } catch (CreationException e) { 52 return e; 53 } 54 } 55 56 static class A { 57 @Inject B b; 58 } 59 60 static class B {} 61 } 62