package com.hubspot.jinjava.lib.filter;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;

import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
import org.mockito.runners.MockitoJUnitRunner;

import com.hubspot.jinjava.interpret.JinjavaInterpreter;

@RunWith(MockitoJUnitRunner.class)
public class TruncateFilterTest {

  @Mock
  JinjavaInterpreter interpreter;
  @InjectMocks
  TruncateFilter filter;

  @Before
  public void setup() {
    when(interpreter.resolveString(anyString(), anyInt(), anyInt())).thenAnswer(new ReturnsArgumentAt(0));
  }

  @Test
  public void itPassesThroughSmallEnoughText() throws Exception {
    String s = StringUtils.rightPad("", 255, 'x');
    assertThat(filter.filter(s, interpreter)).isEqualTo(s);
  }

  @Test
  public void itTruncatesText() throws Exception {
    assertThat(filter.filter(StringUtils.rightPad("", 256, 'x') + "y", interpreter, "255", "True").toString()).hasSize(258).endsWith("x...");
  }

  @Test
  public void itTruncatesToSpecifiedLength() throws Exception {
    assertThat(filter.filter("foo bar", interpreter, "5", "True")).isEqualTo("foo b...");
  }

  @Test
  public void itDiscardsLastWordWhenKillwordsFalse() throws Exception {
    assertThat(filter.filter("foo bar", interpreter, "5")).isEqualTo("foo ...");
  }

  @Test
  public void itTruncatesWithDifferentEndingIfSpecified() throws Exception {
    assertThat(filter.filter("foo bar", interpreter, "5", "True", "!")).isEqualTo("foo b!");
  }

}

@@ -95,137 +95,8 @@
 hat;
-%0Aimport static org.mockito.Matchers.anyInt;%0Aimport static org.mockito.Matchers.anyString;%0Aimport static org.mockito.Mockito.when;
 %0A%0Aim
@@ -142,33 +142,8 @@
 ls;%0A
-import org.junit.Before;%0A
 impo
@@ -255,72 +255,8 @@
 ck;%0A
-import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;%0A
 impo
@@ -484,16 +484,16 @@
 ctMocks%0A
+
   Trunca
@@ -514,154 +514,8 @@
 r;%0A%0A
-  @Before%0A  public void setup() %7B%0A    when(interpreter.resolveString(anyString(), anyInt(), anyInt())).thenAnswer(new ReturnsArgumentAt(0));%0A  %7D%0A%0A
   @T

remove unnecessary mock