1 package org.apache.maven.shared.io.location;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.net.URL;
25
26 import org.apache.maven.shared.io.Utils;
27
28 import junit.framework.TestCase;
29
30 public class URLLocationTest
31 extends TestCase
32 {
33
34 public void testShouldConstructFromUrlAndTempFileSpecifications() throws IOException
35 {
36 File f = File.createTempFile( "url-location.", ".test" );
37 f.deleteOnExit();
38
39 URL url = f.toURL();
40
41 new URLLocation( url, f.getAbsolutePath(), "prefix.", ".suffix", true );
42 }
43
44 public void testShouldTransferFromTempFile() throws IOException
45 {
46 File f = File.createTempFile( "url-location.", ".test" );
47 f.deleteOnExit();
48
49 URL url = f.toURL();
50
51 URLLocation location = new URLLocation( url, f.getAbsolutePath(), "prefix.", ".suffix", true );
52
53 assertNotNull( location.getFile() );
54 assertFalse( f.equals( location.getFile() ) );
55 }
56
57 public void testShouldTransferFromTempFileThenRead() throws IOException
58 {
59 File f = File.createTempFile( "url-location.", ".test" );
60 f.deleteOnExit();
61
62 String testStr = "This is a test";
63
64 Utils.writeFileWithEncoding( f, testStr, "US-ASCII" );
65
66 URL url = f.toURL();
67
68 URLLocation location = new URLLocation( url, f.getAbsolutePath(), "prefix.", ".suffix", true );
69
70 location.open();
71
72 byte[] buffer = new byte[ testStr.length() ];
73
74 int read = location.read( buffer );
75
76 assertEquals( testStr.length(), read );
77
78 assertEquals( testStr, new String( buffer, "US-ASCII" ) );
79 }
80
81 }