View Javadoc
1   package emissary.util.web;
2   
3   import emissary.test.core.junit5.UnitTest;
4   
5   import org.junit.jupiter.api.BeforeEach;
6   import org.junit.jupiter.api.Test;
7   
8   import static org.junit.jupiter.api.Assertions.assertEquals;
9   import static org.junit.jupiter.api.Assertions.assertThrows;
10  
11  class UrlTest extends UnitTest {
12  
13      @BeforeEach
14      public void before() {}
15  
16      /*
17       * The getUrl method should not throw an exception regardless of the situation.
18       */
19      @Test
20      void testEmptyUrl() {
21          assertEquals(0, Url.getUrl(new UrlData()).getResponseCode());
22      }
23  
24      @Test
25      void testDoUrlWithNull() {
26          assertThrows(IllegalArgumentException.class, () -> Url.doUrl(null));
27      }
28  
29      @Test
30      void testDoUrlWithHead() {
31          final UrlData urlData = new UrlData();
32          urlData.setTheMethod(Url.HEAD);
33          assertThrows(IllegalArgumentException.class, () -> Url.doUrl(urlData));
34      }
35  
36      @Test
37      void testDoUrlWithGet() {
38          final UrlData urlData = new UrlData();
39          urlData.setTheMethod(Url.GET);
40          assertEquals(0, Url.doUrl(urlData).getResponseCode());
41      }
42  
43      @Test
44      void testDoUrlWithPost() {
45          final UrlData urlData = new UrlData();
46          urlData.setTheMethod(Url.POST);
47          assertEquals(0, Url.doUrl(urlData).getResponseCode());
48      }
49  }