Skip to content

Commit 00cd335

Browse files
committed
Moved tests to spock
1 parent e14fb2f commit 00cd335

File tree

4 files changed

+126
-159
lines changed

4 files changed

+126
-159
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (C)2009 - SSHJ Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.schmizz.sshj.sftp
17+
18+
import spock.lang.Shared
19+
import spock.lang.Specification
20+
import spock.lang.Unroll
21+
22+
class PathHelperSpec extends Specification {
23+
24+
@Shared
25+
def pathHelper = new PathHelper(new PathHelper.Canonicalizer() {
26+
/**
27+
* Very basic, it does not try to canonicalize relative bits in the middle of a path.
28+
*/
29+
@Override
30+
String canonicalize(String path)
31+
throws IOException {
32+
if ("" == path || "." == path || "./" == path)
33+
return "/home/me"
34+
if (".." == path || "../" == path)
35+
return "/home"
36+
return path
37+
}
38+
}, "/")
39+
40+
41+
@Unroll
42+
def "should correctly componentize path \"#input\""() {
43+
given:
44+
def components = pathHelper.getComponents(input)
45+
46+
expect:
47+
components.getName() == name
48+
components.getParent() == parent
49+
components.getPath() == path
50+
51+
where:
52+
input || name | path | parent
53+
"" || "me" | "/home/me" | "/home"
54+
"/" || "/" | "/" | ""
55+
"." || "me" | "/home/me" | "/home"
56+
".." || "home" | "/home" | "/"
57+
"somefile" || "somefile" | "somefile" | ""
58+
"dir1/dir2" || "dir2" | "dir1/dir2" | "dir1"
59+
"/home/me/../somedir/somefile" || "somefile" | "/home/me/../somedir/somefile" | "/home/me/../somedir"
60+
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C)2009 - SSHJ Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.schmizz.sshj.sftp
17+
18+
import spock.lang.Specification
19+
import spock.lang.Unroll
20+
21+
class ResponseStatusCodeSpec extends Specification {
22+
23+
@Unroll
24+
def "status #status should have status code #code"() {
25+
expect:
26+
code == status.getCode()
27+
28+
where:
29+
status || code
30+
Response.StatusCode.UNKNOWN || -1
31+
Response.StatusCode.OK || 0
32+
Response.StatusCode.EOF || 1
33+
Response.StatusCode.NO_SUCH_FILE || 2
34+
Response.StatusCode.PERMISSION_DENIED || 3
35+
Response.StatusCode.FAILURE || 4
36+
Response.StatusCode.BAD_MESSAGE || 5
37+
Response.StatusCode.NO_CONNECTION || 6
38+
Response.StatusCode.CONNECITON_LOST || 7
39+
Response.StatusCode.OP_UNSUPPORTED || 8
40+
Response.StatusCode.INVALID_HANDLE || 9
41+
Response.StatusCode.NO_SUCH_PATH || 10
42+
Response.StatusCode.FILE_ALREADY_EXISTS || 11
43+
Response.StatusCode.WRITE_PROTECT || 12
44+
Response.StatusCode.NO_MEDIA || 13
45+
Response.StatusCode.NO_SPACE_ON_FILESYSTEM || 14
46+
Response.StatusCode.QUOTA_EXCEEDED || 15
47+
Response.StatusCode.UNKNOWN_PRINCIPAL || 16
48+
Response.StatusCode.LOCK_CONFLICT || 17
49+
Response.StatusCode.DIR_NOT_EMPTY || 18
50+
Response.StatusCode.NOT_A_DIRECTORY || 19
51+
Response.StatusCode.INVALID_FILENAME || 20
52+
Response.StatusCode.LINK_LOOP || 21
53+
Response.StatusCode.CANNOT_DELETE || 22
54+
Response.StatusCode.INVALID_PARAMETER || 23
55+
Response.StatusCode.FILE_IS_A_DIRECTORY || 24
56+
Response.StatusCode.BYTE_RANGE_LOCK_CONFLICT || 25
57+
Response.StatusCode.BYTE_RANGE_LOCK_REFUSED || 26
58+
Response.StatusCode.DELETE_PENDING || 27
59+
Response.StatusCode.FILE_CORRUPT || 28
60+
Response.StatusCode.OWNER_INVALID || 29
61+
Response.StatusCode.GROUP_INVALID || 30
62+
Response.StatusCode.NO_MATCHING_BYTE_RANGE_LOCK || 31
63+
}
64+
}

src/test/java/net/schmizz/sshj/sftp/PathHelperTest.java

-98
This file was deleted.

src/test/java/net/schmizz/sshj/sftp/ResponseStatusCodeTest.java

-61
This file was deleted.

0 commit comments

Comments
 (0)