package com.codingchili.flashcards;

import com.codingchili.core.configuration.BaseConfigurable;
import com.codingchili.core.files.Configurations;
import com.codingchili.core.security.TokenFactory;
import com.codingchili.core.storage.IndexedMapPersisted;

/**
 * Stores flashcard application configuration.
 */
public class AppConfig extends BaseConfigurable {
    private static final String APPLICATION_JSON = "application.json";
    private static String secret = System.getProperty("secret");
    private String storage = IndexedMapPersisted.class.getName();
    private String database = "flashcards";

    public static String db() {
        return settings().database;
    }

    public static TokenFactory factory() {
        return new TokenFactory(secret.getBytes());
    }

    public static Class storage() {
        try {
            return Class.forName(settings().getStorage());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    private static AppConfig settings() {
        return Configurations.get(APPLICATION_JSON, AppConfig.class);
    }

    @Override
    public String getPath() {
        return APPLICATION_JSON;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        AppConfig.secret = secret;
    }

    public String getStorage() {
        return storage;
    }

    public void setStorage(String storage) {
        this.storage = storage;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }
}

@@ -256,16 +256,42 @@
 ted;%0D%0A%0D%0A
+import java.util.UUID;%0D%0A%0D%0A
 /**%0D%0A * 
@@ -502,35 +502,27 @@
 t = 
-System.getProperty(%22secret%22
+getSecretOrDefault(
 );%0D%0A
@@ -1724,12 +1724,244 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    private static String getSecretOrDefault() %7B%0D%0A        String secret = System.getProperty(%22secret%22);%0D%0A        if (secret == null) %7B%0D%0A            secret = UUID.randomUUID().toString();%0D%0A        %7D%0D%0A        return secret;%0D%0A    %7D%0D
 %0A%7D%0D%0A

Make test pass: set default secret when no sysproperty set.