View Javadoc
1   package org.eclipse.aether.internal.impl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 WarnChecksumPolicyTest
31  {
32  
33      private WarnChecksumPolicy policy;
34  
35      private ChecksumFailureException exception;
36  
37      @Before
38      public void setup()
39      {
40          policy = new WarnChecksumPolicy( 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          assertTrue( 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  }