1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl;
20
21 import org.eclipse.aether.spi.connector.checksum.ChecksumPolicy.ChecksumKind;
22 import org.eclipse.aether.transfer.ChecksumFailureException;
23 import org.eclipse.aether.transfer.TransferResource;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import static org.junit.Assert.*;
28
29 public class WarnChecksumPolicyTest {
30
31 private WarnChecksumPolicy policy;
32
33 private ChecksumFailureException exception;
34
35 @Before
36 public void setup() {
37 policy = new WarnChecksumPolicy(new TransferResource("null", "file:/dev/null", "file.txt", null, null));
38 exception = new ChecksumFailureException("test");
39 }
40
41 @Test
42 public void testOnTransferChecksumFailure() {
43 assertTrue(policy.onTransferChecksumFailure(exception));
44 }
45
46 @Test
47 public void testOnChecksumMatch() {
48 assertTrue(policy.onChecksumMatch("SHA-1", ChecksumKind.REMOTE_EXTERNAL));
49 assertTrue(policy.onChecksumMatch("SHA-1", ChecksumKind.REMOTE_INCLUDED));
50 assertTrue(policy.onChecksumMatch("SHA-1", ChecksumKind.PROVIDED));
51 }
52
53 @Test
54 public void testOnChecksumMismatch() throws Exception {
55 try {
56 policy.onChecksumMismatch("SHA-1", ChecksumKind.REMOTE_EXTERNAL, exception);
57 fail("No exception");
58 } catch (ChecksumFailureException e) {
59 assertSame(exception, e);
60 }
61 try {
62 policy.onChecksumMismatch("SHA-1", ChecksumKind.REMOTE_INCLUDED, exception);
63 fail("No exception");
64 } catch (ChecksumFailureException e) {
65 assertSame(exception, e);
66 }
67 try {
68 policy.onChecksumMismatch("SHA-1", ChecksumKind.PROVIDED, exception);
69 fail("No exception");
70 } catch (ChecksumFailureException e) {
71 assertSame(exception, e);
72 }
73 }
74
75 @Test
76 public void testOnChecksumError() throws Exception {
77 policy.onChecksumError("SHA-1", ChecksumKind.REMOTE_EXTERNAL, exception);
78 }
79
80 @Test
81 public void testOnNoMoreChecksums() {
82 try {
83 policy.onNoMoreChecksums();
84 fail("No exception");
85 } catch (ChecksumFailureException e) {
86 assertTrue(e.getMessage().contains("no checksums available"));
87 }
88 }
89 }