1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package libcore.libcore.internal; 18 19 import java.io.IOException; 20 import java.util.Arrays; 21 import java.util.Objects; 22 import java.util.concurrent.atomic.AtomicReference; 23 import junit.framework.TestCase; 24 import libcore.internal.Java9LanguageFeatures; 25 26 public class Java9LanguageFeaturesTest extends TestCase { 27 28 public static class SimplePerson implements Java9LanguageFeatures.Person { 29 private final String name; SimplePerson(String name)30 public SimplePerson(String name) { this.name = Objects.requireNonNull(name); } toString()31 @Override public String toString() { return "Person: " + name; } name()32 @Override public String name() { return name; } 33 } 34 testPrivateInterfaceMethods()35 public void testPrivateInterfaceMethods() { 36 assertFalse(new SimplePerson("Anna").isPalindrome()); 37 assertTrue(new SimplePerson("Anna").isPalindromeIgnoreCase()); 38 assertTrue(new SimplePerson("anna").isPalindrome()); 39 assertTrue(new SimplePerson("bob").isPalindrome()); 40 assertFalse(new SimplePerson("larry").isPalindrome()); 41 assertFalse(new SimplePerson("larry").isPalindromeIgnoreCase()); 42 } 43 testTryOnEffectivelyFinalVariables()44 public void testTryOnEffectivelyFinalVariables() throws IOException { 45 byte[] data = "Hello, world!".getBytes(); 46 byte[] dataCopy = Java9LanguageFeatures.copy(data); 47 assertTrue(Arrays.equals(data, dataCopy)); 48 assertTrue(data != dataCopy); 49 } 50 testDiamondOnAnonymousClasses()51 public void testDiamondOnAnonymousClasses() { 52 AtomicReference<String> ref = new Java9LanguageFeatures().createReference("Hello, world"); 53 assertSame("Hello, world", ref.get()); 54 } 55 testSafeVarargsOnPrivateMethod()56 public void testSafeVarargsOnPrivateMethod() { 57 assertEquals("[23, and, 42]", Java9LanguageFeatures.toListString(23, "and", 42L)); 58 } 59 60 } 61