package com.mesosphere.sdk.state;

import com.mesosphere.sdk.storage.MemPersister;
import com.mesosphere.sdk.storage.Persister;
import org.junit.Test;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.is;

/**
 * Tests for {@link StateStoreUtils}.
 */
public class StateStoreUtilsTest {

    @Test
    public void emptyStateStoreReturnsEmptyArray () {
        final StateStore stateStore = new DefaultStateStore(new MemPersister());

        byte[] result = StateStoreUtils.fetchPropertyOrEmptyArray(stateStore, "UNDEFINED");

        assertThat(result.length, is(0));
    }

    @Test
    public void unmatchedKeyReturnsEmptyArray() {
        final StateStore stateStore = new DefaultStateStore(new MemPersister());
        stateStore.storeProperty("DEFINED", "VALUE".getBytes());

        byte[] result = StateStoreUtils.fetchPropertyOrEmptyArray(stateStore, "UNDEFINED");

        assertThat(result.length, is(0));
    }

    @Test
    public void matchedKeyReturnsValue() {
        final StateStore stateStore = new DefaultStateStore(new MemPersister());
        stateStore.storeProperty("DEFINED", "VALUE".getBytes());

        byte[] result = StateStoreUtils.fetchPropertyOrEmptyArray(stateStore, "DEFINED");

        assertThat(result, is("VALUE".getBytes()));
    }

}

@@ -117,24 +117,64 @@
 .Persister;%0A
+import net.jcip.annotations.ThreadSafe;%0A
 import org.j
@@ -1338,10 +1338,906 @@
 %0A    %7D%0A%0A
+    @Test(expected = StateStoreException.class)%0A    public void emptyStringIsIsInvalidKey() %7B%0A        StateStoreUtils.validateKey(%22%22);%0A    %7D%0A%0A    @Test(expected = StateStoreException.class)%0A    public void nullIsIsInvalidKey() %7B%0A        StateStoreUtils.validateKey(null);%0A    %7D%0A%0A    @Test(expected = StateStoreException.class)%0A    public void blankStringIsInvaldiKey() %7B%0A        StateStoreUtils.validateKey(%22    %22);%0A    %7D%0A%0A    @Test(expected = StateStoreException.class)%0A    public void stringWithLeadingSlashIsInvalidKey() %7B%0A        StateStoreUtils.validateKey(%22/key%22);%0A    %7D%0A%0A    @Test(expected = StateStoreException.class)%0A    public void stringWithTrailingSlashIsInvalidKey() %7B%0A        StateStoreUtils.validateKey(%22key/%22);%0A    %7D%0A%0A    @Test(expected = StateStoreException.class)%0A    public void stringWithEmbeddedSlashIsInvalidKey() %7B%0A        StateStoreUtils.validateKey(%22key/value%22);%0A    %7D%0A%0A%0A
 %7D%0A

Add unit tests for valdidateKey method