package lab.dynafig;

import org.junit.Before;
import org.junit.Test;

import java.util.Properties;

import static java.util.Collections.singletonMap;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

/**
 * {@code DefaultDynafigTest} tests {@link DefaultDynafig}.
 *
 * @author <a href="mailto:binkley@alumni.rice.edu">B. K. Oxley</a>
 */
public final class DefaultDynafigTest<T, R>
        extends DynafigTesting<T, R, DefaultDynafig> {
    public DefaultDynafigTest(final Args<T, R> args) {
        super(args);
    }

    @Before
    public void setUpFixture() {
        dynafig(new DefaultDynafig());
    }

    @Override
    protected void presetValue(final String value) {
        dynafig(new DefaultDynafig(singletonMap(KEY, value)));
    }

    public static final class CtorTest {
        @Test
        public void shouldConstructFromMap() {
            assertThat(new DefaultDynafig(singletonMap(KEY, "")).
                    track(KEY).isPresent(), is(true));
        }

        @Test
        public void shouldConstructFromEntryStream() {
            assertThat(new DefaultDynafig(singletonMap(KEY, "").
                    entrySet().stream()).
                    track(KEY).isPresent(), is(true));
        }

        @Test
        public void shouldConstructFromProperties() {
            final Properties properties = new Properties();
            properties.put(KEY, "");
            assertThat(new DefaultDynafig(properties).
                    track(KEY).isPresent(), is(true));
        }
    }
}

@@ -57,20 +57,85 @@
 g.junit.
-Test
+Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException
 ;%0A%0Aimpor
@@ -209,16 +209,61 @@
 tonMap;%0A
+import static org.hamcrest.Matchers.equalTo;%0A
 import s
@@ -922,18 +922,109 @@
 ss C
+us
 to
-r
+m
 Test %7B%0A
+        @Rule%0A        public final ExpectedException thrown = ExpectedException.none();%0A%0A
     
@@ -1619,16 +1619,17 @@
 Y, %22%22);%0A
+%0A
         
@@ -1675,16 +1675,16 @@
 rties).%0A
-
         
@@ -1739,16 +1739,495 @@
        %7D
+%0A%0A        @Test%0A        public void shouldInsertKeyValuesFromTheSide() %7B%0A            final DefaultDynafig dynafig = new DefaultDynafig();%0A            dynafig.insert(KEY, %22%22);%0A%0A            assertThat(dynafig.track(KEY).get().get(), is(equalTo(%22%22)));%0A        %7D%0A%0A        @Test%0A        public void shouldComplainWhenInsertingPreesitingKey() %7B%0A            thrown.expect(IllegalArgumentException.class);%0A%0A            new DefaultDynafig(singletonMap(KEY, %22%22)).insert(KEY, %22%22);%0A        %7D
 %0A    %7D%0A%7D

Test "insert".