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