package uk.ac.ebi.quickgo.client.service.loader.presets.withFrom;

import uk.ac.ebi.quickgo.client.service.loader.presets.ff.RawNamedPreset;

import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.item.ItemProcessor;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.IsNull.notNullValue;

/**
 * @author Tony Wardell
 * Date: 03/08/2017
 * Time: 11:01
 * Created with IntelliJ IDEA.
 */
public class WithFromPresetsConfigTest {

    private WithFromPresetsConfig withFromPresetsConfig;

    @Before
    public void setup(){
        withFromPresetsConfig = new WithFromPresetsConfig();
    }

    @Test
    public void preventDuplicates() throws Exception {
        final ItemProcessor<RawNamedPreset, RawNamedPreset> itemProcessor =
                withFromPresetsConfig.duplicateChecker();
        RawNamedPreset rawNamedPreset1 = new RawNamedPreset();
        rawNamedPreset1.name = "AGI_LocusCode ";
        RawNamedPreset rawNamedPreset2 = new RawNamedPreset();
        rawNamedPreset2.name = "AspGD";
        RawNamedPreset rawNamedPreset3 = new RawNamedPreset();
        rawNamedPreset3.name = "ASPGD";
        RawNamedPreset rawNamedPreset4 = new RawNamedPreset();
        rawNamedPreset4.name = "CGD ";

        assertThat(itemProcessor.process(rawNamedPreset1), notNullValue());
        assertThat(itemProcessor.process(rawNamedPreset2), notNullValue());
        assertThat(itemProcessor.process(rawNamedPreset3), nullValue());
        assertThat(itemProcessor.process(rawNamedPreset4), notNullValue());
    }
}

@@ -96,304 +96,270 @@
 ent.
-service.loader.presets.ff.RawNamedPreset;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.springframework.batch.item.ItemProcessor;%0A%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.nullValue;%0Aimport static org.hamcrest.core.IsNull.notNullValue
+model.presets.impl.CompositePresetImpl;%0Aimport uk.ac.ebi.quickgo.client.service.loader.presets.ff.RawNamedPreset;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.springframework.batch.item.ItemWriter
 ;%0A%0A/
@@ -513,51 +513,41 @@
 ate 
-WithFromPresetsConfig withFromPresetsConfig
+CompositePresetImpl presetBuilder
 ;%0A%0A 
@@ -580,12 +580,13 @@
  set
-u
+U
 p()
+ 
 %7B%0A  
@@ -595,226 +595,231 @@
     
-withFromPresetsConfig = new WithFromPresetsConfig();%0A    %7D%0A%0A    @Test%0A    public void preventDuplicates() throws Exception %7B%0A        final ItemProcessor%3CRawNamedPreset, RawNamedPreset%3E itemProcessor =%0A                w
+presetBuilder = new CompositePresetImpl();%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)%0A    public void avoidsNullPointerExceptionIfNameIsNull() throws Exception %7B%0A        WithFromPresetsConfig config = new W
 ithF
@@ -838,37 +838,21 @@
 nfig
-.duplicateChecker
 ();%0A
+%0A
         
 RawN
@@ -839,32 +839,37 @@
 fig();%0A%0A        
+List%3C
 RawNamedPreset r
@@ -858,32 +858,33 @@
 t%3CRawNamedPreset
+%3E
  rawNamedPreset1
@@ -886,90 +886,44 @@
 eset
-1
+s
  = new 
-RawNamedPreset();%0A        rawNamedPreset1.name = %22AGI_LocusCode %22;%0A       
+ArrayList%3C%3E();%0A        final
  Raw
@@ -937,28 +937,17 @@
 eset raw
-NamedPreset2
+1
  = new R
@@ -978,28 +978,17 @@
  raw
-NamedPreset2
+1
 .name = 
 %22Asp
@@ -987,15 +987,12 @@
 e = 
-%22AspGD%22
+null
 ;%0A  
@@ -1001,504 +1001,207 @@
     
-RawNamedPreset rawNamedPreset3 = new RawNamedPreset();%0A        rawNamedPreset3.name = %22ASPGD%22;%0A        RawNamedPreset rawNamedPreset4 = new RawNamedPreset();%0A        rawNamedPreset4.name = %22CGD %22;%0A%0A        assertThat(itemProcessor.process(rawNamedPreset1), notNullValue());%0A        assertThat(itemProcessor.process(rawNamedPreset2), notNullValue());%0A        assertThat(itemProcessor.process(rawNamedPreset3), nullValue());%0A        assertThat(itemProcessor.process(rawNamedPreset4), notNullValue()
+raw1.id = null;%0A        raw1.relevancy = 1;%0A        rawNamedPresets.add(raw1);%0A%0A        ItemWriter%3CRawNamedPreset%3E writer = config.rawPresetWriter(presetBuilder);%0A        writer.write(rawNamedPresets
 );%0A 

Test now changed as the data is only coming from a REST service.