1 package org.apache.maven.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import org.apache.maven.wagon.ConnectionException;
25 import org.apache.maven.wagon.authentication.AuthenticationException;
26 import org.apache.maven.wagon.events.TransferEvent;
27 import org.apache.maven.wagon.providers.file.FileWagon;
28 import org.apache.maven.wagon.repository.Repository;
29 import org.apache.maven.wagon.resource.Resource;
30
31
32
33
34
35
36
37 public abstract class AbstractConsoleDownloadMonitorTest
38 extends TestCase
39 {
40
41 protected AbstractConsoleDownloadMonitor monitor;
42
43 public AbstractConsoleDownloadMonitorTest()
44 {
45 super();
46 }
47
48 public void setMonitor( AbstractConsoleDownloadMonitor monitor )
49 {
50 this.monitor = monitor;
51 }
52
53 public AbstractConsoleDownloadMonitor getMonitor()
54 {
55 return monitor;
56 }
57
58 public void testTransferInitiated()
59 throws Exception
60 {
61 monitor.transferInitiated( new TransferEventMock() );
62 }
63
64 public void testTransferStarted()
65 throws Exception
66 {
67 monitor.transferStarted( new TransferEventMock() );
68 }
69
70 public void testTransferProgress()
71 throws Exception
72 {
73 byte[] buffer = new byte[1000];
74 monitor.transferProgress( new TransferEventMock(), buffer, 1000 );
75 }
76
77 public void testTransferCompleted()
78 throws Exception
79 {
80 monitor.transferCompleted( new TransferEventMock() );
81 }
82
83 public void testTransferError()
84 throws Exception
85 {
86 monitor.transferError( new TransferEventMock( new RuntimeException() ) );
87 }
88
89 public void testDebug()
90 throws Exception
91 {
92 monitor.debug( "msg" );
93 }
94
95 static class TransferEventMock
96 extends TransferEvent
97 {
98
99 public TransferEventMock()
100 throws ConnectionException, AuthenticationException
101 {
102 super( new FileWagon(), new Resource(), TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
103 getResource().setContentLength( 100000 );
104 getResource().setName( "foo.bar" );
105 Repository repository = new Repository();
106 getWagon().connect( repository );
107 }
108
109 public TransferEventMock( Resource resource, int length )
110 throws ConnectionException, AuthenticationException
111 {
112 super( new FileWagon(), resource, TransferEvent.TRANSFER_INITIATED, TransferEvent.REQUEST_GET );
113 getResource().setContentLength( length );
114 Repository repository = new Repository();
115 getWagon().connect( repository );
116 }
117
118 public TransferEventMock( Exception exception )
119 throws ConnectionException, AuthenticationException
120 {
121 super( new FileWagon(), new Resource(), exception, TransferEvent.REQUEST_GET );
122 getResource().setContentLength( 100000 );
123 getResource().setName( "foo.bar" );
124 Repository repository = new Repository();
125 getWagon().connect( repository );
126 }
127 }
128 }