|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 | 20 | import java.io.IOException;
|
21 |
| -import java.nio.file.Files; |
22 | 21 | import java.util.Date;
|
23 | 22 |
|
24 | 23 | import org.codehaus.plexus.components.io.filemappers.FileMapper;
|
25 | 24 | import org.hamcrest.BaseMatcher;
|
26 |
| -import org.hamcrest.CoreMatchers; |
27 | 25 | import org.hamcrest.Description;
|
28 | 26 | import org.hamcrest.core.StringContains;
|
29 | 27 | import org.junit.After;
|
@@ -112,65 +110,77 @@ public String getMappedFileName( String pName )
|
112 | 110 | // ArchiverException is thrown providing the rewritten path
|
113 | 111 | }
|
114 | 112 |
|
| 113 | + @Test |
| 114 | + public void shouldExtractWhenFileOnDiskDoesNotExist() throws IOException |
| 115 | + { |
| 116 | + // given |
| 117 | + File file = new File( temporaryFolder.getRoot(), "whatever.txt" ); // does not create the file! |
| 118 | + String entryname = file.getName(); |
| 119 | + Date entryDate = new Date(); |
| 120 | + |
| 121 | + // when & then |
| 122 | + assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is ( true ) ); |
| 123 | + } |
| 124 | + |
115 | 125 | @Test
|
116 | 126 | public void shouldNotExtractWhenFileOnDiskIsNewerThanEntryInArchive() throws IOException
|
117 | 127 | {
|
118 | 128 | // given
|
119 |
| - File file = temporaryFolder.newFile( "readme.txt" ); |
| 129 | + File file = temporaryFolder.newFile(); |
120 | 130 | file.setLastModified( System.currentTimeMillis() );
|
121 |
| - String entryname = "readme.txt"; |
| 131 | + String entryname = file.getName(); |
122 | 132 | Date entryDate = new Date( 0 );
|
123 | 133 |
|
124 | 134 | // when & then
|
125 |
| - assertThat( this.abstractUnArchiver.shouldExtractEntry( file, entryname, entryDate ), is ( false ) ); |
| 135 | + assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is ( false ) ); |
126 | 136 | }
|
127 | 137 |
|
128 | 138 | @Test
|
129 | 139 | public void shouldNotExtractWhenFileOnDiskIsNewerThanEntryInArchive_andWarnAboutDifferentCasing() throws IOException
|
130 | 140 | {
|
131 | 141 | // given
|
132 |
| - File file = temporaryFolder.newFile( "readme.txt" ); |
| 142 | + File file = temporaryFolder.newFile(); |
133 | 143 | file.setLastModified( System.currentTimeMillis() );
|
134 |
| - String entryname = "README.txt"; |
| 144 | + String entryname = file.getName().toUpperCase(); |
135 | 145 | Date entryDate = new Date( 0 );
|
136 | 146 |
|
137 | 147 | // when & then
|
138 |
| - assertThat( this.abstractUnArchiver.shouldExtractEntry( file, entryname, entryDate ), is ( false ) ); |
| 148 | + assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is ( false ) ); |
139 | 149 | assertThat( this.log.getWarns(), hasItem( new LogMessageMatcher( "names differ only by case" ) ) );
|
140 | 150 | }
|
141 | 151 |
|
142 | 152 | @Test
|
143 | 153 | public void shouldExtractWhenEntryInArchiveIsNewerThanFileOnDisk() throws IOException
|
144 | 154 | {
|
145 | 155 | // given
|
146 |
| - File file = temporaryFolder.newFile( "readme.txt" ); |
| 156 | + File file = temporaryFolder.newFile(); |
147 | 157 | file.setLastModified( 0 );
|
148 |
| - String entryname = "readme.txt"; |
| 158 | + String entryname = file.getName().toUpperCase(); |
149 | 159 | Date entryDate = new Date( System.currentTimeMillis() );
|
150 | 160 |
|
151 | 161 | // when & then
|
152 | 162 | this.abstractUnArchiver.setOverwrite( true );
|
153 |
| - assertThat( this.abstractUnArchiver.shouldExtractEntry( file, entryname, entryDate ), is( true ) ); |
| 163 | + assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is( true ) ); |
154 | 164 |
|
155 | 165 | // when & then
|
156 | 166 | this.abstractUnArchiver.setOverwrite( false );
|
157 |
| - assertThat( this.abstractUnArchiver.shouldExtractEntry( file, entryname, entryDate ), is( false ) ); |
| 167 | + assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is( false ) ); |
158 | 168 | }
|
159 | 169 |
|
160 | 170 | @Test
|
161 | 171 | public void shouldExtractWhenEntryInArchiveIsNewerThanFileOnDiskAndWarnAboutDifferentCasing() throws IOException
|
162 | 172 | {
|
163 | 173 | // given
|
164 |
| - File file = temporaryFolder.newFile( "readme.txt" ); |
| 174 | + File file = temporaryFolder.newFile(); |
165 | 175 | file.setLastModified( 0 );
|
166 |
| - String entryname = "README.txt"; |
| 176 | + String entryname = file.getName().toUpperCase(); |
167 | 177 | Date entryDate = new Date( System.currentTimeMillis() );
|
168 | 178 |
|
169 | 179 | // when & then
|
170 | 180 | this.abstractUnArchiver.setOverwrite( true );
|
171 |
| - assertThat( this.abstractUnArchiver.shouldExtractEntry( file, entryname, entryDate ), is( true ) ); |
| 181 | + assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is( true ) ); |
172 | 182 | this.abstractUnArchiver.setOverwrite( false );
|
173 |
| - assertThat( this.abstractUnArchiver.shouldExtractEntry( file, entryname, entryDate ), is( false ) ); |
| 183 | + assertThat( this.abstractUnArchiver.shouldExtractEntry( temporaryFolder.getRoot(), file, entryname, entryDate ), is( false ) ); |
174 | 184 | assertThat( this.log.getWarns(), hasItem( new LogMessageMatcher( "names differ only by case" ) ) );
|
175 | 185 | }
|
176 | 186 |
|
|
0 commit comments