EqualityTest.java revision 14838:c38ef6119041
177943Sdfr/* 277943Sdfr * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 377943Sdfr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4163898Smarcel * 5163898Smarcel * This code is free software; you can redistribute it and/or modify it 6163898Smarcel * under the terms of the GNU General Public License version 2 only, as 7163898Smarcel * published by the Free Software Foundation. 8163898Smarcel * 9163898Smarcel * This code is distributed in the hope that it will be useful, but WITHOUT 10163898Smarcel * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11163898Smarcel * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1277943Sdfr * version 2 for more details (a copy is included in the LICENSE file that 1377943Sdfr * accompanied this code). 1477943Sdfr * 1577943Sdfr * You should have received a copy of the GNU General Public License version 1677943Sdfr * 2 along with this work; if not, write to the Free Software Foundation, 1777943Sdfr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1877943Sdfr * 1977943Sdfr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2077943Sdfr * or visit www.oracle.com if you need additional information or have any 2177943Sdfr * questions. 2277943Sdfr */ 2377943Sdfr 2477943Sdfr/* 2577943Sdfr * @test 2677943Sdfr * @bug 8071859 2777943Sdfr * @summary Check annotation equality behavior against the invocation handler 2877943Sdfr */ 2977943Sdfr 3077943Sdfrimport java.lang.annotation.*; 31163898Smarcelimport java.lang.reflect.*; 32163898Smarcel 33163898Smarcel@TestAnnotation 34163898Smarcelpublic class EqualityTest { 35163898Smarcel public static void main(String... args) throws Exception { 36163898Smarcel TestAnnotation annotation = 3777943Sdfr EqualityTest.class.getAnnotation(TestAnnotation.class); 3877943Sdfr InvocationHandler handler = Proxy.getInvocationHandler(annotation); 3977943Sdfr 40163898Smarcel testEquality(annotation, handler, false); 4177943Sdfr testEquality(annotation, annotation, true); 4277943Sdfr testEquality(handler, handler, true); 4377943Sdfr } 44163898Smarcel 4577943Sdfr private static void testEquality(Object a, Object b, boolean expected) { 4677943Sdfr boolean result = a.equals(b); 4777943Sdfr if (result != b.equals(a) || result != expected) 4877943Sdfr throw new RuntimeException("Unexpected result"); 4977943Sdfr } 5077943Sdfr} 5177943Sdfr 5277943Sdfr@Retention(RetentionPolicy.RUNTIME) 5377943Sdfr@interface TestAnnotation { 5477943Sdfr} 5577943Sdfr 5677943Sdfr