package org.lodder.subtools.multisubdownloader.lib.control.subtitles.sorting.replacers;

import java.util.HashMap;
import org.junit.Before;
import org.junit.Test;
import org.lodder.subtools.sublibrary.model.Release;


import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class GroupReplacerTest {

  protected GroupReplacer replacer;

  @Before
  public void setUp() throws Exception {
    replacer = new GroupReplacer();
  }

  @Test
  public void test_it_replaces_the_keyword_group_to_a_releasename() throws Exception {
    Release release = mock(Release.class);
    when(release.getReleasegroup()).thenReturn("Acme");

    HashMap<String, Integer> definedWeights = new HashMap<>();
    definedWeights.put("%GROUP%",5);

    replacer.replace(release, definedWeights);

    /* check if the weight there is only one weight */
    assertEquals(1, definedWeights.size());

    /* check if the weight is acme */
    assertTrue(definedWeights.containsKey("acme"));
  }
}

@@ -1027,10 +1027,480 @@
 ));%0A  %7D%0A
+  %0A  @Test%0A  public void testEmptyWeights() throws Exception %7B%0A    Release release = mock(Release.class);%0A    when(release.getReleasegroup()).thenReturn(%22Acme%22);%0A%0A    HashMap%3CString, Integer%3E definedWeights = new HashMap%3C%3E();%0A%0A    replacer.replace(release, definedWeights);%0A%0A    /* check if the weight there is only one weight */%0A    assertEquals(0, definedWeights.size());%0A%0A    /* check if the weight is acme */%0A    assertFalse(definedWeights.containsKey(%22acme%22));%0A  %7D%0A
 %7D%0A

Extend test for empty weights