1 4 package com.tc.config.schema.dynamic; 5 6 import com.tc.test.TCTestCase; 7 8 11 public class CompoundConfigItemListenerTest extends TCTestCase { 12 13 private MockConfigItemListener listener1; 14 private MockConfigItemListener listener2; 15 16 private CompoundConfigItemListener listener; 17 18 private Object oldValue1; 19 private Object oldValue2; 20 private Object newValue1; 21 private Object newValue2; 22 23 public void setUp() throws Exception { 24 this.listener1 = new MockConfigItemListener(); 25 this.listener2 = new MockConfigItemListener(); 26 27 this.listener = new CompoundConfigItemListener(); 28 29 this.oldValue1 = new Object (); 30 this.oldValue2 = new Object (); 31 this.newValue1 = new Object (); 32 this.newValue2 = new Object (); 33 } 34 35 public void testAll() throws Exception { 36 try { 37 this.listener.addListener(null); 38 fail("Didn't get NPE on no listener"); 39 } catch (NullPointerException npe) { 40 } 42 43 try { 44 this.listener.removeListener(null); 45 fail("Didn't get NPE on no listener"); 46 } catch (NullPointerException npe) { 47 } 49 50 this.listener.valueChanged(this.oldValue1, this.newValue1); 51 assertEquals(0, this.listener1.getNumValueChangeds()); 52 assertEquals(0, this.listener2.getNumValueChangeds()); 53 54 this.listener1.reset(); 55 this.listener2.reset(); 56 57 this.listener.addListener(this.listener1); 58 this.listener.valueChanged(this.oldValue1, this.newValue1); 59 60 assertEquals(1, this.listener1.getNumValueChangeds()); 61 assertSame(this.oldValue1, this.listener1.getLastOldValue()); 62 assertSame(this.newValue1, this.listener1.getLastNewValue()); 63 assertEquals(0, this.listener2.getNumValueChangeds()); 64 65 this.listener1.reset(); 66 this.listener2.reset(); 67 68 this.listener.addListener(this.listener2); 69 this.listener.valueChanged(this.oldValue2, this.newValue2); 70 71 assertEquals(1, this.listener1.getNumValueChangeds()); 72 assertSame(this.oldValue2, this.listener1.getLastOldValue()); 73 assertSame(this.newValue2, this.listener1.getLastNewValue()); 74 assertEquals(1, this.listener2.getNumValueChangeds()); 75 assertSame(this.oldValue2, this.listener2.getLastOldValue()); 76 assertSame(this.newValue2, this.listener2.getLastNewValue()); 77 78 this.listener1.reset(); 79 this.listener2.reset(); 80 81 this.listener.removeListener(this.listener1); 82 this.listener.valueChanged(this.oldValue1, this.newValue1); 83 84 assertEquals(0, this.listener1.getNumValueChangeds()); 85 assertEquals(1, this.listener2.getNumValueChangeds()); 86 assertSame(this.oldValue1, this.listener2.getLastOldValue()); 87 assertSame(this.newValue1, this.listener2.getLastNewValue()); 88 89 this.listener1.reset(); 90 this.listener2.reset(); 91 92 this.listener.removeListener(this.listener2); 93 this.listener.valueChanged(this.oldValue2, this.newValue2); 94 95 assertEquals(0, this.listener1.getNumValueChangeds()); 96 assertEquals(0, this.listener2.getNumValueChangeds()); 97 } 98 99 } 100 | Popular Tags |