Star { void setMemento(StarMemento memento) { StarMementoInternal state = (StarMementoInternal) memento; this.type = state.getType(); this.ageYears = state.getAgeYears(); this.massTons = state.getMassTons(); } Star(StarType startType, int startAge, int startMass); void timePasses(); @Override String toString();  }
@Test public void testSetMemento() { final Star star = new Star(StarType.SUN, 1, 2); final StarMemento firstMemento = star.getMemento(); assertEquals("sun age: 1 years mass: 2 tons", star.toString()); star.timePasses(); final StarMemento secondMemento = star.getMemento(); assertEquals("red giant age: 2 years mass: 16 tons", star.toString()); star.timePasses(); final StarMemento thirdMemento = star.getMemento(); assertEquals("white dwarf age: 4 years mass: 128 tons", star.toString()); star.timePasses(); assertEquals("supernova age: 8 years mass: 1024 tons", star.toString()); star.setMemento(thirdMemento); assertEquals("white dwarf age: 4 years mass: 128 tons", star.toString()); star.timePasses(); assertEquals("supernova age: 8 years mass: 1024 tons", star.toString()); star.setMemento(secondMemento); assertEquals("red giant age: 2 years mass: 16 tons", star.toString()); star.setMemento(firstMemento); assertEquals("sun age: 1 years mass: 2 tons", star.toString()); }