ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicBooleanTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicBooleanTest.java (file contents):
Revision 1.18 by jsr166, Tue Mar 15 19:47:06 2011 UTC vs.
Revision 1.30 by dl, Tue Jan 26 13:33:05 2021 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
10 < import java.util.concurrent.atomic.*;
11 < import java.io.*;
9 > import java.util.concurrent.atomic.AtomicBoolean;
10 >
11 > import junit.framework.Test;
12 > import junit.framework.TestSuite;
13  
14   public class AtomicBooleanTest extends JSR166TestCase {
15      public static void main(String[] args) {
16 <        junit.textui.TestRunner.run(suite());
16 >        main(suite(), args);
17      }
18      public static Test suite() {
19          return new TestSuite(AtomicBooleanTest.class);
# Line 63 | Line 64 | public class AtomicBooleanTest extends J
64       */
65      public void testCompareAndSet() {
66          AtomicBoolean ai = new AtomicBoolean(true);
67 <        assertTrue(ai.compareAndSet(true,false));
67 >        assertTrue(ai.compareAndSet(true, false));
68          assertFalse(ai.get());
69 <        assertTrue(ai.compareAndSet(false,false));
69 >        assertTrue(ai.compareAndSet(false, false));
70          assertFalse(ai.get());
71 <        assertFalse(ai.compareAndSet(true,false));
71 >        assertFalse(ai.compareAndSet(true, false));
72          assertFalse(ai.get());
73 <        assertTrue(ai.compareAndSet(false,true));
73 >        assertTrue(ai.compareAndSet(false, true));
74          assertTrue(ai.get());
75      }
76  
# Line 94 | Line 95 | public class AtomicBooleanTest extends J
95       * repeated weakCompareAndSet succeeds in changing value when equal
96       * to expected
97       */
98 +    @SuppressWarnings("deprecation")
99      public void testWeakCompareAndSet() {
100          AtomicBoolean ai = new AtomicBoolean(true);
101 <        while (!ai.weakCompareAndSet(true,false));
101 >        do {} while (!ai.weakCompareAndSet(true, false));
102          assertFalse(ai.get());
103 <        while (!ai.weakCompareAndSet(false,false));
103 >        do {} while (!ai.weakCompareAndSet(false, false));
104          assertFalse(ai.get());
105 <        while (!ai.weakCompareAndSet(false,true));
105 >        do {} while (!ai.weakCompareAndSet(false, true));
106          assertTrue(ai.get());
107      }
108  
# Line 108 | Line 110 | public class AtomicBooleanTest extends J
110       * getAndSet returns previous value and sets to given value
111       */
112      public void testGetAndSet() {
113 <        AtomicBoolean ai = new AtomicBoolean(true);
114 <        assertEquals(true,ai.getAndSet(false));
115 <        assertEquals(false,ai.getAndSet(false));
116 <        assertEquals(false,ai.getAndSet(true));
117 <        assertTrue(ai.get());
113 >        AtomicBoolean ai = new AtomicBoolean();
114 >        boolean[] booleans = { false, true };
115 >        for (boolean before : booleans)
116 >            for (boolean after : booleans) {
117 >                ai.set(before);
118 >                assertEquals(before, ai.getAndSet(after));
119 >                assertEquals(after, ai.get());
120 >            }
121      }
122  
123      /**
124 <     * a deserialized serialized atomic holds same value
124 >     * a deserialized/reserialized atomic holds same value
125       */
126      public void testSerialization() throws Exception {
127 <        AtomicBoolean l = new AtomicBoolean();
128 <
129 <        l.set(true);
130 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
131 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
132 <        out.writeObject(l);
133 <        out.close();
129 <
130 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
131 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
132 <        AtomicBoolean r = (AtomicBoolean) in.readObject();
133 <        assertEquals(l.get(), r.get());
127 >        AtomicBoolean x = new AtomicBoolean();
128 >        AtomicBoolean y = serialClone(x);
129 >        x.set(true);
130 >        AtomicBoolean z = serialClone(x);
131 >        assertTrue(x.get());
132 >        assertFalse(y.get());
133 >        assertTrue(z.get());
134      }
135  
136      /**
# Line 138 | Line 138 | public class AtomicBooleanTest extends J
138       */
139      public void testToString() {
140          AtomicBoolean ai = new AtomicBoolean();
141 <        assertEquals(ai.toString(), Boolean.toString(false));
141 >        assertEquals(Boolean.toString(false), ai.toString());
142          ai.set(true);
143 <        assertEquals(ai.toString(), Boolean.toString(true));
143 >        assertEquals(Boolean.toString(true), ai.toString());
144      }
145  
146   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines