Java Code Examples for org.assertj.core.api.Assertions#fail()

The following examples show how to use org.assertj.core.api.Assertions#fail() . 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 File: MarshallingCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeNonSerializable() throws IOException {
    MarshallingCodec m = new MarshallingCodec();
    try {
        ByteBuf t = m.getValueEncoder().encode(new NonSerializable());
        Assertions.fail("Exception should be thrown");
    } catch (Exception e) {
        // skip
    }
    ByteBuf d = m.getValueEncoder().encode("test");
    Object s = m.getValueDecoder().decode(d, null);
    Assertions.assertThat(s).isEqualTo("test");
}
 
Example 2
Source File: CollectionAssertTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_throw_an_exception_when_collection_is_null_for_greater_than_or_equal() {
	Collection collection = null;

	try {
		SpringCloudContractAssertions.assertThat(collection)
				.hasSizeGreaterThanOrEqualTo(1);
		Assertions.fail("should throw exception");
	}
	catch (AssertionError e) {
		Assertions.assertThat(e)
				.hasMessageContaining("Expecting actual not to be null");
	}
}
 
Example 3
Source File: CollectionAssertTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_throw_an_exception_when_element_is_null() {
	Collection collection = collectionWithNulls();

	try {
		SpringCloudContractAssertions.assertThat(collection)
				.allElementsMatch("[0-9]");
		Assertions.fail("should throw exception");
	}
	catch (AssertionError e) {
		Assertions.assertThat(e).hasMessageContaining(
				"The value <null> doesn't match the regex <[0-9]>");
	}
}
 
Example 4
Source File: CollectionAssertTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_throw_an_exception_when_collection_is_null_for_flattened_less_than_or_equal() {
	Collection collection = null;

	try {
		SpringCloudContractAssertions.assertThat(collection)
				.hasFlattenedSizeLessThanOrEqualTo(1);
		Assertions.fail("should throw exception");
	}
	catch (AssertionError e) {
		Assertions.assertThat(e)
				.hasMessageContaining("Expecting actual not to be null");
	}
}
 
Example 5
Source File: FuchsiaHelper.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
/**
 * Create an instance with the given factory and properties.
 *
 * @param factory
 * @param properties
 * @return
 */
public static ComponentInstance createInstance(final Factory factory, final Dictionary<String, Object> properties) {
    ComponentInstance instance = null;

    // Create an instance
    try {
        instance = factory.createComponentInstance(properties);
    } catch (Exception e) {
        Assertions.fail("Creation of instance failed (" + factory +
                ", " + properties + ").", e);
    }
    return instance;
}
 
Example 6
Source File: SequenceEncodersTest.java    From morfologik-stemming with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void assertRoundtripEncode(String srcString, String dstString) {
    ByteBuffer source = ByteBuffer.wrap(srcString.getBytes(UTF8));
    ByteBuffer target = ByteBuffer.wrap(dstString.getBytes(UTF8));

    ByteBuffer encoded = coder.encode(ByteBuffer.allocate(randomInt(30)), source, target);
    ByteBuffer decoded = coder.decode(ByteBuffer.allocate(randomInt(30)), source, encoded);

    if (!decoded.equals(target)) {
        System.out.println("src: " + BufferUtils.toString(source, StandardCharsets.UTF_8));
        System.out.println("dst: " + BufferUtils.toString(target, StandardCharsets.UTF_8));
        System.out.println("enc: " + BufferUtils.toString(encoded, StandardCharsets.UTF_8));
        System.out.println("dec: " + BufferUtils.toString(decoded, StandardCharsets.UTF_8));
        Assertions.fail("Mismatch.");
    }
}
 
Example 7
Source File: CollectionAssertTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_throw_an_exception_when_size_is_not_greater_than_or_equal_to_provided_size() {
	Collection collection = collection();

	try {
		SpringCloudContractAssertions.assertThat(collection)
				.hasSizeGreaterThanOrEqualTo(5);
		Assertions.fail("should throw exception");
	}
	catch (AssertionError e) {
		Assertions.assertThat(e)
				.hasMessageContaining("The size <3> is not greater or equal to <5>");
	}
}
 
Example 8
Source File: AccessTokenBuilderTest.java    From tokens with Apache License 2.0 5 votes vote down vote up
@Test
public void notAnUri_OAUTH2_ACCESS_TOKEN_URL() {
    environmentVariables.set("OAUTH2_ACCESS_TOKEN_URL", "::::");
    try {
        Tokens.createAccessTokens();
        Assertions.fail("Not expected to reach this point");
    } catch (Exception e) {
        assertThat(e.getMessage())
                .contains("environment variable OAUTH2_ACCESS_TOKEN_URL cannot be converted to an URI");
    }
}
 
Example 9
Source File: BusProtoStuffMessageConverterTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Verifies that a MessageConversationException is thrown on missing event-type information encoding")
public void missingEventTypeMappingThrowsMessageConversationException() {
    final DummyRemoteEntityEvent dummyEvent = new DummyRemoteEntityEvent(targetMock, "applicationId");
    try {
        underTest.convertToInternal(dummyEvent, new MessageHeaders(new HashMap<>()), null);
        Assertions.fail("Missing MessageConversationException for un-defined event-type");
    } catch (final MessageConversionException e) {
        // expected exception
    }
}
 
Example 10
Source File: SchemaController.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private String readFile(String restController) {
  // test code, make simple
  try {
    InputStream inputStream = this.getClass().getResource("/" + restController).openStream();
    byte[] buffer = new byte[2048 * 10];
    int len = inputStream.read(buffer);
    assertThat(len).isLessThan(2048 * 10);
    inputStream.close();
    return new String(buffer, 0, len, Charset.forName("UTF-8"));
  } catch (IOException e) {
    Assertions.fail(e.getMessage());
    return null;
  }
}
 
Example 11
Source File: DatabaseCleanupTaskTest.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Make sure the trigger returned is accurate.
 */
@Test
void canGetTrigger() {
    final String expression = "0 0 1 * * *";
    this.environment.setProperty(DatabaseCleanupProperties.EXPRESSION_PROPERTY, expression);
    Mockito.when(this.cleanupProperties.getExpression()).thenReturn("0 0 0 * * *");
    final Trigger trigger = this.task.getTrigger();
    if (trigger instanceof CronTrigger) {
        final CronTrigger cronTrigger = (CronTrigger) trigger;
        Assertions.assertThat(cronTrigger.getExpression()).isEqualTo(expression);
    } else {
        Assertions.fail("Trigger was not of expected type: " + CronTrigger.class.getName());
    }
}
 
Example 12
Source File: AgentConnectionEntityTest.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Verify validated fields value.
 */
@Test
void cantCreateAgentConnectionEntityDueToSize() {

    final List<Pair<String, String>> invalidParameterPairs = Lists.newArrayList();

    invalidParameterPairs.add(Pair.of(JOB, null));
    invalidParameterPairs.add(Pair.of(null, HOST));
    invalidParameterPairs.add(Pair.of(JOB, " "));
    invalidParameterPairs.add(Pair.of(" ", HOST));
    invalidParameterPairs.add(Pair.of(StringUtils.rightPad(JOB, 256), HOST));
    invalidParameterPairs.add(Pair.of(JOB, StringUtils.rightPad(HOST, 256)));

    for (final Pair<String, String> invalidParameters : invalidParameterPairs) {
        final AgentConnectionEntity entity =
            new AgentConnectionEntity(invalidParameters.getLeft(), invalidParameters.getRight());

        try {
            this.validate(entity);
        } catch (final ConstraintViolationException e) {
            // Expected, move on to the next pair.
            continue;
        }

        Assertions.fail("Entity unexpectedly passed validation: " + entity.toString());
    }
}
 
Example 13
Source File: CollectionAssertTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_throw_an_exception_when_size_is_not_less_than_or_equal_to_provided_size() {
	Collection collection = collection();

	try {
		SpringCloudContractAssertions.assertThat(collection)
				.hasSizeLessThanOrEqualTo(1);
		Assertions.fail("should throw exception");
	}
	catch (AssertionError e) {
		Assertions.assertThat(e)
				.hasMessageContaining("The size <3> is not less or equal to <1>");
	}
}
 
Example 14
Source File: CollectionAssertTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_throw_an_exception_when_collection_is_null_for_between() {
	Collection collection = null;

	try {
		SpringCloudContractAssertions.assertThat(collection).hasSizeBetween(1, 2);
		Assertions.fail("should throw exception");
	}
	catch (AssertionError e) {
		Assertions.assertThat(e)
				.hasMessageContaining("Expecting actual not to be null");
	}
}
 
Example 15
Source File: NetworkingServiceLifecycleTest.java    From besu with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void createP2PNetwork_InvalidPort() throws IOException {
  final NetworkingConfiguration config =
      NetworkingConfiguration.create()
          .setDiscovery(DiscoveryConfiguration.create().setBindPort(-1));
  try (final P2PNetwork broken = builder().config(config).build()) {
    Assertions.fail("Expected Exception");
  }
}
 
Example 16
Source File: NetworkingServiceLifecycleTest.java    From besu with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void createP2PNetwork_InvalidHost() throws IOException {
  final NetworkingConfiguration config =
      NetworkingConfiguration.create()
          .setDiscovery(DiscoveryConfiguration.create().setBindHost("fake.fake.fake"));
  try (final P2PNetwork broken = builder().config(config).build()) {
    Assertions.fail("Expected Exception");
  }
}
 
Example 17
Source File: CollectionAssertTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void should_throw_an_exception_when_flattened_size_is_not_less_than_or_equal_to_provided_size() {
	Collection collection = nestedCollection();

	try {
		SpringCloudContractAssertions.assertThat(collection)
				.hasFlattenedSizeLessThanOrEqualTo(1);
		Assertions.fail("should throw exception");
	}
	catch (AssertionError e) {
		Assertions.assertThat(e).hasMessageContaining(
				"The flattened size <7> is not less or equal to <1>");
	}
}
 
Example 18
Source File: AccessTokenBuilderTest.java    From tokens with Apache License 2.0 5 votes vote down vote up
@Test
public void noEnvironmentSet() {
    try {
        Tokens.createAccessTokens();
        Assertions.fail("Not expected to reach this point");
    } catch (Exception e) {
        assertThat(e.getMessage()).contains("environment variable OAUTH2_ACCESS_TOKEN_URL not set");
    } finally {
        System.getProperties().remove("OAUTH2_ACCESS_TOKEN_URL");
    }
}
 
Example 19
Source File: MultithreadTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
@Disabled
public void testConcurrencyWithChronThreads() throws InterruptedException {

    final String drl = "package it.intext.drools.fusion.bug;\n" +
            "\n" +
            "import " + MyFact.class.getCanonicalName() + ";\n " +
            " global java.util.List list; \n" +
            "\n" +
            "declare MyFact\n" +
            "\t@role( event )\n" +
            "\t@expires( 1s )\n" +
            "end\n" +
            "\n" +
            "rule \"Dummy\"\n" +
            "timer( cron: 0/1 * * * * ? )\n" +
            "when\n" +
            "  Number( $count : intValue ) from accumulate( MyFact( ) over window:time(1s); sum(1) )\n" +
            "then\n" +
            "    System.out.println($count+\" myfact(s) seen in the last 1 seconds\");\n" +
            "    list.add( $count ); \n" +
            "end";

    final KieBaseConfiguration kbconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kbconfig.setOption(EventProcessingOption.STREAM);

    final KieBase kbase = loadKnowledgeBaseFromString(kbconfig, drl);

    final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(ClockTypeOption.get("REALTIME"));
    final KieSession ksession = kbase.newKieSession(conf, null);

    final List list = new ArrayList();
    ksession.setGlobal("list", list);

    ksession.fireAllRules();

    final Runner t = new Runner(ksession);
    t.start();
    try {
        final int FACTS_PER_POLL = 1000;
        final int POLL_INTERVAL = 500;

        final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        try {
            executor.scheduleAtFixedRate(
                    () -> {
                        for (int j = 0; j < FACTS_PER_POLL; j++) {
                            ksession.insert(new MyFact());
                        }
                    },
                    0,
                    POLL_INTERVAL,
                    TimeUnit.MILLISECONDS);

            Thread.sleep(10200);
        } finally {
            executor.shutdownNow();
        }
    } finally {
        ksession.halt();
        ksession.dispose();
    }

    t.join();

    if (t.getError() != null) {
        Assertions.fail(t.getError().getMessage());
    }

    System.out.println("Final size " + ksession.getObjects().size());

    ksession.dispose();
}
 
Example 20
Source File: CommonG.java    From bdt with Apache License 2.0 4 votes vote down vote up
/**
 * Generate deployment json from schema
 *
 * @param schema schema obtained from deploy-api
 * @return JSONObject   deployment json
 */
public JSONObject parseJSONSchema(JSONObject schema) throws Exception {
    JSONObject json = new JSONObject();
    String name = "";
    JSONObject properties = schema;

    // Check if key 'properties' exists
    if (schema.has("properties")) {
        // Obtain properties
        properties = schema.getJSONObject("properties");
    }

    // Obtain all keys and iterate through them
    Iterator<?> keys = properties.keys();
    while (keys.hasNext()) {
        // Obtain key
        String key = keys.next().toString();
        // Obtain value of key
        JSONObject element = properties.getJSONObject(key);
        // Check if value contain properties
        // If it DOESN'T CONTAIN properties
        if (!element.has("properties")) {
            // Check if it has default value
            if (element.has("default")) {
                // Add element with the default value assigned
                json.put(key, element.get("default"));
                // If it doesn't have default value, we assign a default value depending on the type
            } else {
                switch (element.getString("type")) {
                    case "string":
                        json.put(key, "");
                        break;
                    case "boolean":
                        json.put(key, false);
                        break;
                    case "number":
                    case "integer":
                        json.put(key, 0);
                        break;
                    default:
                        Assertions.fail("type not expected");
                }
            }
            // If it CONTAINS properties
        } else {
            // Recursive call, keep evaluating json
            json.put(key, parseJSONSchema(element));
        }
    }

    return json;
}