use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project noip by davidecolombo.
the class AppTest method testSystemExitWithStatus.
@Test
@ExpectSystemExitWithStatus(1)
void testSystemExitWithStatus() throws IOException {
try (MockedStatic<INoIpApi> mockedApi = Mockito.mockStatic(INoIpApi.class);
MockedStatic<ObjectMapperUtils> mockedJsonUtils = Mockito.mockStatic(ObjectMapperUtils.class)) {
INoIpApi api = Mockito.mock(INoIpApi.class);
Mockito.when(api.update(// hostname
Mockito.anyString(), // ip
Mockito.anyString())).thenReturn(Calls.response(String.format("%s %s", "nochg", TestUtils.LOOPBACK_ADDRESS)));
mockedApi.when(() -> INoIpApi.build(// username
Mockito.anyString(), // password
Mockito.anyString(), // user-agent
Mockito.anyString())).thenReturn(api);
ObjectMapper objectMapper = Mockito.mock(ObjectMapper.class, Mockito.RETURNS_DEEP_STUBS);
// fake settings
Mockito.when(objectMapper.readValue(Mockito.any(File.class), Mockito.eq(NoIpSettings.class))).thenReturn(TestUtils.createMockedNoIpSettings());
// fake ipify
IpifyResponse mockedIpifyResponse = new IpifyResponse();
mockedIpifyResponse.setIp(TestUtils.LOOPBACK_ADDRESS);
Mockito.when(objectMapper.readValue(Mockito.any(URL.class), Mockito.eq(IpifyResponse.class))).thenReturn(mockedIpifyResponse);
mockedJsonUtils.when(ObjectMapperUtils::createObjectMapper).thenReturn(objectMapper);
Assertions.assertNotNull(ObjectMapperUtils.createObjectMapper());
App.main(new String[] { "-settings", "dummy.json" });
// wait for system exit with exit code
}
}
use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project SchemaCrawler by schemacrawler.
the class LinterConfigsDispatchTest method testSystemExitLinterConfigExecutable.
@Test
@ExpectSystemExitWithStatus(1)
public void testSystemExitLinterConfigExecutable(final TestContext testContext, final Connection connection) throws Exception {
final Config additionalConfig = new Config();
additionalConfig.put("lint-dispatch", "terminate_system");
executableLint(connection, "/schemacrawler-linter-configs-with-dispatch.yaml", additionalConfig, "schemacrawler-linter-configs-with-dispatch");
checkSystemErrLog(testContext);
}
use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project keycloak-config-cli by adorsys.
the class CommandLineImportFilesIT method testImportFile.
@Test
@ExpectSystemExitWithStatus(0)
void testImportFile() {
KeycloakConfigApplication.main(new String[] { "--import.path=src/test/resources/import-files/cli/file.json" });
RealmRepresentation fileRealm = keycloakProvider.getInstance().realm("file").toRepresentation();
assertThat(fileRealm.getRealm(), is("file"));
assertThat(fileRealm.isEnabled(), is(true));
}
use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project pgpainless by pgpainless.
the class SignUsingPublicKeyBehaviorTest method testSignatureCreationAndVerification.
@Test
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
public void testSignatureCreationAndVerification() throws IOException {
originalSout = System.out;
InputStream originalIn = System.in;
// Write alice key to disc
File aliceKeyFile = new File(tempDir, "alice.key");
assertTrue(aliceKeyFile.createNewFile());
OutputStream aliceKeyOut = new FileOutputStream(aliceKeyFile);
Streams.pipeAll(new ByteArrayInputStream(KEY_THAT_IS_A_CERT.getBytes(StandardCharsets.UTF_8)), aliceKeyOut);
aliceKeyOut.close();
// Write alice pub key to disc
File aliceCertFile = new File(tempDir, "alice.pub");
assertTrue(aliceCertFile.createNewFile());
OutputStream aliceCertOut = new FileOutputStream(aliceCertFile);
Streams.pipeAll(new ByteArrayInputStream(KEY_THAT_IS_A_CERT.getBytes(StandardCharsets.UTF_8)), aliceCertOut);
aliceCertOut.close();
// Write test data to disc
String data = "If privacy is outlawed, only outlaws will have privacy.\n";
File dataFile = new File(tempDir, "data");
assertTrue(dataFile.createNewFile());
FileOutputStream dataOut = new FileOutputStream(dataFile);
Streams.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), dataOut);
dataOut.close();
// Sign test data
FileInputStream dataIn = new FileInputStream(dataFile);
System.setIn(dataIn);
File sigFile = new File(tempDir, "sig.asc");
assertTrue(sigFile.createNewFile());
FileOutputStream sigOut = new FileOutputStream(sigFile);
System.setOut(new PrintStream(sigOut));
PGPainlessCLI.execute("sign", "--armor", aliceKeyFile.getAbsolutePath());
System.setIn(originalIn);
}
use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project pgpainless by pgpainless.
the class DetachInbandSignatureAndMessageTest method existingSignatureOutCausesException.
@Test
@ExpectSystemExitWithStatus(SOPGPException.OutputExists.EXIT_CODE)
public void existingSignatureOutCausesException() throws IOException {
// Clearsigned In
ByteArrayInputStream clearSignedIn = new ByteArrayInputStream(CLEAR_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8));
System.setIn(clearSignedIn);
// Plaintext Out
ByteArrayOutputStream msgOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(msgOut));
// Detach
File existingSigFile = new File(tempDir, "sig.existing");
assertTrue(existingSigFile.createNewFile());
PGPainlessCLI.main(new String[] { "detach-inband-signature-and-message", "--signatures-out=" + existingSigFile.getAbsolutePath() });
}
Aggregations