### Question:
AccessInfo { public AccessInfo changeVisibility(int flag) { int currentVisFlags = accFlags & VISIBILITY_FLAGS; if (currentVisFlags == flag) { return this; } int unsetAllVisFlags = accFlags & ~VISIBILITY_FLAGS; return new AccessInfo(unsetAllVisFlags | flag, type); } AccessInfo(int accessFlags, AFType type); boolean containsFlag(int flag); AccessInfo remove(int flag); AccessInfo add(int flag); AccessInfo changeVisibility(int flag); AccessInfo getVisibility(); boolean isPublic(); boolean isProtected(); boolean isPrivate(); boolean isPackagePrivate(); boolean isAbstract(); boolean isInterface(); boolean isAnnotation(); boolean isNative(); boolean isStatic(); boolean isFinal(); boolean isConstructor(); boolean isEnum(); boolean isSynthetic(); boolean isBridge(); boolean isVarArgs(); boolean isSynchronized(); boolean isTransient(); boolean isVolatile(); AFType getType(); String makeString(); String visibilityName(); String rawString(); int rawValue(); @Override String toString(); static final int VISIBILITY_FLAGS; }### Answer:
@Test public void changeVisibility() { AccessInfo accessInfo = new AccessInfo(AccessFlags.ACC_PROTECTED | AccessFlags.ACC_STATIC, AFType.METHOD); AccessInfo result = accessInfo.changeVisibility(AccessFlags.ACC_PUBLIC); assertThat(result.isPublic(), is(true)); assertThat(result.isPrivate(), is(false)); assertThat(result.isProtected(), is(false)); assertThat(result.isStatic(), is(true)); }
@Test public void changeVisibilityNoOp() { AccessInfo accessInfo = new AccessInfo(AccessFlags.ACC_PUBLIC, AFType.METHOD); AccessInfo result = accessInfo.changeVisibility(AccessFlags.ACC_PUBLIC); assertSame(accessInfo, result); }