1 10 package org.picocontainer.testmodel; 11 12 import junit.framework.TestCase; 13 14 import org.picocontainer.Disposable; 15 import org.picocontainer.PicoContainer; 16 import org.picocontainer.Startable; 17 18 19 public abstract class RecordingLifecycle implements Startable, Disposable { 20 private final StringBuffer recording; 21 22 protected RecordingLifecycle(StringBuffer recording) { 23 this.recording = recording; 24 } 25 26 public void start() { 27 recording.append("<" + code()); 28 } 29 30 public void stop() { 31 recording.append(code() + ">"); 32 } 33 34 public void dispose() { 35 recording.append("!" + code()); 36 } 37 38 public String recording() { 39 return recording.toString(); 40 } 41 42 private String code() { 43 String name = getClass().getName(); 44 int idx = Math.max(name.lastIndexOf('$'), name.lastIndexOf('.')); 45 return name.substring(idx + 1); 46 } 47 48 public interface Recorder extends Startable, Disposable { 49 String recording(); 50 } 51 52 public static class One extends RecordingLifecycle implements Recorder { 53 public One(StringBuffer sb) { 54 super(sb); 55 } 56 } 57 58 public static class Two extends RecordingLifecycle { 59 public Two(StringBuffer sb, One one) { 60 super(sb); 61 TestCase.assertNotNull(one); 62 } 63 } 64 65 public static class Three extends RecordingLifecycle { 66 public Three(StringBuffer sb, One one, Two two) { 67 super(sb); 68 TestCase.assertNotNull(one); 69 TestCase.assertNotNull(two); 70 } 71 } 72 73 public static class Four extends RecordingLifecycle { 74 public Four(StringBuffer sb, Two two, Three three, One one) { 75 super(sb); 76 TestCase.assertNotNull(one); 77 TestCase.assertNotNull(two); 78 TestCase.assertNotNull(three); 79 } 80 } 81 82 public static class FiveTriesToBeMalicious extends RecordingLifecycle { 83 public FiveTriesToBeMalicious(StringBuffer sb, PicoContainer pc) { 84 super(sb); 85 TestCase.assertNotNull(pc); 86 sb.append("Whao! Should not get instantiated!!"); 87 } 88 } 89 90 } | Popular Tags |