package uk.ac.ebi.quickgo.annotation.validation.service;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.ac.ebi.quickgo.annotation.validation.service.DbCrossReferenceId.*;

/**
 * @author Tony Wardell
 * Date: 21/11/2016
 * Time: 14:36
 * Created with IntelliJ IDEA.
 */
public class DbCrossReferenceIdTest {

    private static final String DB = "UniProt";
    private static final String ID = "12345";
    private static final String DELIMITER = ":";
    private static final String ID_WITH_DB = DB + DELIMITER + ID;

    @Test
    public void retrieveDbSectionSuccessfully(){
        assertThat(db(ID_WITH_DB), is(DB));
    }

    @Test
    public void retrieveIdSectionSuccessfully(){
        assertThat(id(ID_WITH_DB), is(ID));
    }

    @Test
    public void retrieveIdSectionSuccessfullyWithUpperCaseLettersInTheId(){
        assertThat(id("UniProt:AA"), is("AA"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void throwExceptionIfValueDoesNotContainDelimiterDb(){
        db("ABC");
    }

    @Test(expected = IllegalArgumentException.class)
    public void throwExceptionIfValueDoesNotContainDelimiterForId(){
        id("ABC");
    }

    @Test(expected = IllegalArgumentException.class)
    public void throwExceptionIfValueIsNullForDb(){
        db(null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void throwExceptionIfValueIsNullForId(){
        id(null);
    }

    @Test
    public void retrieveDbSectionFromJustTheDelimiterGivesEmptyString(){
        assertThat(db(DELIMITER), is(""));
    }

    @Test
    public void retrieveIdSectionFromJustTheDelimiterGivesEmptyString(){
        assertThat(id(DELIMITER), is(""));
    }

    @Test
    public void retrieveDbSectionWhereDoesNotExistGivesEmptyString(){
        assertThat(db(DELIMITER+ID), is(""));
    }

    @Test
    public void retrieveIdSectionWhereDoesNotExistGivesEmptyString(){
        assertThat(id(DB+DELIMITER), is(""));
    }

    @Test
    public void retrieveDbSectionWhereDbSectionContainsSpaces(){
        assertThat(db("   " + DB + "   " + DELIMITER), is(DB));
    }

    @Test
    public void retrieveIdSectionWhereIdSectionContainsSpaces(){
        assertThat(id(DELIMITER + "    " + ID + "    "), is(ID));
    }
}

@@ -172,16 +172,65 @@
 rtThat;%0A
+import static org.hamcrest.core.IsEqual.equalTo;%0A
 import s
@@ -541,57 +541,8 @@
 5%22;%0A
-    private static final String DELIMITER = %22:%22;%0A
     
@@ -978,51 +978,8 @@
 Test
-(expected = IllegalArgumentException.class)
 %0A   
@@ -987,38 +987,34 @@
 public void 
-throwException
+returnNull
 IfValueDoesN
@@ -1049,78 +1049,66 @@
     
-db(%22ABC%22);%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)
+assertThat(db(%22ABC%22), is(equalTo(null)));%0A    %7D%0A%0A    @Test
 %0A   
@@ -1185,16 +1185,47 @@
     
-id(%22ABC%22
+assertThat(id(%22ABC%22), is(equalTo(null))
 );%0A 
@@ -2314,11 +2314,269 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void detectWhenValueContainsDelimiter()%7B%0A        assertThat(isFullId(%22DB%22 + DELIMITER + %22ID%22), is(true));%0A    %7D%0A%0A    @Test%0A    public void detectWhenValueDoesNotContainDelimiter()%7B%0A        assertThat(isFullId(%22DBID%22), is(false));%0A    %7D
 %0A%7D%0A

Add test for delimiter check.