rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionClassValueTest.java
changeset 1985 cd1cc103a03c
parent 1982 cee8ecc45816
     1.1 --- a/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionClassValueTest.java	Tue Jan 17 06:14:39 2017 +0100
     1.2 +++ b/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionClassValueTest.java	Tue Jan 17 07:04:06 2017 +0100
     1.3 @@ -17,6 +17,8 @@
     1.4   */
     1.5  package org.apidesign.bck2brwsr.tck;
     1.6  
     1.7 +import java.io.Serializable;
     1.8 +import java.lang.ClassValue;
     1.9  import org.apidesign.bck2brwsr.vmtest.Compare;
    1.10  import org.apidesign.bck2brwsr.vmtest.VMTest;
    1.11  import org.testng.annotations.Factory;
    1.12 @@ -56,13 +58,6 @@
    1.13          return one == two;
    1.14      }
    1.15  
    1.16 -    @Compare public boolean valueCanBeCleared() {
    1.17 -        String one = LOWER.get(Runnable.class);
    1.18 -        LOWER.remove(Runnable.class);
    1.19 -        String two = LOWER.get(Runnable.class);
    1.20 -        return one != two;
    1.21 -    }
    1.22 -
    1.23      @Compare public String upperObject() {
    1.24          return UPPER.get(Object.class);
    1.25      }
    1.26 @@ -79,6 +74,47 @@
    1.27          return LOWER.get(CharSequence.class) + UPPER.get(CharSequence.class);
    1.28      }
    1.29  
    1.30 +    private static final class CountingNull extends ClassValue<Object> {
    1.31 +        int cnt;
    1.32 +
    1.33 +        @Override
    1.34 +        protected Object computeValue(Class<?> type) {
    1.35 +            cnt++;
    1.36 +            return null;
    1.37 +        }
    1.38 +    }
    1.39 +
    1.40 +    @Compare public int getNullThreeTimes() {
    1.41 +        CountingNull counter = new CountingNull();
    1.42 +        Object o1 = counter.get(Serializable.class);
    1.43 +        Object o2 = counter.get(Serializable.class);
    1.44 +        Object o3 = counter.get(Serializable.class);
    1.45 +        assert o1 == null;
    1.46 +        assert o2 == null;
    1.47 +        assert o3 == null;
    1.48 +        return counter.cnt;
    1.49 +    }
    1.50 +
    1.51 +    private static final class NewObj extends ClassValue<Integer> {
    1.52 +        int cnt;
    1.53 +
    1.54 +        @Override
    1.55 +        protected Integer computeValue(Class<?> type) {
    1.56 +            cnt++;
    1.57 +            return new Integer(cnt);
    1.58 +        }
    1.59 +    }
    1.60 +
    1.61 +    @Compare public boolean valueCanBeCleared() {
    1.62 +        NewObj cache = new NewObj();
    1.63 +        Integer one = cache.get(Runnable.class);
    1.64 +        Integer two = cache.get(Runnable.class);
    1.65 +        assert one == two;
    1.66 +        cache.remove(Runnable.class);
    1.67 +        Integer three = cache.get(Runnable.class);
    1.68 +        return one != three;
    1.69 +    }
    1.70 +
    1.71      @Factory
    1.72      public static Object[] create() {
    1.73          return VMTest.create(ReflectionClassValueTest.class);