Merge pull request #15 from myrle-krantz/develop

minor change
diff --git a/service/src/main/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializer.java b/service/src/main/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializer.java
index 0fb9c70..4865a7b 100644
--- a/service/src/main/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializer.java
+++ b/service/src/main/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializer.java
@@ -149,7 +149,7 @@
       //You might look at this and wonder: "Why isn't she returning a stream here? She's just turning it back into
       //a stream on the other side..."
       //The answer is that you need the createOrFindPermittableGroup to be executed in the proper tenant context. If you
-      //return the stream, the call to createOrFindPermittableGroup will be executed when the stream is itereated over.
+      //return the stream, the call to createOrFindPermittableGroup will be executed when the stream is iterated over.
       return permittableGroups.map(x -> createOrFindPermittableGroup(identityService, x)).collect(Collectors.toList());
     } catch (final Exception e) {
       throw new IllegalStateException(e);
@@ -254,11 +254,11 @@
     }
     catch (final PermittableGroupAlreadyExistsException groupAlreadyExistsException)
     {
+      identityListener.withdrawExpectation(eventExpectation);
       //if the group already exists, read out and compare.  If the group is the same, there is nothing left to do.
       final PermittableGroup existingGroup = identityService.getPermittableGroup(permittableGroup.getIdentifier());
       if (!existingGroup.getIdentifier().equals(permittableGroup.getIdentifier())) {
         logger.error("Group '{}' already exists for tenant {}, but has a different name {} (strange).", permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier(), existingGroup.getIdentifier());
-        identityListener.withdrawExpectation(eventExpectation);
       }
 
       //Compare as sets because I'm not going to get into a hissy fit over order.
@@ -266,13 +266,12 @@
       final Set<PermittableEndpoint> newGroupPermittables = new HashSet<>(permittableGroup.getPermittables());
       if (!existingGroupPermittables.equals(newGroupPermittables)) {
         logger.error("Group '{}' already exists for tenant {}, but has different contents.", permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier());
-        identityListener.withdrawExpectation(eventExpectation);
       }
     }
     catch (final RuntimeException unexpected)
     {
-      logger.error("Creating group '{}' for tenant {} failed.", permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier(), unexpected);
       identityListener.withdrawExpectation(eventExpectation);
+      logger.error("Creating group '{}' for tenant {} failed.", permittableGroup.getIdentifier(), TenantContextHolder.checkedGetIdentifier(), unexpected);
     }
     return eventExpectation;
   }
diff --git a/service/src/test/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializerTest.java b/service/src/test/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializerTest.java
index 09cddf4..75dbf3c 100644
--- a/service/src/test/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializerTest.java
+++ b/service/src/test/java/io/mifos/provisioner/internal/service/applications/IdentityServiceInitializerTest.java
@@ -103,7 +103,8 @@
 
     try (final AutoTenantContext ignored = new AutoTenantContext("blah")) {
       final SystemProperties systemProperties = new SystemProperties();
-      new IdentityServiceInitializer(identityListenerMock, null, null, loggerMock, systemProperties).createOrFindPermittableGroup(identityServiceMock, group1);
+      new IdentityServiceInitializer(identityListenerMock, null, null, loggerMock, systemProperties)
+          .createOrFindPermittableGroup(identityServiceMock, group1);
     }
   }
 
@@ -118,7 +119,8 @@
 
     try (final AutoTenantContext ignored = new AutoTenantContext("blah")) {
       final SystemProperties systemProperties = new SystemProperties();
-      new IdentityServiceInitializer(identityListenerMock, null, null, loggerMock, systemProperties).createOrFindPermittableGroup(identityServiceMock, group1);
+      new IdentityServiceInitializer(identityListenerMock, null, null, loggerMock, systemProperties)
+          .createOrFindPermittableGroup(identityServiceMock, group1);
     }
 
     verify(loggerMock).error(anyString(), anyString(), anyString());
@@ -135,7 +137,8 @@
 
     try (final AutoTenantContext ignored = new AutoTenantContext("blah")) {
       final SystemProperties systemProperties = new SystemProperties();
-      new IdentityServiceInitializer(identityListenerMock, null, null, loggerMock, systemProperties).createOrFindPermittableGroup(identityServiceMock, group1);
+      new IdentityServiceInitializer(identityListenerMock, null, null, loggerMock, systemProperties)
+          .createOrFindPermittableGroup(identityServiceMock, group1);
     }
 
     verify(loggerMock).error(anyString(), anyString(), anyString(), isA(IllegalStateException.class));