|
43 | 43 | import org.springframework.util.FileCopyUtils;
|
44 | 44 | import org.springframework.util.StreamUtils;
|
45 | 45 |
|
46 |
| -import static org.hamcrest.Matchers.containsString; |
47 | 46 | import static org.hamcrest.Matchers.equalTo;
|
48 | 47 | import static org.hamcrest.Matchers.greaterThan;
|
49 | 48 | import static org.hamcrest.Matchers.instanceOf;
|
50 | 49 | import static org.hamcrest.Matchers.is;
|
51 |
| -import static org.hamcrest.Matchers.not; |
52 | 50 | import static org.hamcrest.Matchers.notNullValue;
|
53 | 51 | import static org.hamcrest.Matchers.nullValue;
|
54 | 52 | import static org.hamcrest.Matchers.sameInstance;
|
@@ -459,10 +457,41 @@ public void cannotLoadMissingJar() throws Exception {
|
459 | 457 | }
|
460 | 458 |
|
461 | 459 | @Test
|
462 |
| - public void registerUrlProtocolHandler() { |
463 |
| - JarFile.registerUrlProtocolHandler(); |
464 |
| - String protocolHandler = System.getProperty(PROTOCOL_HANDLER); |
465 |
| - assertThat(protocolHandler, containsString(HANDLERS_PACKAGE)); |
466 |
| - assertThat(protocolHandler, not(containsString("null"))); |
| 460 | + public void registerUrlProtocolHandlerWithNoExistingRegistration() { |
| 461 | + String original = System.getProperty(PROTOCOL_HANDLER); |
| 462 | + try { |
| 463 | + System.clearProperty(PROTOCOL_HANDLER); |
| 464 | + JarFile.registerUrlProtocolHandler(); |
| 465 | + String protocolHandler = System.getProperty(PROTOCOL_HANDLER); |
| 466 | + assertThat(protocolHandler, equalTo(HANDLERS_PACKAGE)); |
| 467 | + } |
| 468 | + finally { |
| 469 | + if (original == null) { |
| 470 | + System.clearProperty(PROTOCOL_HANDLER); |
| 471 | + } |
| 472 | + else { |
| 473 | + System.setProperty(PROTOCOL_HANDLER, original); |
| 474 | + } |
| 475 | + } |
467 | 476 | }
|
| 477 | + |
| 478 | + @Test |
| 479 | + public void registerUrlProtocolHandlerAddsToExistingRegistration() { |
| 480 | + String original = System.getProperty(PROTOCOL_HANDLER); |
| 481 | + try { |
| 482 | + System.setProperty(PROTOCOL_HANDLER, "com.example"); |
| 483 | + JarFile.registerUrlProtocolHandler(); |
| 484 | + String protocolHandler = System.getProperty(PROTOCOL_HANDLER); |
| 485 | + assertThat(protocolHandler, equalTo("com.example|" + HANDLERS_PACKAGE)); |
| 486 | + } |
| 487 | + finally { |
| 488 | + if (original == null) { |
| 489 | + System.clearProperty(PROTOCOL_HANDLER); |
| 490 | + } |
| 491 | + else { |
| 492 | + System.setProperty(PROTOCOL_HANDLER, original); |
| 493 | + } |
| 494 | + } |
| 495 | + } |
| 496 | + |
468 | 497 | }
|
0 commit comments