notToBe

infix fun <T : CharSequence> Expect<T>.notToBe(empty: empty): Expect<T>(source)

Expects that the subject of this expectation (a CharSequence) CharSequence.kotlin.text.isNotEmpty.

Return

an Expect for the subject of this expectation.

Parameters

empty

Use the pseudo-keyword empty.

Samples

expect("XYZ") notToBe empty

fails {
    expect("") notToBe empty
}

// use `notToBe blank` to check for whitespaces
expect(" ") notToBe empty

infix fun <T : CharSequence> Expect<T>.notToBe(blank: blank): Expect<T>(source)

Expects that the subject of this expectation (a CharSequence) CharSequence.kotlin.text.isNotBlank.

Return

an Expect for the subject of this expectation.

Parameters

blank

Use the pseudo-keyword blank.

Samples

expect("XZY") notToBe blank

fails {
    expect(" ") notToBe blank
}

fails { // because an empty string is also considered to be a blank string
    expect("") notToBe blank
}

infix fun <T : Collection<*>> Expect<T>.notToBe(empty: empty): Expect<T>(source)

Expects that the subject of this expectation (a Collection) is not an empty Collection.

Return

an Expect for the subject of this expectation.

Parameters

empty

Use the pseudo-keyword empty.

Samples

expect(listOf(1, 2, 3)) notToBe empty

fails {
    expect(emptyList<Int>()) notToBe empty
}

infix fun <T : Map<*, *>> Expect<T>.notToBe(empty: empty): Expect<T>(source)

Expects that the subject of this expectation (a Map) is not an empty Map.

Return

an Expect for the subject of this expectation.

Parameters

empty

Use the pseudo-keyword empty.

Samples

expect(mapOf(1 to "a")) notToBe empty

fails { // because the map is empty
    expect(emptyMap<Int, String>()) notToBe empty
}
infix fun <T : Path> Expect<T>.notToBe(existing: existing): Expect<T>(source)

Expects that the subject of this expectation (a Path) does not exist; meaning that there is no file system entry at the location the Path points to.

This assertion resolves symbolic links. Therefore, if a symbolic link exists at the location the subject points to, then the search will continue at that location.

Return

an Expect for the subject of this expectation.

Since

0.12.0

Samples

val dir = tempDir.newDirectory("test_dir")

expect(Paths.get("non_existing_dir")) notToBe existing

fails {
    expect(dir) notToBe existing
}

infix fun <T : Path> Expect<T>.notToBe(readable: readable): Expect<T>(source)

Expects that the subject of this expectation (a Path) is not readable; meaning that there is a file system entry at the location the Path points to and that the current thread does not have the permission to read from it.

This assertion resolves symbolic links. Therefore, if a symbolic link exists at the location the subject points to, search will continue at the location the link points at.

This assertion is not atomic with respect to concurrent file system operations on the paths the assertion works on. Its result, in particular its extended explanations, may be wrong if such concurrent file system operations take place.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

assertIf(fileSystemSupportsPosixPermissions()) {
    val writeOnlyPermissions =
        PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("-w--w--w-"))
    val readWritePermissions =
        PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-"))

    val writeOnlyDir = tempDir.newDirectory("write_only_dir", writeOnlyPermissions)
    val writeOnlyFile = tempDir.newFile("write_only_file", writeOnlyPermissions)
    val readWriteDir = tempDir.newDirectory("read_write_dir", readWritePermissions)
    val readWriteFile = tempDir.newFile("read_write_file", readWritePermissions)

    expect(writeOnlyDir) notToBe readable
    expect(writeOnlyFile) notToBe readable

    fails {
        expect(readWriteDir) notToBe readable
    }
    fails {
        expect(readWriteFile) notToBe readable
    }
}

fails {
    expect(Paths.get("non_existing_dir")) notToBe readable
}

infix fun <T : Path> Expect<T>.notToBe(writable: writable): Expect<T>(source)

Expects that the subject of this expectation (a Path) is not writable; meaning that there is a file system entry at the location the Path points to and that the current thread does not have the permission to write from it.

This assertion resolves symbolic links. Therefore, if a symbolic link exists at the location the subject points to, search will continue at the location the link points at.

This assertion is not atomic with respect to concurrent file system operations on the paths the assertion works on. Its result, in particular its extended explanations, may be wrong if such concurrent file system operations take place.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

assertIf(ifPosixSupported) {
    val readyOnlyPermissions =
        PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("r--r--r--"))
    val readyWritePermissions =
        PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-r--r--"))

    val readOnlyDir = tempDir.newDirectory("read_only_dir", readyOnlyPermissions)
    val readOnlyFile = tempDir.newFile("read_only_file", readyOnlyPermissions)
    val readWriteDir = tempDir.newDirectory("read_write_dir", readyWritePermissions)
    val readWriteFile = tempDir.newFile("read_write_file", readyWritePermissions)

    expect(readOnlyDir) notToBe writable
    expect(readOnlyFile) notToBe writable

    fails {
        expect(readWriteDir) notToBe writable
    }
    fails {
        expect(readWriteFile) notToBe writable
    }
}

fails {
    expect(Paths.get("non_existing_dir")) notToBe writable
}

infix fun <T : Path> Expect<T>.notToBe(executable: executable): Expect<T>(source)

Expects that the subject of this expectation (a Path) is not executable; meaning that there is a file system entry at the location the Path points to and that the current thread does not have the permission to execute it.

The semantics of “permission to execute it” may differ when checking access to a directory. For example, on UNIX systems, it means that the Java virtual machine has permission to search the directory in order to access file or subdirectories.

This assertion resolves symbolic links. Therefore, if a symbolic link exists at the location the subject points to, search will continue at the location the link points at.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

assertIf(ifPosixSupported) {
    val readyOnlyPermissions =
        PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("r--r--r--"))
    val readyWriteExecutePermissions =
        PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr--r--"))

    val readOnlyDir = tempDir.newDirectory("read_only_dir", readyOnlyPermissions)
    val readOnlyFile = tempDir.newFile("read_only_file", readyOnlyPermissions)
    val readWriteExecuteDir = tempDir.newDirectory("read_write_execute_dir", readyWriteExecutePermissions)
    val readWriteExecuteFile = tempDir.newFile("read_write_execute_file", readyWriteExecutePermissions)

    expect(readOnlyDir) notToBe executable
    expect(readOnlyFile) notToBe executable

    fails {
        expect(readWriteExecuteDir) notToBe executable
    }
    fails {
        expect(readWriteExecuteFile) notToBe executable
    }
}

fails {
    expect(Paths.get("non_existing_dir")) notToBe executable
}