@Override
    public void upgrade() {
        final MigrationCompleted migrationCompleted = configService.get(MigrationCompleted.class);

        final Set<String> patternNames = patternsToMigrate.stream()
                .map(PatternToMigrate::name)
                .collect(Collectors.toSet());

        if (migrationCompleted != null && migrationCompleted.patterns().containsAll(patternNames)) {
            log.debug("Migration already completed.");
            return;
        }

        try {
            for (PatternToMigrate patternToMigrate : patternsToMigrate) {
                migratePattern(patternToMigrate);
            }
            configService.write(MigrationCompleted.create(patternNames));
        } catch (ValidationException e) {
            log.error("Unable to migrate Grok Pattern.", e);
        }
    }
@Test
    public void alreadyMigrated() {
        final MigrationCompleted migrationCompleted = MigrationCompleted.create(Collections.singleton(PATTERN_NAME));
        when(configService.get(MigrationCompleted.class)).thenReturn(migrationCompleted);

        migration.upgrade();

        verifyNoMoreInteractions(grokPatternService);
    }