package uk.ac.ebi.atlas.experimentpage;

import org.junit.Test;
import uk.ac.ebi.atlas.model.Profile;

import java.util.concurrent.ThreadLocalRandom;

import static org.hamcrest.Matchers.endsWith;
import static org.junit.Assert.assertThat;

public class LinkToGeneTest {

    class DummyProfile extends Profile {
        DummyProfile(String id, String name) {
            super(id, name);
        }

        @Override
        protected Profile createEmptyCopy() {
            return null;
        }
    }

    // Not comprehensive, if gene IDs need to use any of the following chars we need to use a URLEncoder
    String[] ILLEGAL_CHARS = {"%", "ˆ", "|", "<", ">", "`", "#", "\"", "\\", "[", "]", "{", "}"};

    LinkToGene<DummyProfile> subject = new LinkToGene<>();

    @Test
    public void linksPointAtTheInformationTab() throws Exception {
        assertThat(subject.apply(new DummyProfile("geneId", "geneName")).toString(), endsWith("#information"));
    }

    @Test(expected = RuntimeException.class)
    public void uriSyntaxExceptionsAreWrapped() throws Exception {
        String randomIllegalChar = ILLEGAL_CHARS[ThreadLocalRandom.current().nextInt(0, ILLEGAL_CHARS.length)];
        subject.apply(new DummyProfile(randomIllegalChar, ""));
    }

}
@@ -232,16 +232,53 @@
 ertThat;
+%0Aimport static org.junit.Assert.fail;
 %0A%0Apublic
@@ -679,13 +679,8 @@
 %22%25%22,
- %22%CB%86%22,
  %22%7C%22
@@ -1004,43 +1004,8 @@
 Test
-(expected = RuntimeException.class)
 %0A   
@@ -1048,33 +1048,16 @@
 rapped()
- throws Exception
  %7B%0A     
@@ -1063,22 +1063,20 @@
     
+for(
 String 
-randomI
+i
 lleg
@@ -1081,18 +1081,17 @@
 egalChar
- =
+:
  ILLEGAL
@@ -1100,80 +1100,44 @@
 HARS
-%5BThreadLocalRandom.current().nextInt(0, ILLEGAL_CHARS.length)%5D;%0A
+)%7B%0A            try %7B%0A       
         
 subj
@@ -1132,16 +1132,17 @@
         
+ 
 subject.
@@ -1168,15 +1168,9 @@
 ile(
-randomI
+i
 lleg
@@ -1179,20 +1179,161 @@
 Char, %22%22));%0A
+                fail(%22Did not throw:%22 +illegalChar);%0A            %7D catch (RuntimeException e)%7B%0A                //yum%0A            %7D%0A        %7D%0A
     %7D%0A%0A%7D

Fix interminnently failing test