package uk.ac.ebi.quickgo.common.validator;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
 * Test for DbXRefEntity
 * @author Tony Wardell
 *         Date: 19/04/2016
 *         Time: 13:50
 *         Created with IntelliJ IDEA.
 */
public class DbXRefEntityTest {

	private static final String database = "UniProtKB";
	private static final String entityType = "PR:000000001";
	private static final String entityTypeName = "protein";
	private static final String idValidationPattern = "([OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z]([0-9][A-Z][A-Z0-9]{2}){1,2}[0-9])((-[0-9]+)|:PRO_[0-9]{10}|:VAR_[0-9]{6}){0,1}";
	private static final String dbURL = " http://www.uniprot.org/uniprot/[example_id]";
	@Rule
	public ExpectedException thrown = ExpectedException.none();
	private DbXRefEntity dbXrefEntity;

	@Before
	public void setup(){
		dbXrefEntity = new DbXRefEntity(database, entityType, entityTypeName, idValidationPattern, dbURL);
	}

	@Test
	public void validId(){
		assertThat(dbXrefEntity.matches("A0A000"), is(true));
	}

	@Test
	public void inValidId(){
		assertThat(dbXrefEntity.matches("99999"), is(false));
	}

	@Test
	public void exceptionThrownIfDatabaseIsNull(){
		thrown.expect(IllegalArgumentException.class);
		new DbXRefEntity(null, entityType, entityTypeName, idValidationPattern, dbURL);
	}

	@Test
	public void exceptionThrownIfEntityTypeIsNull(){
		thrown.expect(IllegalArgumentException.class);
		new DbXRefEntity(database, null, entityTypeName, idValidationPattern, dbURL);
	}

	@Test
	public void exceptionThrownIfIdValidationPatternIsNull(){
		thrown.expect(IllegalArgumentException.class);
		new DbXRefEntity(database, entityType, entityTypeName, null, dbURL);
	}

	@Test
	public void exceptionNotThrownIfEntityTypeNameIsNull(){
		new DbXRefEntity(database, entityType, null, idValidationPattern, dbURL);
	}

	@Test
	public void exceptionNotThrownIfDbURLIsNull(){
		new DbXRefEntity(database, entityType, entityTypeName, idValidationPattern, null);
	}
}

@@ -424,16 +424,79 @@
 yTest %7B%0A
+%09private static final boolean CASE_SENSITIVE_MATCHING  = false;
 %0A%09privat
@@ -1137,32 +1137,57 @@
 onPattern, dbURL
+, CASE_SENSITIVE_MATCHING
 );%0A%09%7D%0A%0A%09@Test%0A%09p
@@ -1260,24 +1260,80 @@
  is(true));%0A
+%09%09assertThat(dbXrefEntity.matches(%22a0A000%22), is(true));%0A
 %09%7D%0A%0A%09@Test%0A%09
@@ -1404,21 +1404,39 @@
 9%22), is(
-false
+CASE_SENSITIVE_MATCHING
 ));%0A%09%7D%0A%0A
@@ -1610,32 +1610,57 @@
 onPattern, dbURL
+, CASE_SENSITIVE_MATCHING
 );%0A%09%7D%0A%0A%09@Test%0A%09p
@@ -1825,32 +1825,57 @@
 onPattern, dbURL
+, CASE_SENSITIVE_MATCHING
 );%0A%09%7D%0A%0A%09@Test%0A%09p
@@ -2044,24 +2044,49 @@
  null, dbURL
+, CASE_SENSITIVE_MATCHING
 );%0A%09%7D%0A%0A%09@Tes
@@ -2217,16 +2217,41 @@
 n, dbURL
+, CASE_SENSITIVE_MATCHING
 );%0A%09%7D%0A%0A%09
@@ -2386,16 +2386,382 @@
 rn, null
+, CASE_SENSITIVE_MATCHING);%0A%09%7D%0A%0A%09@Test%0A%09public void validationCanBeMadeCaseSensitive()%7B%0A%09%09boolean matchingIsCaseSensitive = true;%0A%09%09dbXrefEntity = new DbXRefEntity(database, entityType, entityTypeName, idValidationPattern, dbURL, matchingIsCaseSensitive);%0A%09%09assertThat(dbXrefEntity.matches(%22A0A000%22), is(true));%0A%09%09assertThat(dbXrefEntity.matches(%22a0A000%22), is(false)
 );%0A%09%7D%0A%7D%0A

Add constant for case sensitivity. Use variable in case sensitivity test.