package uk.ac.ebi.quickgo.geneproduct.model;

import org.junit.Before;
import org.junit.Test;

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

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

	private String database = "UniProtKB";
	private String entityType = "PR:000000001";
	private String entityTypeName = "protein";
	private String localIdSyntax = "([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 String urlSyntax = " http://www.uniprot.org/uniprot/[example_id]";

	GeneProductDbXRefIDFormat geneProductXrefEntity;

	@Before
	public void setup(){
		geneProductXrefEntity = new GeneProductDbXRefIDFormat(database, entityType, entityTypeName,
				localIdSyntax, urlSyntax);
	}

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

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


}

@@ -81,20 +81,85 @@
 g.junit.
-Test
+Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException
 ;%0A%0Aimpor
@@ -410,16 +410,86 @@
 Test %7B%0A%0A
+%09@Rule%0A%09public ExpectedException thrown = ExpectedException.none();%0A%0A%0A
 %09private
@@ -625,29 +625,35 @@
  String 
-localIdSyntax
+idValidationPattern
  = %22(%5BOP
@@ -782,25 +782,21 @@
  String 
-urlSyntax
+dbURL
  = %22 htt
@@ -1023,32 +1023,34 @@
 %09%09%09%09
-localIdSyntax, urlSyntax
+idValidationPattern, dbURL
 );%0A%09
@@ -1254,11 +1254,920 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09public void exceptionThrownIfDatabaseIsNull()%7B%0A%09%09thrown.expect(NullPointerException.class);%0A%09%09new GeneProductDbXRefIDFormat(null, entityType, entityTypeName, idValidationPattern, dbURL);%0A%09%7D%0A%0A%09@Test%0A%09public void exceptionThrownIfEntityTypeIsNull()%7B%0A%09%09thrown.expect(NullPointerException.class);%0A%09%09new GeneProductDbXRefIDFormat(database, null, entityTypeName, idValidationPattern, dbURL);%0A%09%7D%0A%0A%09@Test%0A%09public void exceptionThrownIfIdValidationPatternIsNull()%7B%0A%09%09thrown.expect(NullPointerException.class);%0A%09%09new GeneProductDbXRefIDFormat(database, entityType, entityTypeName, null, dbURL);%0A%09%7D%0A%0A%09@Test%0A%09public void exceptionNotThrownIfEntityTypeNameIsNull()%7B%0A%09%09new GeneProductDbXRefIDFormat(database, entityType, null, idValidationPattern, dbURL);%0A%09%7D%0A%0A%09@Test%0A%09public void exceptionNotThrownIfDbURLIsNull()%7B%0A%09%09new GeneProductDbXRefIDFormat(database, entityType, entityTypeName, idValidationPattern, null);%0A%09%7D
 %0A%7D%0A

Test preconditions defending against nulls in constructor for parameters as required.