|
4 | 4 | import static org.junit.Assert.assertFalse; |
5 | 5 | import static org.junit.Assert.assertTrue; |
6 | 6 |
|
| 7 | +import java.io.ByteArrayInputStream; |
7 | 8 | import java.io.IOException; |
| 9 | +import java.io.InputStream; |
8 | 10 | import java.util.ArrayList; |
9 | 11 | import java.util.HashMap; |
10 | 12 | import java.util.Map; |
@@ -80,5 +82,47 @@ public Map<String, String> getHeaders() { |
80 | 82 | assertTrue(message.indexOf("Error code: Unable to parse error response message") == 0); |
81 | 83 | assertTrue(message.indexOf("http://localhost") > 0); |
82 | 84 | } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testNullConnection() { |
| 88 | + DefaultLogger logger = new DefaultLogger(); |
| 89 | + GraphServiceException exception = null; |
| 90 | + Boolean success = false; |
| 91 | + Boolean failure = false; |
| 92 | + final ITestConnectionData data = new ITestConnectionData() { |
| 93 | + @Override |
| 94 | + public int getRequestCode() { |
| 95 | + return 401; |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public String getJsonResponse() { |
| 100 | + return "{}"; |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public Map<String, String> getHeaders() { |
| 105 | + return new HashMap<>(); |
| 106 | + } |
| 107 | + }; |
| 108 | + try{ |
| 109 | + exception = GraphServiceException.createFromConnection(new MockHttpRequest(),null,null,new MockConnection(data) { |
| 110 | + @Override |
| 111 | + public InputStream getInputStream() throws IOException { |
| 112 | + return null; |
| 113 | + } |
| 114 | + },logger); |
| 115 | + success = true; |
| 116 | + }catch (IOException ex){ |
| 117 | + failure = true; |
| 118 | + } |
| 119 | + |
| 120 | + assertTrue(success); |
| 121 | + assertFalse(failure); |
| 122 | + |
| 123 | + String message = exception.getMessage(); |
| 124 | + assertTrue(message.indexOf("Error code: Unable to parse error response message") == 0); |
| 125 | + assertTrue(message.indexOf("http://localhost") > 0); |
| 126 | + } |
83 | 127 |
|
84 | 128 | } |
0 commit comments