package org.netmelody.cieye.server.configuration.test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.netmelody.cieye.core.domain.Sponsor;
import org.netmelody.cieye.server.configuration.RecordedKnownOffenders;
import org.netmelody.cieye.server.configuration.SettingsFile;


public final class RecordedKnownOffendersTest {

    @Rule
    public TemporaryFolder testFolder = new TemporaryFolder();
    private RecordedKnownOffenders offenders;
    

    @Before
    public void createOffendersFile() throws IOException {
        final File peeps = testFolder.newFile("peeps.txt");
        FileUtils.copyInputStreamToFile(RecordedKnownOffenders.class.getResourceAsStream("templates/pictures.txt.template"),
                                        peeps);
        offenders = new RecordedKnownOffenders(new SettingsFile(peeps));
    }
    
    @Test public void
    looksUpSimpleOffenderStrings() {
        assertThat(offenders.search("vlad"), contains(new Sponsor("", "/pictures/vlad.png")));
    }
    
}

@@ -254,17 +254,72 @@
 org.
-junit.Bef
+hamcrest.Matchers;%0Aimport org.junit.Before;%0Aimport org.junit.Ign
 ore;
@@ -588,16 +588,57 @@
 sFile;%0A%0A
+import static org.hamcrest.Matchers.is;%0A%0A
 %0Apublic 
@@ -797,21 +797,16 @@
 fenders;
-%0A    
 %0A%0A    @B
@@ -1347,15 +1347,863 @@
 ;%0A    %7D%0A
-
     %0A
+    @Test public void%0A    looksUpWrappedOffenderStrings() %7B%0A        assertThat(offenders.search(%22-vlad-%22), contains(new Sponsor(%22%22, %22/pictures/vlad.png%22)));%0A    %7D%0A    %0A    @Test public void%0A    looksUpOffenderStringsAtTheBegginingOfALine() %7B%0A        assertThat(offenders.search(%22someguff%5Cnvlad: did stuff%22), contains(new Sponsor(%22%22, %22/pictures/vlad.png%22)));%0A    %7D%0A    %0A    @Test public void%0A    looksUpMultipleOffenders() %7B%0A        assertThat(offenders.search(%22vlad/stupid:%22), contains(new Sponsor(%22%22, %22/pictures/vlad.png%22),%0A                                                              new Sponsor(%22%22, %22/pictures/stupid.png%22)));%0A    %7D%0A    %0A    @Ignore(%22pending implementation%22)%0A    @Test public void%0A    ignoresOffenderNamesAppearingInTheMiddleOfAWord() %7B%0A        assertThat(offenders.search(%22markovladies%22), is(Matchers.%3CSponsor%3Eempty()));%0A    %7D%0A
 %7D%0A

test cases for the known offenders list