Пример #1
0
  @Test
  public void shouldReturnProperSize() {
    // given
    SmallMap<String, Integer> smallTestMap = smallTestMap();
    assertThat(smallTestMap.size()).isEqualTo(3);

    // when
    smallTestMap.put("123", 1234);

    // then
    assertThat(smallTestMap.size()).isEqualTo(4);
  }
Пример #2
0
  @Test
  public void shouldRemoveElement() {
    // given
    SmallMap<String, Integer> newSmallMap = smallTestMap();
    int size = newSmallMap.size();

    // when
    newSmallMap.remove("abc");

    // then
    assertThat(newSmallMap.get("def")).isEqualTo(456);
    assertThat(newSmallMap.get("xyz")).isEqualTo(123);
    assertThat(newSmallMap.get("abc")).isNull();
    assertThat(newSmallMap.size()).isEqualTo(size - 1);
  }
Пример #3
0
  @Test
  public void shouldDelegateToCreatedMapWhenBig() {
    // given
    SmallMap<String, Integer> map2 = smallTestMap();
    Map<String, Integer> mapMock = createMapMock();
    SmallMap<String, Integer> smallMap = createSmallMap(mapMock);
    fillAndVerify(mapMock, smallMap);

    // when
    smallMap.put("abc", 123);
    Mockito.verify(mapMock).put("abc", 123);

    // when
    smallMap.containsKey("abc");
    Mockito.verify(mapMock).containsKey("abc");

    // when
    smallMap.containsValue(123);
    Mockito.verify(mapMock).containsValue(123);

    // when
    smallMap.entrySet();
    Mockito.verify(mapMock).entrySet();

    // when
    smallMap.values();
    Mockito.verify(mapMock).values();

    // when
    smallMap.keySet();
    Mockito.verify(mapMock).keySet();

    // when
    smallMap.get("abc");
    Mockito.verify(mapMock).get("abc");

    // when
    smallMap.isEmpty();
    Mockito.verify(mapMock).isEmpty();

    // when
    smallMap.size();
    Mockito.verify(mapMock).size();

    // when
    smallMap.putAll(map2);
    Mockito.verify(mapMock).putAll(map2);

    // when
    smallMap.remove("abc");
    Mockito.verify(mapMock).remove("abc");

    // then
    Mockito.verifyNoMoreInteractions(mapMock);
  }
Пример #4
0
  @Test
  public void shouldClearMap() {
    // given
    SmallMap<String, Integer> smallTestMap = smallTestMap();
    assertThat(smallTestMap.isEmpty()).isFalse();

    // when
    smallTestMap.clear();

    // then
    assertThat(smallTestMap.isEmpty()).isTrue();
    assertThat(smallTestMap.size()).isZero();
  }
Пример #5
0
  @Test
  public void emptyMapShouldBeEmpty() {
    // given
    SmallMap<Object, Object> newSmallMap = SmallMap.newSmallMap();

    // when
    boolean empty = newSmallMap.isEmpty();
    int size = newSmallMap.size();

    // then
    assertThat(empty).isTrue();
    assertThat(size).isZero();
  }