The file is ObserverTest.java add 2 new tests f or the update() method declared
ID: 3716725 • Letter: T
Question
The file is ObserverTest.java add 2 new tests f or the update() method declared in com/FlyweightObserver.java . The tests will need both subjects and observers.
package com.hundredwordsgof.observer;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class ObserverTest {
@Test
public void testObserver() throws CloneNotSupportedException {
ConcreteSubject subject = new ConcreteSubject();
Observer observer = new ConcreteObserver(subject);
subject.attach(observer);
subject.setState(1);
assertEquals(1, ((ConcreteObserver) observer).getObserverState());
subject.dettach(observer);
subject.setState(0);
assertEquals(1, ((ConcreteObserver) observer).getObserverState());
}
}
Explanation / Answer
package com.hundredwordsgof.observer;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class ObserverTest {
@Test
public void testObserver() throws CloneNotSupportedException {
ConcreteSubject subject = new ConcreteSubject();
Observer observer = new ConcreteObserver(subject);
subject.attach(observer);
subject.setState(1);
assertEquals(1, ((ConcreteObserver) observer).getObserverState());
subject.dettach(observer);
subject.setState(0);
assertEquals(1, ((ConcreteObserver) observer).getObserverState());
}
}
Kindly provide me the implementation of FlyweightObserver.java so that I can assist you with this assignment.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.