org.testng.Assert#expectThrows ( )源码实例Demo

下面列出了org.testng.Assert#expectThrows ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JMPQ3   文件: MpqTests.java
@Test
public void testDuplicatePaths() throws IOException {
    File[] mpqs = getMpqs();
    for (File mpq : mpqs) {
        if (mpq.getName().equals("invalidHashSize.scx_copy")) {
            continue;
        }
        try (JMpqEditor mpqEditor = new JMpqEditor(mpq, MPQOpenOption.FORCE_V0)) {
            if (!mpqEditor.isCanWrite()) {
                return;
            }
            mpqEditor.insertByteArray("Test", "bytesasdadasdad".getBytes());
            Assert.expectThrows(IllegalArgumentException.class, () -> {
                mpqEditor.insertByteArray("Test", "bytesasdadasdad".getBytes());
            });
            Assert.expectThrows(IllegalArgumentException.class, () -> {
                mpqEditor.insertByteArray("teST", "bytesasdadasdad".getBytes());
            });
            mpqEditor.insertByteArray("teST", "bytesasdadasdad".getBytes(), true);
        }
    }
}
 
@Test()
public void testRequirePythonEnvironment() {
    // This test is deliberately left out of the "python" test group in order to ensure that
    // it only executes when the Python environment has *NOT* been properly established. Also,
    // skip this test if we're running on the Docker because the Python environment is always
    // activated there.
    if (isGATKDockerContainer()) {
        throw new SkipException("Python environment validation test must be skipped when running on the Docker");
    }

    // validate that we throw if the GATK Python environment is not active
    final RuntimeException rte = Assert.expectThrows(RuntimeException.class, ()-> {
        final StreamingPythonScriptExecutor<String> streamingPythonExecutor =
                new StreamingPythonScriptExecutor<>(PythonScriptExecutor.PythonExecutableName.PYTHON3, true);
        streamingPythonExecutor.start(Collections.emptyList());
    });

    // make sure that the underlying cause is actually a PythonScriptExecutorException
    Assert.assertEquals(rte.getCause().getClass(), PythonScriptExecutorException.class);
}
 
@Test
public void testTimeoutExceptionShouldBeThrownIfConditionIsNotMetAndDefaultTimeoutIsOver() {
    Timer timer = new Timer();
    Assert.expectThrows(TimeoutException.class, () -> getConditionalWait().waitForTrue(() ->
    {
        timer.start();
        return false;
    }, "Condition should be true"));
    DurationSample durationSample = new DurationSample(timer.duration(), getTimeoutConfig().getCondition(), defaultDeviation);
    assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString());
}
 
@Test
public void testTimeoutExceptionShouldBeThrownIfConditionIsNotMetAndTimeoutIsOver() {
    Timer timer = new Timer();
    Assert.expectThrows(TimeoutException.class, () -> getConditionalWait().waitForTrue(() ->
    {
        timer.start();
        return false;
    }, waitForTimeoutCondition, waitForTimeoutPolling, "Condition should be true"));
    DurationSample durationSample = new DurationSample(timer.duration(), waitForTimeoutCondition, defaultDeviation);
    assertTrue(durationSample.isDurationBetweenLimits(), durationSample.toString());
}
 
源代码5 项目: incubator-gobblin   文件: JobSpecResolverTest.java
@Test
public void testWithResolutionAction() throws Exception {

	Config sysConfig = ConfigFactory.empty();

	SecureJobTemplate insecureTemplate = Mockito.mock(SecureJobTemplate.class);
	Mockito.when(insecureTemplate.getResolvedConfig(Mockito.any(Config.class))).thenAnswer(i -> (Config) i.getArguments()[0]);
	Mockito.when(insecureTemplate.isSecure()).thenReturn(false);

	SecureJobTemplate secureTemplate = Mockito.mock(SecureJobTemplate.class);
	Mockito.when(secureTemplate.getResolvedConfig(Mockito.any(Config.class))).thenAnswer(i -> (Config) i.getArguments()[0]);
	Mockito.when(secureTemplate.isSecure()).thenReturn(true);

	JobCatalogWithTemplates catalog = Mockito.mock(JobCatalogWithTemplates.class);
	Mockito.when(catalog.getTemplate(Mockito.eq(URI.create("my://template.insecure")))).thenReturn(insecureTemplate);
	Mockito.when(catalog.getTemplate(Mockito.eq(URI.create("my://template.secure")))).thenReturn(secureTemplate);

	JobSpecResolver resolver = JobSpecResolver.builder(sysConfig).jobCatalog(catalog)
			// This resolution action should block any resolution that does not use a secure template
			.jobResolutionAction(new SecureTemplateEnforcer()).build();

	JobSpec jobSpec = JobSpec.builder()
			.withConfig(ConfigFactory.parseMap(ImmutableMap.of("key", "value")))
			.withTemplate(URI.create("my://template.insecure")).build();
	Assert.expectThrows(JobTemplate.TemplateException.class, () -> resolver.resolveJobSpec(jobSpec));

	JobSpec jobSpec2 = JobSpec.builder()
			.withConfig(ConfigFactory.parseMap(ImmutableMap.of("key", "value")))
			.withTemplate(URI.create("my://template.secure")).build();
	ResolvedJobSpec resolvedJobSpec = resolver.resolveJobSpec(jobSpec2);

	Assert.assertEquals(resolvedJobSpec.getOriginalJobSpec(), jobSpec2);
	Assert.assertEquals(resolvedJobSpec.getConfig().entrySet().size(), 1);
	Assert.assertEquals(resolvedJobSpec.getConfig().getString("key"), "value");
}
 
@Test(dataProvider = "getIntervalFiles")
public void testCompareIntervals(File left, File right, boolean expectedMatch) {
    final ArgumentsBuilder args = new ArgumentsBuilder();
    args.addReference(new File(hg19MiniReference))
            .add("L", left)
            .add("L2", right);

    if(expectedMatch) {
        runCommandLine(args);
    } else {
        Assert.expectThrows(UserException.class, () -> runCommandLine(args));
    }

}
 
源代码7 项目: gatk   文件: DeprecatedToolsRegistryTest.java
@Test
public void testRunMissingDeprecatedTool() {
    final String missingTool = "IndelRealigner";

    final UserException e = Assert.expectThrows(
            UserException.class,
            () -> new Main().instanceMain( new String[] {missingTool} )
    );
    Assert.assertTrue(e.getMessage().contains(DeprecatedToolsRegistry.getToolDeprecationInfo(missingTool)));
}
 
源代码8 项目: gatk   文件: DeprecatedToolsRegistryTest.java
@Test
public void testRunMissingButNotRegisteredTool() {
    final String missingButNotRegisteredTool = "MadeUpToolNotInTheRegistry";

    Assert.assertNull(DeprecatedToolsRegistry.getToolDeprecationInfo(missingButNotRegisteredTool));

    final Main main = new Main();
    final UserException e = Assert.expectThrows(
            UserException.class,
            () -> main.instanceMain( new String[] {missingButNotRegisteredTool} )
    );
    Assert.assertTrue(e.getMessage().contains(main.getUnknownCommandMessage(Collections.emptySet(), missingButNotRegisteredTool)));
}
 
源代码9 项目: aquality-selenium-java   文件: BrowserTabsTests.java
@Test
public void testShouldThrowIfSwitchToNewTabByIncorrectIndex() {
    Assert.expectThrows(IndexOutOfBoundsException.class, () -> AqualityServices.getBrowser().tabs().switchToTab(10, true));
}
 
源代码10 项目: pulsar   文件: SimpleSchemaTest.java
@Test
public void newProducerForMessageSchemaOnTopicWithMultiVersionSchema() throws Exception {
    String topic = "my-property/my-ns/schema-test";
    Schema<V1Data> v1Schema = Schema.AVRO(V1Data.class);
    byte[] v1SchemaBytes = v1Schema.getSchemaInfo().getSchema();
    AvroWriter<V1Data> v1Writer = new AvroWriter<>(
            new Parser().parse(new ByteArrayInputStream(v1SchemaBytes)));
    Schema<V2Data> v2Schema = Schema.AVRO(V2Data.class);
    byte[] v2SchemaBytes = v2Schema.getSchemaInfo().getSchema();
    AvroWriter<V2Data> v2Writer = new AvroWriter<>(
            new Parser().parse(new ByteArrayInputStream(v2SchemaBytes)));
    try (Producer<V1Data> ignored = pulsarClient.newProducer(v1Schema)
                                                .topic(topic).create()) {
    }
    try (Producer<V2Data> p = pulsarClient.newProducer(Schema.AVRO(V2Data.class))
                                          .topic(topic).create()) {
        p.send(new V2Data(-1, -1));
    }
    V1Data dataV1 = new V1Data(2);
    V2Data dataV2 = new V2Data(3, 5);
    byte[] contentV1 = v1Writer.write(dataV1);
    byte[] contentV2 = v2Writer.write(dataV2);
    try (Producer<byte[]> p = pulsarClient.newProducer(Schema.AUTO_PRODUCE_BYTES())
                                          .topic(topic).create();
            Consumer<V2Data> c = pulsarClient.newConsumer(v2Schema)
                                             .topic(topic)
                                             .subscriptionName("sub1").subscribe()) {
        Assert.expectThrows(SchemaSerializationException.class, () -> p.send(contentV1));

        p.newMessage(Schema.AUTO_PRODUCE_BYTES(Schema.AVRO(V1Data.class)))
         .value(contentV1).send();
        p.send(contentV2);
        Message<V2Data> msg1 = c.receive();
        V2Data msg1Value = msg1.getValue();
        Assert.assertEquals(dataV1.i, msg1Value.i);
        Assert.assertNull(msg1Value.j);
        Assert.assertEquals(msg1.getSchemaVersion(), new LongSchemaVersion(0).bytes());

        Message<V2Data> msg2 = c.receive();
        Assert.assertEquals(dataV2, msg2.getValue());
        Assert.assertEquals(msg2.getSchemaVersion(), new LongSchemaVersion(1).bytes());

        try {
            p.newMessage(Schema.BYTES).value(contentV1).send();
            if (schemaValidationEnforced) {
                Assert.fail("Shouldn't be able to send to a schema'd topic with no schema"
                                    + " if SchemaValidationEnabled is enabled");
            }
            Message<V2Data> msg3 = c.receive();
            Assert.assertEquals(msg3.getSchemaVersion(), SchemaVersion.Empty.bytes());
        } catch (PulsarClientException e) {
            if (schemaValidationEnforced) {
                Assert.assertTrue(e instanceof IncompatibleSchemaException);
            } else {
                Assert.fail("Shouldn't throw IncompatibleSchemaException"
                                    + " if SchemaValidationEnforced is disabled");
            }
        }
    }
}
 
源代码11 项目: JMPQ3   文件: MpqTests.java
@Test
public void testException() {
    Assert.expectThrows(JMpqException.class, () -> new BlockTable(ByteBuffer.wrap(new byte[0])).getBlockAtPos(-1));
}
 
源代码12 项目: git-as-svn   文件: AuthLdapTest.java
@Test(dataProvider = "sslModes")
public void invalidPassword(@NotNull DirectoryServerNet serverNet) {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser(EmbeddedDirectoryServer.ADMIN_USERNAME, "wrongpassword", serverNet));
}
 
源代码13 项目: git-as-svn   文件: AuthLdapTest.java
@Test(dataProvider = "sslModes")
public void invalidUser(@NotNull DirectoryServerNet serverNet) {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser("ldapadmin2", EmbeddedDirectoryServer.ADMIN_PASSWORD, serverNet));
}
 
源代码14 项目: git-as-svn   文件: AuthLdapTest.java
@Test(dataProvider = "sslModes")
public void anonymousUserDenies(@NotNull DirectoryServerNet serverNet) {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkAnonymous(false, serverNet));
}
 
源代码15 项目: git-as-svn   文件: GitLabIntegrationTest.java
@Test
void invalidPassword() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser(root, "wrongpassword"));
}
 
源代码16 项目: git-as-svn   文件: GitLabIntegrationTest.java
@Test
void invalidUser() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser("wronguser", rootPassword));
}
 
源代码17 项目: git-as-svn   文件: GiteaIntegrationTest.java
@Test
void testInvalidPassword() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser(administrator, "wrongpassword"));
}
 
源代码18 项目: git-as-svn   文件: GiteaIntegrationTest.java
@Test
void testInvalidUser() {
  Assert.expectThrows(SVNAuthenticationException.class, () -> checkUser("wronguser", administratorPassword));
}