本文整理了Java中org.junit.experimental.theories.Theory
类的一些代码示例,展示了Theory
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Theory
类的具体详情如下:
包路径:org.junit.experimental.theories.Theory
类名称:Theory
暂无
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryNonDirectoriesHaveFileWithSameContents(String path) throws Exception {
Resource res = getResource(path);
assumeThat(res, not(directory()));
byte[] test = {42, 29, 32, 120, 69, 0, 1};
try (OutputStream ostream = res.out()) {
ostream.write(test);
}
byte[] result = new byte[test.length];
try (InputStream istream = new FileInputStream(res.file())) {
istream.read(result);
assertThat(istream.read(), is(-1));
}
assertThat(result, equalTo(test));
}
代码示例来源:origin: junit-team/junit4
private boolean nullsOk() {
Theory annotation = testMethod.getMethod().getAnnotation(
Theory.class);
if (annotation == null) {
return false;
}
return annotation.nullsAccepted();
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryChildrenKnowTheirParents(String path) throws Exception {
Resource res = getResource(path);
assumeThat(res, is(directory()));
Collection<Resource> children = res.list();
assumeThat(children, not(empty())); // Make sure this resource has children
for (Resource child : children) {
Resource parent = child.parent();
assertThat(parent, equalTo(res));
}
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryDoubleClose(String path) throws Exception {
final Resource res = getResource(path);
assumeThat(res, is(resource()));
OutputStream os = res.out();
os.close();
os.close();
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryMultipleOutputStreamsAreSafe(String path) throws Exception {
final Resource res = getResource(path);
assumeThat(res, is(resource()));
final byte[] thread1Content = "This is the content for thread 1".getBytes();
final byte[] thread2Content = "Thread 2 has this content".getBytes();
try (OutputStream out1 = res.out()) {
try (OutputStream out2 = res.out()) {
for (int i = 0; i < thread1Content.length || i < thread2Content.length; i++) {
if (i < thread1Content.length) {
out1.write(thread1Content[i]);
}
if (i < thread2Content.length) {
out2.write(thread2Content[i]);
}
}
}
}
final byte[] resultContent;
try (InputStream in = res.in()) {
resultContent = IOUtils.toByteArray(in);
}
// 2 streams being written to concurrently should result in the resource containing
// what was written to one of the two streams.
assertThat(resultContent, anyOf(equalTo(thread1Content), equalTo(thread2Content)));
}
代码示例来源:origin: jenkinsci/remoting
@Theory
public void headerExchange(NetworkLayerFactory serverFactory, NetworkLayerFactory clientFactory) throws Exception {
Random entropy = new Random();
.on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink()))
.filter(new ConnectionHeadersFilterLayer(clientExpectedHeaders,
new ConnectionHeadersFilterLayer.Listener() {
.on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink()))
.filter(new ConnectionHeadersFilterLayer(serverExpectedHeaders,
new ConnectionHeadersFilterLayer.Listener() {
data.flip();
server.get().send(data);
client.get().awaitByteContent(is(expected));
assertThat(client.get().asByteArray(), is(expected));
assertThat(serverActualHeaders.get(1000, TimeUnit.MICROSECONDS), is(serverExpectedHeaders));
assertThat(clientActualHeaders.get(1000, TimeUnit.MICROSECONDS), is(clientExpectedHeaders));
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryAddingFileToDirectoryAddsResource(String path) throws Exception {
Resource res = getResource(path);
assumeThat(res, is(directory()));
File dir = res.dir();
File file = new File(dir, "newFileCreatedDirectly");
assumeTrue(file.createNewFile());
Resource child = getResource(Paths.path(res.path(), "newFileCreatedDirectly"));
Collection<Resource> children = res.list();
assertThat(child, is(defined()));
assertThat(children, hasItem(child));
}
代码示例来源:origin: neo4j/neo4j
@Theory
public void hashCodeMustFollowValues(
ValueProducer values, Factory<PrimitiveCollection> factory )
assumeTrue( values.isApplicable( factory ) );
try ( PrimitiveCollection a = factory.newInstance() )
int o = a.hashCode();
assertThat( "0 elm hashcode equal", o, is( i ) );
assertThat( "1 elm hashcode equal", n, is( j ) );
assertThat( "2 elm hashcode equal", m, is( k ) );
assertThat( "3 elm hashcode distinct", l, not( isOneOf( i, j, k, m, n, o ) ) );
assertThat( "2 elm hashcode distinct", k, not( isOneOf( i, j, l, n, o ) ) );
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryDirectoriesHaveNoIstreams(String path) throws Exception {
Resource res = getResource(path);
assumeThat(res, is(directory()));
exception.expect(IllegalStateException.class);
res.in().close();
}
代码示例来源:origin: real-logic/agrona
@Theory
public void shouldGetSizeWhenEmpty(final Fixture fixture)
{
final Queue<Integer> queue = fixture.newInstance();
assertThat(queue.size(), is(0));
}
代码示例来源:origin: jenkinsci/remoting
@Theory
public void clientRefuses(NetworkLayerFactory serverFactory, NetworkLayerFactory clientFactory) throws Exception {
ProtocolStack<IOBufferMatcher> client =
ProtocolStack
.on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink()))
.filter(new ConnectionHeadersFilterLayer(Collections.<String, String>emptyMap(),
new ConnectionHeadersFilterLayer.Listener() {
.on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink()))
.filter(new ConnectionHeadersFilterLayer(Collections.<String, String>emptyMap(),
new ConnectionHeadersFilterLayer.Listener() {
allOf(instanceOf(ConnectionRefusalException.class), not(instanceOf(PermanentConnectionRefusalException.class))));
server.get().awaitClose();
assertThat(server.get().getCloseCause(),
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryRenamedResourcesAreEquivalent(String path) throws Exception {
final Resource res = getResource(path);
assumeThat(res, resource());
final byte[] expectedContent;
try (InputStream in = res.in()) {
expectedContent = IOUtils.toByteArray(in);
}
final Resource target = getUndefined();
assertThat(res.renameTo(target), is(true));
assertThat(target, resource());
final byte[] resultContent;
try (InputStream in = target.in()) {
resultContent = IOUtils.toByteArray(in);
}
assertThat(resultContent, equalTo(expectedContent));
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryParentsKnowTheirChildren(String path) throws Exception {
Resource res = getResource(path);
assumeThat(res, is(directory()));
Resource parent = res.parent();
assumeThat(path, parent, notNullValue()); // Make sure this resource has a parent
Collection<Resource> result = parent.list();
assertThat(path, result, hasItem(res)); // this assumed equals was written!
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryHaveSamePath(String path) throws Exception {
Resource res = getResource(path);
String result = res.path();
assertThat(result, is(equalTo(path)));
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryLeavesHaveEmptyListOfChildren(String path) throws Exception {
Resource res = getResource(path);
assumeThat(res, is(resource()));
Collection<Resource> result = res.list();
assertThat(result, empty());
}
代码示例来源:origin: lenskit/lenskit
@Theory
public void testSingleton(KeyData data) {
assumeThat(data, notNullValue());
long key = data.getKey(); // key to use
long low = data.getLow(); // unused low key
long high = data.getAfter(1); // unused high key
long[] rawKeys = {key};
SortedKeyIndex keys = SortedKeyIndex.wrap(rawKeys, 1);
assertThat(keys.size(), equalTo(1));
assertThat(keys.size(), equalTo(1));
assertThat(keys.keySet(), hasSize(1));
assertThat(keys.tryGetIndex(key), equalTo(0));
assertThat(keys.tryGetIndex(low), lessThan(0));
assertThat(keys.tryGetIndex(high), lessThan(0));
assertThat(keys.getKeyList(), contains(key));
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryParentIsDirectory(String path) throws Exception {
Resource res = getResource(path);
Resource parent = res.parent();
assumeThat(path + " not root", parent, notNullValue());
if (res.getType() != Type.UNDEFINED) {
assertThat(path + " directory", parent, is(directory()));
}
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryRecursiveDelete(String path) throws Exception {
final Resource res = getResource(path);
assumeThat(res, is(directory()));
assumeThat(res, is(directory()));
Collection<Resource> result = res.list();
assumeThat(result.size(), greaterThan(0));
assertTrue(res.delete());
}
代码示例来源:origin: geoserver/geoserver
@Theory
public void theoryDirectoriesHaveChildren(String path) throws Exception {
Resource res = getResource(path);
assumeThat(res, is(directory()));
Collection<Resource> result = res.list();
assertThat(result, notNullValue());
}
代码示例来源:origin: jenkinsci/remoting
@Theory
public void serverRejectsClient(NetworkLayerFactory serverFactory, NetworkLayerFactory clientFactory) throws Exception {
Logger.getLogger(name.getMethodName()).log(
clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink()))
.filter(new SSLEngineFilterLayer(clientEngine, null))
.build(new IOBufferMatcherLayer());
serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink()))
.filter(new SSLEngineFilterLayer(serverEngine, new SSLEngineFilterLayer.Listener() {
@Override
Logger.getLogger(name.getMethodName()).log(Level.INFO, "Waiting for server close");
serverMatcher.awaitClose();
assertThat(clientMatcher.getCloseCause(), instanceOf(ClosedChannelException.class));
assertThat(serverMatcher.getCloseCause(), instanceOf(ConnectionRefusalException.class));
Logger.getLogger(name.getMethodName()).log(Level.INFO, "Done");
内容来源于网络,如有侵权,请联系作者删除!