From 28320018e8c6f97a37389aa14af3e14c5b082701 Mon Sep 17 00:00:00 2001 From: syev Date: Fri, 24 Oct 2014 12:11:36 +0200 Subject: Tests on access permissions checks. --- .../test/java/org/osjava/jardiff/ToolsTest.java | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/api/src/test/java/org/osjava/jardiff/ToolsTest.java b/api/src/test/java/org/osjava/jardiff/ToolsTest.java index 39683bd..7af6d45 100644 --- a/api/src/test/java/org/osjava/jardiff/ToolsTest.java +++ b/api/src/test/java/org/osjava/jardiff/ToolsTest.java @@ -58,10 +58,20 @@ public class ToolsTest { assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_FINAL, 0)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); - // No matter the final access, can't become protected or private or - // package if it was public. + // A field can become more accessible + assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PUBLIC)); + assertFalse(Tools.isFieldAccessChange(0, Opcodes.ACC_PUBLIC)); + assertFalse(Tools.isFieldAccessChange(0, Opcodes.ACC_PROTECTED)); + assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PUBLIC)); + assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PROTECTED)); + assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PRIVATE, 0)); + // ...but can't become less accessible assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, 0)); assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PROTECTED)); + assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PRIVATE)); + assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PROTECTED, 0)); + assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PRIVATE)); + assertTrue(Tools.isFieldAccessChange(0, Opcodes.ACC_PRIVATE)); // A field can't change static assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_STATIC, 0)); @@ -96,10 +106,21 @@ public class ToolsTest { assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC, Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL)); - // No matter the final access, can't become protected or private or - // package if it was public. + // A method can become more accessible + assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PUBLIC)); + assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_PUBLIC)); + assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_PROTECTED)); + assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PUBLIC)); + assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PROTECTED)); + assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, 0)); + // ...but can't become less accessible assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, 0)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PROTECTED)); + assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PRIVATE)); + assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, 0)); + assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PRIVATE)); + assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_PRIVATE)); + // A class or method can become concrete. assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT, 0)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); -- cgit v1.2.3