org.hamcrest.core.IsNull类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(13.7k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中org.hamcrest.core.IsNull类的一些代码示例,展示了IsNull类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IsNull类的具体详情如下:
包路径:org.hamcrest.core.IsNull
类名称:IsNull

IsNull介绍

[英]Is the value null?
[中]值是否为空?

代码示例

代码示例来源:origin: google/j2objc

/**
 * A shortcut to the frequently used <code>not(nullValue())</code>.
 * <p/>
 * For example:
 * <pre>assertThat(cheese, is(notNullValue()))</pre>
 * instead of:
 * <pre>assertThat(cheese, is(not(nullValue())))</pre>
 */
public static org.hamcrest.Matcher<java.lang.Object> notNullValue() {
 return org.hamcrest.core.IsNull.notNullValue();
}

代码示例来源:origin: google/j2objc

/**
 * Creates a matcher that matches if examined object is <code>null</code>.
 * <p/>
 * For example:
 * <pre>assertThat(cheese, is(nullValue())</pre>
 */
public static org.hamcrest.Matcher<java.lang.Object> nullValue() {
 return org.hamcrest.core.IsNull.nullValue();
}

代码示例来源:origin: hamcrest/JavaHamcrest

/**
 * Creates a matcher that matches if examined object is <code>null</code>.
 * For example:
 * <pre>assertThat(cheese, is(nullValue())</pre>
 * 
 */
public static Matcher<Object> nullValue() {
  return new IsNull<Object>();
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void testTryWriteLockFailingClosesEntity() throws Exception {
 when(client.tryLock(WRITE)).thenReturn(false);
 when(entityRef.fetchEntity(null)).thenReturn(client);
 when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef);
 VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock");
 assertThat(lock.tryWriteLock(), nullValue());
 verify(client).close();
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldParseDynamicOperandFromStringContainingReferenceValueOfSelector() {
  DynamicOperand operand = parser.parseDynamicOperand(tokens("REFERENCE(tableA)"), typeSystem, mock(Source.class));
  assertThat(operand, is(instanceOf(ReferenceValue.class)));
  ReferenceValue value = (ReferenceValue)operand;
  assertThat(value.selectorName(), is(selectorName("tableA")));
  assertThat(value.getPropertyName(), is(nullValue()));
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void testTryReadLockTryLocksRead() throws Exception {
 when(client.tryLock(READ)).thenReturn(true);
 when(entityRef.fetchEntity(null)).thenReturn(client);
 when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef);
 VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock");
 assertThat(lock.tryReadLock(), notNullValue());
 verify(client).tryLock(READ);
}

代码示例来源:origin: mulesoft/mule

@Test
public void nullDeploymentClassLoaderAfterDispose() {
 ApplicationDescriptor descriptor = mock(ApplicationDescriptor.class);
 when(descriptor.getConfigResources()).thenReturn(emptySet());
 DefaultMuleApplication application =
   new DefaultMuleApplication(descriptor, mock(MuleApplicationClassLoader.class), emptyList(), null,
                 null, null, appLocation, null, null, null);
 application.install();
 assertThat(application.deploymentClassLoader, is(notNullValue()));
 application.dispose();
 assertThat(application.deploymentClassLoader, is(nullValue()));
}

代码示例来源:origin: mulesoft/mule

@Test
public void transformerFactoryProperties() {
 SetPropertyAnswer setPropertyAnswer = new SetPropertyAnswer(transformerFactory);
 doAnswer(setPropertyAnswer).when(transformerFactoryWrapper).setAttribute(anyString(), anyObject());
 defaultXMLSecureFactories.configureTransformerFactory(transformerFactoryWrapper);
 assertThat(setPropertyAnswer.exception, is(nullValue()));
 for (String property : FACTORY_ATTRIBUTES) {
  verify(transformerFactoryWrapper).setAttribute(property, "");
 }
}

代码示例来源:origin: ehcache/ehcache3

@Test
public void testGetAllWithLoaderException() throws Exception {
 when(cacheLoaderWriter.loadAll(ArgumentMatchers.<Iterable<Number>>any())).thenAnswer(invocation -> {
  @SuppressWarnings("unchecked")
  Iterable<Integer> iterable = (Iterable<Integer>) invocation.getArguments()[0];
  fail("expected BulkCacheLoadingException");
 } catch (BulkCacheLoadingException ex) {
  assertThat(ex.getFailures().size(), is(1));
  assertThat(ex.getFailures().get(2), is(notNullValue()));
  assertThat(ex.getSuccesses().size(), is(lessThan(4)));
  assertThat(ex.getSuccesses().containsKey(2), is(false));

代码示例来源:origin: mulesoft/mule

@Test
public void testActionBeginOrJoinAndNoTx() throws Exception {
 MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_BEGIN_OR_JOIN);
 ExecutionTemplate executionTemplate = createExecutionTemplate(config);
 config.setFactory(new TestTransactionFactory(mockTransaction));
 Object result = executionTemplate.execute(getEmptyTransactionCallback());
 assertThat(result, is(RETURN_VALUE));
 verify(mockTransaction).commit();
 verify(mockTransaction, never()).rollback();
 assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>nullValue());
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldImportIntoWorkspaceTheDocumentViewOfTheContentUsedInTckTests() throws Exception {
  Session session3 = repository.login();
  session.nodeTypeManager().registerNodeTypes(resourceStream("tck/tck_test_types.cnd"), true);
  session.getWorkspace().importXML("/",
                   resourceStream("tck/documentViewForTckTests.xml"),
                   ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
  assertThat(session.getRootNode().hasNode("testroot/workarea"), is(true));
  assertThat(session.getRootNode().getNode("testroot/workarea"), is(notNullValue()));
  assertThat(session.getNode("/testroot/workarea"), is(notNullValue()));
  assertNode("/testroot/workarea");
  Session session1 = repository.login();
  assertThat(session1.getRootNode().hasNode("testroot/workarea"), is(true));
  assertThat(session1.getRootNode().getNode("testroot/workarea"), is(notNullValue()));
  assertThat(session1.getNode("/testroot/workarea"), is(notNullValue()));
  session1.logout();
  assertThat(session3.getRootNode().hasNode("testroot/workarea"), is(true));
  assertThat(session3.getRootNode().getNode("testroot/workarea"), is(notNullValue()));
  assertThat(session3.getNode("/testroot/workarea"), is(notNullValue()));
  session3.logout();
}

代码示例来源:origin: ModeShape/modeshape

@SuppressWarnings( "deprecation" )
public void testShouldCreateProperVersionHistoryWhenSavingVersionedNode() throws Exception {
  session = getHelper().getReadWriteSession();
  Node node = session.getRootNode().addNode("test", "nt:unstructured");
  node.addMixin("mix:versionable");
  session.save();
  assertThat(node.hasProperty("jcr:isCheckedOut"), is(true));
  assertThat(node.getProperty("jcr:isCheckedOut").getBoolean(), is(true));
  assertThat(node.hasProperty("jcr:versionHistory"), is(true));
  Node history = node.getProperty("jcr:versionHistory").getNode();
  assertThat(history, is(notNullValue()));
  assertThat(node.hasProperty("jcr:baseVersion"), is(true));
  Node version = node.getProperty("jcr:baseVersion").getNode();
  assertThat(version, is(notNullValue()));
  assertThat(version.getParent(), is(history));
  assertThat(node.hasProperty("jcr:uuid"), is(true));
  assertThat(node.getProperty("jcr:uuid").getString(), is(history.getProperty("jcr:versionableUuid").getString()));
  assertThat(versionHistory(node).getUUID(), is(history.getUUID()));
  assertThat(versionHistory(node).getIdentifier(), is(history.getIdentifier()));
  assertThat(versionHistory(node).getPath(), is(history.getPath()));
  assertThat(baseVersion(node).getUUID(), is(version.getUUID()));
  assertThat(baseVersion(node).getIdentifier(), is(version.getIdentifier()));
  assertThat(baseVersion(node).getPath(), is(version.getPath()));
}

代码示例来源:origin: ModeShape/modeshape

@FixFor( "MODE-1089" )
public void testShouldNotFailGettingVersionHistoryForNodeMadeVersionableSinceLastSave() throws Exception {
  Session session1 = getHelper().getSuperuserSession();
  VersionManager vm = session1.getWorkspace().getVersionManager();
  // Create node structure
  Node root = session1.getRootNode();
  Node area = root.addNode("tmp2", "nt:unstructured");
  Node outer = area.addNode("outerFolder");
  Node inner = outer.addNode("innerFolder");
  Node file = inner.addNode("testFile.dat");
  file.setProperty("jcr:mimeType", "text/plain");
  file.setProperty("jcr:data", "Original content");
  session1.save();
  file.addMixin("mix:versionable");
  // session.save();
  isVersionable(vm, file); // here's the problem
  session1.save();
  Version v1 = vm.checkin(file.getPath());
  assertThat(v1, is(notNullValue()));
  // System.out.println("Created version: " + v1);
  // ubgraph(root.getNode("jcr:system/jcr:versionStorage"));
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldFindMasterBranchAsPrimaryItemUnderTreeNode() throws Exception {
  Node git = gitRemoteNode();
  Node tree = git.getNode("tree");
  Item primaryItem = tree.getPrimaryItem();
  assertThat(primaryItem, is(notNullValue()));
  assertThat(primaryItem, is(instanceOf(Node.class)));
  Node primaryNode = (Node)primaryItem;
  assertThat(primaryNode.getName(), is("master"));
  assertThat(primaryNode.getParent(), is(sameInstance(tree)));
  assertThat(primaryNode, is(sameInstance(tree.getNode("master"))));
}

代码示例来源:origin: ModeShape/modeshape

protected static void importContent( Node parent,
                   String resourceName,
                   int uuidBehavior ) throws RepositoryException, IOException {
  InputStream stream = resourceStream(resourceName);
  assertThat(stream, is(notNullValue()));
  parent.getSession().getWorkspace().importXML(parent.getPath(), stream, uuidBehavior);
}

代码示例来源:origin: ModeShape/modeshape

@Test
public void shouldStartRepositoryUsingLocalEnvironmentWithDefaultPersistenceConfiguration() throws Exception {
  // Create the repository configuration ...
  String configFilePath = "config/repo-config-inmemory-no-persistence.json";
  InputStream configFileStream = getClass().getClassLoader().getResourceAsStream(configFilePath);
  RepositoryConfiguration repositoryConfiguration = RepositoryConfiguration.read(configFileStream, "doesn't matter");
  LocalEnvironment environment = new LocalEnvironment();
  repositoryConfiguration = repositoryConfiguration.with(environment);
  // Start the engine and repository ...
  ModeShapeEngine engine = new ModeShapeEngine();
  engine.start();
  try {
    JcrRepository repository = engine.deploy(repositoryConfiguration);
    Session session = repository.login();
    Node root = session.getRootNode();
    root.addNode("Library", "nt:folder");
    session.save();
    session.logout();
    session = repository.login();
    Node library = session.getNode("/Library");
    assertThat(library, is(notNullValue()));
    assertThat(library.getPrimaryNodeType().getName(), is("nt:folder"));
    session.logout();
  } finally {
    engine.shutdown().get();
    environment.shutdown();
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldSerializeMapWithSimpleTypes() throws Exception
{
  MapRepresentation rep = new MapRepresentation( map( "nulls", null, "strings", "a string", "numbers", 42,
      "booleans", true ) );
  OutputFormat format = new OutputFormat( new JsonFormat(), new URI( "http://localhost/" ), null );
  String serializedMap = format.assemble( rep );
  Map<String, Object> map = JsonHelper.jsonToMap( serializedMap );
  assertThat( map.get( "nulls" ), is( nullValue() ) );
  assertThat( map.get( "strings" ), is( "a string" ) );
  assertThat( map.get( "numbers" ), is( 42 ) );
  assertThat( map.get( "booleans" ), is( true ) );
}

代码示例来源:origin: mulesoft/mule

@Test
 public void testTransactionalState() throws Exception {
  boolean shouldThrowException = resultMap.get(hasTransactionInContext).get(transactionConfig);
  Exception thrownException = null;
  CoreEvent result = null;
  if (hasTransactionInContext) {
   TransactionCoordination.getInstance().bindTransaction(mockTransaction);
  }
  ValidateTransactionalStateInterceptor<CoreEvent> interceptor =
    new ValidateTransactionalStateInterceptor<>(new ExecuteCallbackInterceptor<CoreEvent>(),
                          transactionConfig, false);
  try {
   result = interceptor.execute(() -> mockMuleEvent, new ExecutionContext());
  } catch (IllegalTransactionStateException e) {
   thrownException = e;
  }
  if (shouldThrowException) {
   assertThat(thrownException, notNullValue());
   assertThat(thrownException, instanceOf(IllegalTransactionStateException.class));
  } else {
   assertThat(result, is(mockMuleEvent));
  }
 }
}

代码示例来源:origin: ModeShape/modeshape

@FixFor( "MODE-701" )
public void testShouldBeAbleToImportAutocreatedChildNodeWithoutDuplication() throws Exception {
  session = getHelper().getSuperuserSession();
  /*
  * Add a node that would satisfy the constraint
  */
  Node root = getTestRoot(session);
  Node parentNode = root.addNode("autocreatedChildRoot", "nt:unstructured");
  session.save();
  Node targetNode = parentNode.addNode("nodeWithAutocreatedChild", "modetest:nodeWithAutocreatedChild");
  assertThat(targetNode.getNode("modetest:autocreatedChild"), is(notNullValue()));
  // Don't save this yet
  session.refresh(false);
  InputStream in = getClass().getResourceAsStream("/io/autocreated-node-test.xml");
  session.importXML(root.getPath() + "/autocreatedChildRoot", in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
}

代码示例来源:origin: ehcache/ehcache3

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRemoveAllWithWriterException() throws Exception {
 doAnswer(invocation -> {
  Iterable<Integer> iterable = (Iterable) invocation.getArguments()[0];
  Set<Integer> result = new HashSet<>();
  fail("expected CacheWritingException");
 } catch (BulkCacheWritingException ex) {
  assertThat(ex.getFailures().size(), is(1));
  assertThat(ex.getFailures().get(2), is(notNullValue()));
  assertThat(ex.getSuccesses().size(), is(3));
  assertThat(ex.getSuccesses().containsAll(Arrays.asList(1, 3, 4)), is(true));

相关文章