mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
hamcrest FileExistenceMatcher, junit 4 TemporaryDirectory
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<root>
|
||||
<item name='org.hamcrest.SelfDescribing void describeTo(org.hamcrest.Description) 0'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='org.hamcrest.TypeSafeDiagnosingMatcher boolean matchesSafely(T, org.hamcrest.Description) 0'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='org.hamcrest.TypeSafeDiagnosingMatcher boolean matchesSafely(T, org.hamcrest.Description) 1'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.testFramework
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.util.SmartList
|
||||
import org.junit.rules.ExternalResource
|
||||
import java.io.File
|
||||
|
||||
public class TemporaryDirectory : ExternalResource() {
|
||||
private val files = SmartList<File>()
|
||||
|
||||
override fun after() {
|
||||
for (file in files) {
|
||||
FileUtil.delete(file)
|
||||
}
|
||||
files.clear()
|
||||
}
|
||||
|
||||
public fun newDirectory(): File {
|
||||
val file = FileUtilRt.generateRandomTemporaryPath()
|
||||
files.add(file)
|
||||
return file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.testFramework
|
||||
|
||||
import org.hamcrest.Description
|
||||
import org.hamcrest.Factory
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.TypeSafeDiagnosingMatcher
|
||||
import java.io.File
|
||||
|
||||
public class FileExistenceMatcher(private val exists: Boolean) : TypeSafeDiagnosingMatcher<File>(javaClass<File>()) {
|
||||
override fun matchesSafely(file: File, mismatchDescription: Description): Boolean {
|
||||
if (exists == file.exists()) {
|
||||
return true
|
||||
}
|
||||
|
||||
mismatchDescription.appendText("is not a file")
|
||||
return false
|
||||
}
|
||||
|
||||
override fun describeTo(description: Description) {
|
||||
description.appendText("an existing file")
|
||||
}
|
||||
}
|
||||
|
||||
public Factory fun exists(): Matcher<File> = FileExistenceMatcher(true)
|
||||
Reference in New Issue
Block a user