1.1 --- a/samples/privilegedcreator/src/org/apidesign/privileged/api/Mutex.java Mon May 25 21:49:25 2009 +0200
1.2 +++ b/samples/privilegedcreator/src/org/apidesign/privileged/api/Mutex.java Tue May 26 09:01:40 2009 +0200
1.3 @@ -19,7 +19,7 @@
1.4 public Mutex() {
1.5 }
1.6
1.7 - public void readAccess(Runnable r) {
1.8 + public void withLock(Runnable r) {
1.9 try {
1.10 lock.lock();
1.11 r.run();
1.12 @@ -40,11 +40,11 @@
1.13 public static final class Privileged {
1.14 private Mutex mutex;
1.15
1.16 - public void enterReadAccess() {
1.17 + public void lock() {
1.18 mutex.lock.lock();
1.19 }
1.20
1.21 - public void exitReadAccess() {
1.22 + public void unlock() {
1.23 mutex.lock.unlock();
1.24 }
1.25 }
2.1 --- a/samples/privilegedcreator/test/api/MutexTest.java Mon May 25 21:49:25 2009 +0200
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,55 +0,0 @@
2.4 -package api;
2.5 -
2.6 -import org.apidesign.privileged.api.Mutex;
2.7 -import org.junit.After;
2.8 -import org.junit.AfterClass;
2.9 -import org.junit.Before;
2.10 -import org.junit.BeforeClass;
2.11 -import org.junit.Test;
2.12 -import static org.junit.Assert.*;
2.13 -
2.14 -public class MutexTest {
2.15 - // BEGIN: mutex.init
2.16 - private static final Mutex.Privileged PRIVILEGED = new Mutex.Privileged();
2.17 - public static final Mutex MUTEX = new Mutex(PRIVILEGED);
2.18 - // END: mutex.init
2.19 -
2.20 - public MutexTest() {
2.21 - }
2.22 -
2.23 - /**
2.24 - * Test of readAccess method, of class Mutex.
2.25 - */
2.26 - @Test
2.27 - public void readAccess() {
2.28 - // BEGIN: mutex.use
2.29 - class R implements Runnable {
2.30 - int cnt;
2.31 -
2.32 - public void run() {
2.33 - cnt++;
2.34 - }
2.35 - }
2.36 - R r = new R();
2.37 - MUTEX.readAccess(r);
2.38 - assertEquals("Counter increased", 1, r.cnt);
2.39 - // END: mutex.use
2.40 - }
2.41 -
2.42 - @Test
2.43 - public void usePrivileged() {
2.44 - int cnt = 0;
2.45 - // BEGIN: mutex.privileged
2.46 - PRIVILEGED.enterReadAccess();
2.47 - try {
2.48 - // do the operation
2.49 - cnt++;
2.50 - } finally {
2.51 - PRIVILEGED.exitReadAccess();
2.52 - }
2.53 - assertEquals("Counter increased", 1, cnt);
2.54 - // END: mutex.privileged
2.55 -
2.56 - }
2.57 -
2.58 -}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/samples/privilegedcreator/test/org/apidesign/privileged/use/MutexTest.java Tue May 26 09:01:40 2009 +0200
3.3 @@ -0,0 +1,51 @@
3.4 +package org.apidesign.privileged.use;
3.5 +
3.6 +import org.apidesign.privileged.api.Mutex;
3.7 +import org.junit.Test;
3.8 +import static org.junit.Assert.*;
3.9 +
3.10 +public class MutexTest {
3.11 + // BEGIN: mutex.init
3.12 + private static final Mutex.Privileged PRIVILEGED = new Mutex.Privileged();
3.13 + public static final Mutex MUTEX = new Mutex(PRIVILEGED);
3.14 + // END: mutex.init
3.15 +
3.16 + public MutexTest() {
3.17 + }
3.18 +
3.19 + /**
3.20 + * Test of withLock method, of class Mutex.
3.21 + */
3.22 + @Test
3.23 + public void readAccess() {
3.24 + // BEGIN: mutex.use
3.25 + class R implements Runnable {
3.26 + int cnt;
3.27 +
3.28 + public void run() {
3.29 + cnt++;
3.30 + }
3.31 + }
3.32 + R r = new R();
3.33 + MUTEX.withLock(r);
3.34 + assertEquals("Counter increased", 1, r.cnt);
3.35 + // END: mutex.use
3.36 + }
3.37 +
3.38 + @Test
3.39 + public void usePrivileged() {
3.40 + int cnt = 0;
3.41 + // BEGIN: mutex.privileged
3.42 + try {
3.43 + PRIVILEGED.lock();
3.44 + // do the operation
3.45 + cnt++;
3.46 + } finally {
3.47 + PRIVILEGED.unlock();
3.48 + }
3.49 + assertEquals("Counter increased", 1, cnt);
3.50 + // END: mutex.privileged
3.51 +
3.52 + }
3.53 +
3.54 +}