package com.rackspacecloud.blueflood.types;

import org.junit.Test;

import static org.junit.Assert.*;

public class PointsTest {

    @Test
    public void newObjectIsEmpty() {

        // when
        Points<SimpleNumber> points = new Points<SimpleNumber>();

        // then
        assertTrue(points.isEmpty());
        assertEquals(0, points.getPoints().size());
    }

    @Test
    public void addIncreasesCount() {

        // given
        Points<SimpleNumber> points = new Points<SimpleNumber>();

        SimpleNumber item = new SimpleNumber(42);
        long timestamp = 1234L;
        Points.Point<SimpleNumber> point = new Points.Point<SimpleNumber>(timestamp, item);

        // when
        points.add(point);

        // then
        assertFalse(points.isEmpty());
        assertEquals(1, points.getPoints().size());
    }

    @Test(expected=IllegalStateException.class)
    public void getDataClassOnEmptyObjectThrowsException() {

        // given
        Points<SimpleNumber> points = new Points<SimpleNumber>();

        // when
        Class actual = points.getDataClass();

        // then the exception is thrown
    }

    @Test
    public void getDataClassGetsClass() {

        // given
        Points<SimpleNumber> points = new Points<SimpleNumber>();

        SimpleNumber item = new SimpleNumber(42);
        long timestamp = 1234L;
        Points.Point<SimpleNumber> point = new Points.Point<SimpleNumber>(timestamp, item);
        points.add(point);

        // when
        Class actual = points.getDataClass();

        // then
        assertSame(SimpleNumber.class, actual);
    }
}

@@ -1609,11 +1609,1587 @@
 );%0A    %7D
+%0A%0A    // adding point with duplicate timestamp replaces previous, e.g. doesn't increase count%0A    @Test%0A    public void addWithDuplicateTimestampDoesNotIncreaseCount() %7B%0A%0A        // given%0A        Points%3CSimpleNumber%3E points = new Points%3CSimpleNumber%3E();%0A%0A        SimpleNumber item = new SimpleNumber(42);%0A        SimpleNumber item2 = new SimpleNumber(43);%0A        long timestamp = 1234L;%0A        Points.Point%3CSimpleNumber%3E point = new Points.Point%3CSimpleNumber%3E(timestamp, item);%0A        Points.Point%3CSimpleNumber%3E point2 = new Points.Point%3CSimpleNumber%3E(timestamp, item2);%0A        points.add(point);%0A%0A        // precondition%0A        assertEquals(1, points.getPoints().size());%0A%0A        // when%0A        points.add(point2);%0A%0A        // then%0A        assertFalse(points.isEmpty());%0A        assertEquals(1, points.getPoints().size());%0A    %7D%0A%0A    @Test%0A    public void addWithDuplicateTimestampReplacesPrevious() %7B%0A%0A        // given%0A        Points%3CSimpleNumber%3E points = new Points%3CSimpleNumber%3E();%0A%0A        SimpleNumber item = new SimpleNumber(42);%0A        SimpleNumber item2 = new SimpleNumber(43);%0A        long timestamp = 1234L;%0A        Points.Point%3CSimpleNumber%3E point = new Points.Point%3CSimpleNumber%3E(timestamp, item);%0A        Points.Point%3CSimpleNumber%3E point2 = new Points.Point%3CSimpleNumber%3E(timestamp, item2);%0A        points.add(point);%0A%0A        // precondition%0A        assertSame(item, points.getPoints().get(timestamp).getData());%0A%0A        // when%0A        points.add(point2);%0A%0A        // then%0A        assertSame(item2, points.getPoints().get(timestamp).getData());%0A    %7D
 %0A%7D%0A

Add tests for duplicate timestamps.