+
+class AccessAuthorizerTest {
+
+ private val accessAuthorizer = AccessAuthorizer()
+
+ @Test
+ fun `access authorizer is instantiated as singleton`() {
+ val injector = Guice.createInjector()
+ assertThat(injector.getInstance(AccessAuthorizer::class.java), sameInstance(injector.getInstance(AccessAuthorizer::class.java)))
+ }
+
+ @Test
+ fun `access authorizer makes correct decisions`() {
+ AccessType.values().forEach { accessType ->
+ FullAccessRequired.values().forEach { fullAccessRequired ->
+ listOf(false, true).forEach { commandRequiresWriteAccess ->
+ assertThat("$accessType, $fullAccessRequired, $commandRequiresWriteAccess", accessAuthorizer.authorized(accessType, fullAccessRequired, commandRequiresWriteAccess), equalTo(
+ accessType != RESTRICTED_FCP ||
+ fullAccessRequired == NO ||
+ (fullAccessRequired == WRITING && !commandRequiresWriteAccess)
+ ))
+ }
+ }
+ }
+ }
+
+}