View Javadoc
1   /*
2    * Copyright (C) 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.transport;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.assertNull;
14  
15  import org.eclipse.jgit.lib.Config;
16  import org.junit.Test;
17  
18  /**
19   * Tests for {@link TransferConfig} parsing.
20   */
21  public class TransferConfigTest {
22  
23  	@Test
24  	public void testParseProtocolV0() {
25  		Config rc = new Config();
26  		rc.setInt("protocol", null, "version", 0);
27  		TransferConfig tc = new TransferConfig(rc);
28  		assertEquals(TransferConfig.ProtocolVersion.V0, tc.protocolVersion);
29  	}
30  
31  	@Test
32  	public void testParseProtocolV1() {
33  		Config rc = new Config();
34  		rc.setInt("protocol", null, "version", 1);
35  		TransferConfig tc = new TransferConfig(rc);
36  		assertEquals(TransferConfig.ProtocolVersion.V0, tc.protocolVersion);
37  	}
38  
39  	@Test
40  	public void testParseProtocolV2() {
41  		Config rc = new Config();
42  		rc.setInt("protocol", null, "version", 2);
43  		TransferConfig tc = new TransferConfig(rc);
44  		assertEquals(TransferConfig.ProtocolVersion.V2, tc.protocolVersion);
45  	}
46  
47  	@Test
48  	public void testParseProtocolNotSet() {
49  		Config rc = new Config();
50  		TransferConfig tc = new TransferConfig(rc);
51  		assertNull(tc.protocolVersion);
52  	}
53  
54  	@Test
55  	public void testParseProtocolUnknown() {
56  		Config rc = new Config();
57  		rc.setInt("protocol", null, "version", 3);
58  		TransferConfig tc = new TransferConfig(rc);
59  		assertNull(tc.protocolVersion);
60  	}
61  
62  	@Test
63  	public void testParseProtocolInvalid() {
64  		Config rc = new Config();
65  		rc.setString("protocol", null, "version", "foo");
66  		TransferConfig tc = new TransferConfig(rc);
67  		assertNull(tc.protocolVersion);
68  	}
69  }