org.hamcrest.core.IsNot Java Examples

The following examples show how to use org.hamcrest.core.IsNot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: cactoos-http   Author: yegor256   File: CloseableInputStreamTest.java    License: MIT License 6 votes vote down vote up
@Test
public void doesNotCloseTheStream() throws Exception {
    final CloseableInputStream closeable = new CloseableInputStream(
        new DeadInputStream()
    );
    new Assertion<>(
        "must not be marked as closed before close is called",
        closeable.wasClosed(),
        new IsNot<>(new IsTrue())
    ).affirm();
    closeable.close();
    new Assertion<>(
        "must be marked as closed after close is called",
        closeable.wasClosed(),
        new IsTrue()
    ).affirm();
}
 
Example #2
Source Project: lucene-solr   Author: apache   File: BaseTestRuleBasedAuthorizationPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAllPermissionDeniesActionsWhenUserIsNotCorrectRole() {
  SolrRequestHandler handler = new UpdateRequestHandler();
  assertThat(handler, new IsInstanceOf(PermissionNameProvider.class));
  setUserRole("dev", "dev");
  setUserRole("admin", "admin");
  addPermission("all", "admin");
  checkRules(makeMap("resource", "/update",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", new UpdateRequestHandler(),
      "params", new MapSolrParams(singletonMap("key", "VAL2")))
      , FORBIDDEN);

  handler = new PropertiesRequestHandler();
  assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class)));
  checkRules(makeMap("resource", "/admin/info/properties",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", handler,
      "params", new MapSolrParams(emptyMap()))
      , FORBIDDEN);
}
 
Example #3
Source Project: ehcache3   Author: ehcache   File: ConfigurationDerivation.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void withServiceCreation() {
  Configuration configuration = ConfigurationBuilder.newConfigurationBuilder()
    .withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
    .build();

  //tag::withServiceCreation[]
  Configuration withBoundedThreads = configuration.derive()
    .withService(new PooledExecutionServiceConfiguration()
      .addDefaultPool("default", 1, 16))
    .build();
  //end::withServiceCreation[]

  Assert.assertThat(configuration.getServiceCreationConfigurations(), IsNot.not(IsCollectionContaining.hasItem(IsInstanceOf.instanceOf(PooledExecutionServiceConfiguration.class))));
  PooledExecutionServiceConfiguration serviceCreationConfiguration = ServiceUtils.findSingletonAmongst(PooledExecutionServiceConfiguration.class, withBoundedThreads.getServiceCreationConfigurations());
  Assert.assertThat(serviceCreationConfiguration.getDefaultPoolAlias(), Is.is("default"));
  Assert.assertThat(serviceCreationConfiguration.getPoolConfigurations().keySet(), IsIterableContainingInAnyOrder.containsInAnyOrder("default"));
  PooledExecutionServiceConfiguration.PoolConfiguration pool = serviceCreationConfiguration.getPoolConfigurations().get("default");
  Assert.assertThat(pool.minSize(), Is.is(1));
  Assert.assertThat(pool.maxSize(), Is.is(16));
}
 
Example #4
Source Project: symbol-sdk-java   Author: nemtech   File: Ed25519EncodedFieldElementTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void hashCodesAreEqualForEquivalentObjects() {
    // Arrange:
    final Ed25519EncodedFieldElement encoded1 = MathUtils.getRandomEncodedFieldElement(32);
    final Ed25519EncodedFieldElement encoded2 = encoded1.decode().encode();
    final Ed25519EncodedFieldElement encoded3 = MathUtils.getRandomEncodedFieldElement(32);
    final Ed25519EncodedFieldElement encoded4 = MathUtils.getRandomEncodedFieldElement(32);

    // Assert:
    MatcherAssert.assertThat(encoded1.hashCode(), IsEqual.equalTo(encoded2.hashCode()));
    MatcherAssert
        .assertThat(encoded1.hashCode(), IsNot.not(IsEqual.equalTo(encoded3.hashCode())));
    MatcherAssert
        .assertThat(encoded1.hashCode(), IsNot.not(IsEqual.equalTo(encoded4.hashCode())));
    MatcherAssert
        .assertThat(encoded3.hashCode(), IsNot.not(IsEqual.equalTo(encoded4.hashCode())));
}
 
Example #5
Source Project: symbol-sdk-java   Author: nemtech   File: Ed25519GroupElementTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void equalsOnlyReturnsTrueForEquivalentObjects() {
    // Arrange:
    final Ed25519GroupElement g1 = MathUtils.getRandomGroupElement();
    final Ed25519GroupElement g2 = MathUtils.toRepresentation(g1, CoordinateSystem.P2);
    final Ed25519GroupElement g3 = MathUtils.toRepresentation(g1, CoordinateSystem.CACHED);
    final Ed25519GroupElement g4 = MathUtils.toRepresentation(g1, CoordinateSystem.P1xP1);
    final Ed25519GroupElement g5 = MathUtils.getRandomGroupElement();

    // Assert
    MatcherAssert.assertThat(g2, IsEqual.equalTo(g1));
    MatcherAssert.assertThat(g3, IsEqual.equalTo(g1));
    MatcherAssert.assertThat(g1, IsEqual.equalTo(g4));
    MatcherAssert.assertThat(g1, IsNot.not(IsEqual.equalTo(g5)));
    MatcherAssert.assertThat(g2, IsNot.not(IsEqual.equalTo(g5)));
    MatcherAssert.assertThat(g3, IsNot.not(IsEqual.equalTo(g5)));
    MatcherAssert.assertThat(g5, IsNot.not(IsEqual.equalTo(g4)));
}
 
Example #6
Source Project: cactoos   Author: yegor256   File: PropertiesOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void sensesChangesInMap() throws Exception {
    final AtomicInteger size = new AtomicInteger(2);
    final PropertiesOf props = new PropertiesOf(
        new MapOf<>(
            () -> new Repeated<>(
                size.incrementAndGet(), () -> new MapEntry<>(
                    new SecureRandom().nextInt(),
                    1
                )
            )
        )
    );
    new Assertion<>(
        "Must sense the changes in the underlying map",
        props.value().size(),
        new IsNot<>(new IsEqual<>(props.value().size()))
    ).affirm();
}
 
Example #7
Source Project: jpeek   Author: yegor256   File: FuturesTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testSimpleScenario() throws Exception {
    new Assertion<>(
        "Futures returns Response",
        new Futures(
            (artifact, group) -> input -> new RsPage(
                new RqFake(),
                "wait",
                () -> new IterableOf<>(
                    new XeAppend("group", group),
                    new XeAppend("artifact", artifact)
                )
            )
        ).apply("a", "g").get().apply("test"),
        new IsNot<>(new IsEqual<>(null))
    ).affirm();
}
 
Example #8
Source Project: lucene-solr   Author: apache   File: BaseTestRuleBasedAuthorizationPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAllPermissionAllowsActionsWhenUserHasCorrectRole() {
  SolrRequestHandler handler = new UpdateRequestHandler();
  assertThat(handler, new IsInstanceOf(PermissionNameProvider.class));
  setUserRole("dev", "dev");
  setUserRole("admin", "admin");
  addPermission("all", "dev", "admin");
  checkRules(makeMap("resource", "/update",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", handler,
      "params", new MapSolrParams(singletonMap("key", "VAL2")))
      , STATUS_OK);

  handler = new PropertiesRequestHandler();
  assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class)));
  checkRules(makeMap("resource", "/admin/info/properties",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", handler,
      "params", new MapSolrParams(emptyMap()))
      , STATUS_OK);
}
 
Example #9
Source Project: symbol-sdk-java   Author: nemtech   File: BlockCipherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void encryptedDataCanBeDecrypted() {
    // Arrange:
    final CryptoEngine engine = this.getCryptoEngine();
    final KeyPair kp = KeyPair.random(engine);
    final BlockCipher blockCipher = this.getBlockCipher(kp, kp);
    final byte[] input = RandomUtils.generateRandomBytes();

    // Act:
    final byte[] encryptedBytes = blockCipher.encrypt(input);
    final byte[] decryptedBytes = blockCipher.decrypt(encryptedBytes);

    // Assert:
    MatcherAssert.assertThat(encryptedBytes, IsNot.not(IsEqual.equalTo(decryptedBytes)));
    MatcherAssert.assertThat(decryptedBytes, IsEqual.equalTo(input));
}
 
Example #10
Source Project: symbol-sdk-java   Author: nemtech   File: BlockCipherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void dataCanBeEncryptedWithSenderPrivateKeyAndRecipientPublicKey() {
    // Arrange:
    final CryptoEngine engine = this.getCryptoEngine();
    final KeyPair skp = KeyPair.random(engine);
    final KeyPair rkp = KeyPair.random(engine);
    final BlockCipher blockCipher =
        this.getBlockCipher(skp, KeyPair.onlyPublic(rkp.getPublicKey(), engine));
    final byte[] input = RandomUtils.generateRandomBytes();

    // Act:
    final byte[] encryptedBytes = blockCipher.encrypt(input);

    // Assert:
    MatcherAssert.assertThat(encryptedBytes, IsNot.not(IsEqual.equalTo(input)));
}
 
Example #11
Source Project: symbol-sdk-java   Author: nemtech   File: BlockCipherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void dataEncryptedWithPrivateKeyCanOnlyBeDecryptedByMatchingPublicKey(
) {
    // Arrange:
    final CryptoEngine engine = this.getCryptoEngine();
    final BlockCipher blockCipher1 =
        this.getBlockCipher(KeyPair.random(engine), KeyPair.random(engine));
    final BlockCipher blockCipher2 =
        this.getBlockCipher(KeyPair.random(engine), KeyPair.random(engine));
    final byte[] input = RandomUtils.generateRandomBytes();

    // Act:
    final byte[] encryptedBytes1 = blockCipher1.encrypt(input);
    final byte[] encryptedBytes2 = blockCipher2.encrypt(input);

    // Assert:
    MatcherAssert.assertThat(blockCipher1.decrypt(encryptedBytes1), IsEqual.equalTo(input));
    MatcherAssert
        .assertThat(blockCipher1.decrypt(encryptedBytes2), IsNot.not(IsEqual.equalTo(input)));
    MatcherAssert
        .assertThat(blockCipher2.decrypt(encryptedBytes1), IsNot.not(IsEqual.equalTo(input)));
    MatcherAssert.assertThat(blockCipher2.decrypt(encryptedBytes2), IsEqual.equalTo(input));
}
 
Example #12
Source Project: ehcache3   Author: ehcache   File: ConfigurationDerivation.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void withService() {
  Configuration configuration = ConfigurationBuilder.newConfigurationBuilder()
    .withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
    .build();

  //tag::withService[]
  Configuration withThrowingStrategy = configuration.derive()
    .updateCache("cache", existing -> existing.withService(
      new DefaultResilienceStrategyConfiguration(new ThrowingResilienceStrategy<>())
    ))
    .build();
  //end::withService[]


  Assert.assertThat(configuration.getServiceCreationConfigurations(), IsNot.not(IsCollectionContaining.hasItem(
    IsInstanceOf.instanceOf(DefaultResilienceStrategyConfiguration.class))));

  DefaultResilienceStrategyConfiguration resilienceStrategyConfiguration =
    ServiceUtils.findSingletonAmongst(DefaultResilienceStrategyConfiguration.class,
      withThrowingStrategy.getCacheConfigurations().get("cache").getServiceConfigurations());
  Assert.assertThat(resilienceStrategyConfiguration.getInstance(), IsInstanceOf.instanceOf(ThrowingResilienceStrategy.class));
}
 
Example #13
Source Project: cactoos   Author: yegor256   File: MapOfTest.java    License: MIT License 6 votes vote down vote up
@Test
public void sensesChangesInMap() throws Exception {
    final AtomicInteger size = new AtomicInteger(2);
    final Map<Integer, Integer> map = new MapOf<>(
        () -> new Repeated<>(
            size.incrementAndGet(), () -> new MapEntry<>(
                new SecureRandom().nextInt(),
                1
            )
        )
    );
    MatcherAssert.assertThat(
        "Can't sense the changes in the underlying map",
        map.size(),
        new IsNot<>(new IsEqual<>(map.size()))
    );
}
 
Example #14
Source Project: arctic-sea   Author: 52North   File: UVFEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotEncodeUnitOfMeasurementForCountObservations() throws EncodingException, NoSuchElementException, OwsExceptionReport {
    OmObservation omObservation = responseToEncode.getObservationCollection().next();
    omObservation.getObservationConstellation().
            setObservationType(OmConstants.OBS_TYPE_COUNT_OBSERVATION);
    Time phenTime = new TimeInstant(new Date(UTC_TIMESTAMP_1));
    omObservation.setValue(new SingleObservationValue<>(phenTime,
            new CountValue(52)));
    ((OmObservableProperty)omObservation.getObservationConstellation()
            .getObservableProperty()).setUnit(null);
    responseToEncode.setObservationCollection(ObservationStream.of(omObservation));

    final String[] actual = getResponseString();
    final String expected = "$sb Mess-Einheit: " + unit;

    assertThat(Arrays.asList(actual), IsNot.not(CoreMatchers.hasItems(expected)));
}
 
Example #15
Source Project: jpeek   Author: yegor256   File: FuturesTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testIgnoresCrashes() throws Exception {
    new Assertion<>(
        "Futures don't crash",
        new Futures(
            (artifact, group) -> {
                throw new UnsupportedOperationException("intended");
            }
        ).apply("a1", "g1").get().apply("test-2"),
        new IsNot<>(new IsEqual<>(null))
    ).affirm();
}
 
Example #16
Source Project: vividus   Author: vividus-framework   File: StringComparisonRuleTests.java    License: Apache License 2.0 5 votes vote down vote up
static Stream<Arguments> dataProvider()
{
    // @formatter:off
    return Stream.of(
        Arguments.of(StringComparisonRule.IS_EQUAL_TO,      IsEqual.class),
        Arguments.of(StringComparisonRule.CONTAINS,         StringContains.class),
        Arguments.of(StringComparisonRule.DOES_NOT_CONTAIN, IsNot.class),
        Arguments.of(StringComparisonRule.MATCHES,          StringRegularExpression.class)
    );
    // @formatter:on
}
 
Example #17
Source Project: verano-http   Author: Vatavuk   File: XmlBodyOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void extractsJsonObjectFromDict() {
    MatcherAssert.assertThat(
        new XmlBody.Of(
            new HashDict(
                new KvpOf("body", "<test/>"),
                new KvpOf("unknown", "")
            )
        ).xml(),
        new IsNot<>(new IsNull<>())
    );
}
 
Example #18
Source Project: verano-http   Author: Vatavuk   File: HtmlBodyOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void extractsHtmlBodyFromDict() {
    MatcherAssert.assertThat(
        new HtmlBody.Of(
            new HashDict(
                new KvpOf("body", "<html></html>"),
                new KvpOf("unknown", "")
            )
        ).html().html(),
        new IsNot<>(new IsNull<>())
    );
}
 
Example #19
Source Project: takes   Author: yegor256   File: HmRsTextBodyTest.java    License: MIT License 5 votes vote down vote up
/**
 * HmRsTextBody can test if body doesn't equal to text.
 */
@Test
public void testsBodyValueDoesNotContainsText() {
    MatcherAssert.assertThat(
        new RsWithBody("Some response"),
        new IsNot<>(new HmRsTextBody("expected something else"))
    );
}
 
Example #20
Source Project: verano-http   Author: Vatavuk   File: JsonBodyOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void extractsJsonArrayFromDict() {
    MatcherAssert.assertThat(
        new JsonBody.Of(
            new HashDict(
                new KvpOf("body", "[]"),
                new KvpOf("unknown", "")
            )
        ).jsonArray(),
        new IsNot<>(new IsNull<>())
    );
}
 
Example #21
Source Project: takes   Author: yegor256   File: HmRqTextBodyTest.java    License: MIT License 5 votes vote down vote up
/**
 * HmRqTextBody can test if body doesn't equal to text.
 */
@Test
public void testsBodyValueDoesNotContainsText() {
    MatcherAssert.assertThat(
        new RqFake(
            Collections.<String>emptyList(),
            "some"
        ),
        new IsNot<>(new HmRqTextBody("other"))
    );
}
 
Example #22
Source Project: verano-http   Author: Vatavuk   File: SslTrustedTest.java    License: MIT License 5 votes vote down vote up
@Test
public void appendsSslTrustedToClient() {
    final HttpClientBuilder builder = HttpClients.custom();
    MatcherAssert.assertThat(
        new SslTrusted().apply(builder),
        new IsEqual<>(builder)
    );
    MatcherAssert.assertThat(
        builder.build(),
        new IsNot<>(new IsNull<>())
    );
}
 
Example #23
Source Project: verano-http   Author: Vatavuk   File: ProxyTest.java    License: MIT License 5 votes vote down vote up
@Test
public void appendsProxyToClient() {
    final HttpClientBuilder builder = HttpClients.custom();
    MatcherAssert.assertThat(
        new Proxy("localhost", 8080).apply(builder),
        new IsEqual<>(builder)
    );
    MatcherAssert.assertThat(
        builder.build(),
        new IsNot<>(new IsNull<>())
    );
}
 
Example #24
Source Project: cactoos   Author: yegor256   File: IterableOfTest.java    License: MIT License 5 votes vote down vote up
@Test
public void isNotEqualsToIterableWithMoreElements() {
    new Assertion<>(
        "Must compare iterables and second one is bigger",
        new IterableOf<>("a", "b").equals(new IterableOf<>("a")),
        new IsNot<>(new IsTrue())
    ).affirm();
}
 
Example #25
Source Project: symbol-sdk-java   Author: nemtech   File: ColumnVectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void scalarCanBeAddedToVector() {
    // Arrange:
    final ColumnVector a = new ColumnVector(2, -4, 1);

    // Act:
    final ColumnVector result = a.add(8);

    // Assert:
    MatcherAssert.assertThat(result, IsNot.not(IsEqual.equalTo(a)));
    MatcherAssert.assertThat(result, IsEqual.equalTo(new ColumnVector(10, 4, 9)));
}
 
Example #26
Source Project: symbol-sdk-java   Author: nemtech   File: ColumnVectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void twoVectorsOfSameSizeCanBeAddedTogetherElementWise() {
    // Arrange:
    final ColumnVector a = new ColumnVector(7, 5, 11);
    final ColumnVector b = new ColumnVector(2, -4, 1);

    // Act:
    final ColumnVector result = a.addElementWise(b);

    // Assert:
    MatcherAssert.assertThat(result, IsNot.not(IsEqual.equalTo(a)));
    MatcherAssert.assertThat(result, IsNot.not(IsEqual.equalTo(b)));
    MatcherAssert.assertThat(result, IsEqual.equalTo(new ColumnVector(9, 1, 12)));
}
 
Example #27
Source Project: symbol-sdk-java   Author: nemtech   File: ColumnVectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void vectorCanBeMultipliedByScalar() {
    // Arrange:
    final ColumnVector a = new ColumnVector(2, -4, 1);

    // Act:
    final ColumnVector result = a.multiply(8);

    // Assert:
    MatcherAssert.assertThat(result, IsNot.not(IsEqual.equalTo(a)));
    MatcherAssert.assertThat(result, IsEqual.equalTo(new ColumnVector(16, -32, 8)));
}
 
Example #28
Source Project: symbol-sdk-java   Author: nemtech   File: ColumnVectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void vectorCanBeMultipliedByVectorElementWise() {
    // Arrange:
    final ColumnVector v1 = new ColumnVector(3, 7, 2);
    final ColumnVector v2 = new ColumnVector(1, 5, 3);

    // Act:
    final ColumnVector result = v1.multiplyElementWise(v2);

    // Assert:
    MatcherAssert.assertThat(result, IsNot.not(IsEqual.equalTo(v1)));
    MatcherAssert.assertThat(result, IsNot.not(IsEqual.equalTo(v2)));
    MatcherAssert.assertThat(result, IsEqual.equalTo(new ColumnVector(3, 35, 6)));
}
 
Example #29
Source Project: symbol-sdk-java   Author: nemtech   File: ColumnVectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void vectorAbsoluteValueCanBeTaken() {
    // Arrange:
    final ColumnVector vector = new ColumnVector(12.4, -2.1, 7);

    // Act:
    final ColumnVector result = vector.abs();

    // Assert:
    MatcherAssert.assertThat(result, IsNot.not(IsEqual.equalTo(vector)));
    MatcherAssert.assertThat(result, IsEqual.equalTo(new ColumnVector(12.4, 2.1, 7)));
}
 
Example #30
Source Project: symbol-sdk-java   Author: nemtech   File: ColumnVectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void equalsOnlyReturnsTrueForEquivalentObjects() {
    // Arrange:
    final ColumnVector vector = new ColumnVector(2, -4, 1);

    // Assert:
    MatcherAssert.assertThat(new ColumnVector(2, -4, 1), IsEqual.equalTo(vector));
    MatcherAssert.assertThat(new ColumnVector(1, -4, 1), IsNot.not(IsEqual.equalTo(vector)));
    MatcherAssert.assertThat(new ColumnVector(2, 8, 1), IsNot.not(IsEqual.equalTo(vector)));
    MatcherAssert.assertThat(new ColumnVector(2, -4, 2), IsNot.not(IsEqual.equalTo(vector)));
    MatcherAssert.assertThat(null, IsNot.not(IsEqual.equalTo(vector)));
    MatcherAssert.assertThat(new double[]{2, -4, 1}, IsNot.not(IsEqual.equalTo(vector)));
}