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

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

import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.item.ItemWriter;

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

    private CompositePresetImpl presetBuilder;

    @Before
    public void setUp() {
        presetBuilder = new CompositePresetImpl();
    }

    @Test(expected = IllegalArgumentException.class)
    public void avoidsNullPointerExceptionIfNameIsNull() throws Exception {
        WithFromPresetsConfig config = new WithFromPresetsConfig();

        List<RawNamedPreset> rawNamedPresets = new ArrayList<>();
        final RawNamedPreset raw1 = new RawNamedPreset();
        raw1.name = null;
        raw1.id = null;
        raw1.relevancy = 1;
        rawNamedPresets.add(raw1);

        ItemWriter<RawNamedPreset> writer = config.rawPresetWriter(presetBuilder);
        writer.write(rawNamedPresets);
    }
}

@@ -96,270 +96,304 @@
 ent.
-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
+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
 ;%0A%0A/
@@ -547,41 +547,51 @@
 ate 
-CompositePresetImpl presetBuilder
+WithFromPresetsConfig withFromPresetsConfig
 ;%0A%0A 
@@ -624,9 +624,9 @@
  set
-U
+u
 p() 
@@ -639,231 +639,226 @@
     
-presetBuilder = new CompositePresetImpl();%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)%0A    public void avoidsNullPointerExceptionIfNameIsNull() throws Exception %7B%0A        WithFromPresetsConfig config = new W
+withFromPresetsConfig = new WithFromPresetsConfig();%0A    %7D%0A%0A    @Test%0A    public void preventDuplicates() throws Exception %7B%0A        final ItemProcessor%3CRawNamedPreset, RawNamedPreset%3E itemProcessor =%0A                w
 ithF
@@ -877,21 +877,37 @@
 nfig
+.duplicateChecker
 ();%0A
-%0A
         
 List
@@ -902,21 +902,16 @@
         
-List%3C
 RawNamed
@@ -916,17 +916,16 @@
 edPreset
-%3E
  rawName
@@ -935,44 +935,82 @@
 eset
-s
+1
  = new 
-ArrayList%3C%3E();%0A        final
+RawNamedPreset();%0A        rawNamedPreset1.name = %22AgBase%22;%0A       
  Raw
@@ -1024,17 +1024,28 @@
 eset raw
-1
+NamedPreset2
  = new R
@@ -1072,25 +1072,36 @@
      raw
-1
+NamedPreset2
 .name = 
 null;%0A  
@@ -1092,20 +1092,23 @@
 .name = 
-null
+%22AspGD%22
 ;%0A      
@@ -1113,207 +1113,532 @@
     
-raw1.id = null;%0A        raw1.relevancy = 1;%0A        rawNamedPresets.add(raw1);%0A%0A        ItemWriter%3CRawNamedPreset%3E writer = config.rawPresetWriter(presetBuilder);%0A        writer.write(rawNamedPresets
+RawNamedPreset rawNamedPreset3 = new RawNamedPreset();%0A        rawNamedPreset3.name = %22ASPGD%22;%0A        RawNamedPreset rawNamedPreset4 = new RawNamedPreset();%0A        rawNamedPreset4.name = %22Alzheimers_University_of_Toronto%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()
 );%0A 

Change tests to only test for duplicates.