-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathClockTest.java
More file actions
40 lines (35 loc) · 2.29 KB
/
Copy pathClockTest.java
File metadata and controls
40 lines (35 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package singleton;
import junit.framework.TestCase;
import org.junit.Test;
public class ClockTest extends TestCase {
@Test
public void test() {
Clock clockOutsideTheParadise = Clock.getClock();
Clock clockAtTheTicketCounter = Clock.getClock();
Clock clockInTheRestaurant = Clock.getClock();
System.out.println("1# Functional Test");
System.out.println("Initial States:");
System.out.print("clockOutsideTheParadise:getInstance:("+clockOutsideTheParadise.hashCode()+"): ");
System.out.println("clockOutsideTheParadise's time: "+clockOutsideTheParadise.getTime());
System.out.print("clockAtTheTicketCounter:getInstance:("+clockAtTheTicketCounter.hashCode()+"): ");
System.out.println("clockAtTheTicketCounter's time: "+clockAtTheTicketCounter.getTime());
System.out.print("clockInTheRestaurant:getInstance:("+clockInTheRestaurant.hashCode()+"): ");
System.out.println("clockInTheRestaurant's time: "+clockInTheRestaurant.getTime());
clockAtTheTicketCounter.setTime("11:45:14");
System.out.println("\nUpdated States:");
System.out.print("clockOutsideTheParadise:getInstance:("+clockOutsideTheParadise.hashCode()+"): ");
System.out.println("clockOutsideTheParadise's time: "+clockOutsideTheParadise.getTime());
System.out.print("clockAtTheTicketCounter:getInstance:("+clockAtTheTicketCounter.hashCode()+"): ");
System.out.println("clockAtTheTicketCounter's time: "+clockAtTheTicketCounter.getTime());
System.out.print("clockInTheRestaurant:getInstance:("+clockInTheRestaurant.hashCode()+"): ");
System.out.println("clockInTheRestaurant's time: "+clockInTheRestaurant.getTime());
System.out.println("\n2# Instance Test");
if ((clockOutsideTheParadise == clockAtTheTicketCounter)
& (clockOutsideTheParadise == clockInTheRestaurant)) {
System.out.println("clockOutsideTheParadise:getInstance:("+clockOutsideTheParadise.hashCode()+")");
System.out.println("clockAtTheTicketCounter:getInstance:("+clockAtTheTicketCounter.hashCode()+")");
System.out.println("clockInTheRestaurant:getInstance:("+clockInTheRestaurant.hashCode()+")");
System.out.println("Three clocks are the same instances.");
}
}
}