Search in sources :

Example 1 with MockException

use of com.helger.commons.exception.mock.MockException in project ph-web by phax.

the class FailedMailDataTest method testWithExceptionAndData.

@Test
public void testWithExceptionAndData() {
    final ISMTPSettings aSettings = _createSMTPSettings();
    final EmailData aData = _createEmailData();
    final Throwable aError = new MockException("Test error");
    final FailedMailData aFMD = new FailedMailData(aSettings, aData, new MailTransportError(aError));
    assertNotNull(aFMD.getID());
    assertNotNull(aFMD.getErrorDateTime());
    assertEquals(aSettings, aFMD.getSMTPSettings());
    assertEquals(aData.getSentDateTime(), aFMD.getOriginalSentDateTime());
    assertEquals(aData, aFMD.getEmailData());
    assertTrue(aFMD.hasTransportError());
    assertNotNull(aFMD.getTransportThrowableMessage());
    assertNotNull(aFMD.getTransportError());
    XMLTestHelper.testMicroTypeConversion(aFMD);
}
Also used : MockException(com.helger.commons.exception.mock.MockException) MailTransportError(com.helger.smtp.transport.MailTransportError) ISMTPSettings(com.helger.smtp.settings.ISMTPSettings) EmailData(com.helger.smtp.data.EmailData) Test(org.junit.Test)

Example 2 with MockException

use of com.helger.commons.exception.mock.MockException in project ph-web by phax.

the class FailedMailDataTest method testWithException.

@Test
public void testWithException() {
    final ISMTPSettings aSettings = _createSMTPSettings();
    final Throwable aError = new MockException("Test error");
    final FailedMailData aFMD = new FailedMailData(aSettings, new MailTransportError(aError));
    assertNotNull(aFMD.getID());
    assertNotNull(aFMD.getErrorDateTime());
    assertEquals(aSettings, aFMD.getSMTPSettings());
    assertNull(aFMD.getOriginalSentDateTime());
    assertNull(aFMD.getEmailData());
    assertTrue(aFMD.hasTransportError());
    assertNotNull(aFMD.getTransportThrowableMessage());
    assertNotNull(aFMD.getTransportError());
    XMLTestHelper.testMicroTypeConversion(aFMD);
}
Also used : MockException(com.helger.commons.exception.mock.MockException) MailTransportError(com.helger.smtp.transport.MailTransportError) ISMTPSettings(com.helger.smtp.settings.ISMTPSettings) Test(org.junit.Test)

Example 3 with MockException

use of com.helger.commons.exception.mock.MockException in project ph-commons by phax.

the class FileIOErrorTest method testStdMethods.

@Test
public void testStdMethods() {
    // ctor 1
    final FileIOError e1 = new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(e1, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e1, new FileIOError(EFileIOOperation.COPY_DIR_RECURSIVE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e1, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_EQUALS_TARGET));
    // ctor 2
    final FileIOError e2 = new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f1);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(e2, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f1));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e2, new FileIOError(EFileIOOperation.COPY_DIR_RECURSIVE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f1));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e2, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_EQUALS_TARGET, f1));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e2, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f2));
    // ctor 3
    final FileIOError e3 = new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f1, f2);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(e3, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f1, f2));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e3, new FileIOError(EFileIOOperation.COPY_DIR_RECURSIVE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f1, f2));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e3, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_EQUALS_TARGET, f1, f2));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e3, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f2, f2));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e3, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, f1, f1));
    // ctor 4
    final Exception e = new MockException();
    final FileIOError e4 = new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, e);
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(e4, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, e));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e4, new FileIOError(EFileIOOperation.COPY_DIR_RECURSIVE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, e));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e4, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_EQUALS_TARGET, e));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(e4, new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, new MockIOException()));
}
Also used : MockException(com.helger.commons.exception.mock.MockException) MockIOException(com.helger.commons.exception.mock.MockIOException) MockException(com.helger.commons.exception.mock.MockException) MockIOException(com.helger.commons.exception.mock.MockIOException) Test(org.junit.Test)

Example 4 with MockException

use of com.helger.commons.exception.mock.MockException in project ph-commons by phax.

the class LogMessageTest method testAll.

@Test
public void testAll() {
    final LogMessage lm = new LogMessage(EErrorLevel.WARN, "Msg", new MockException());
    final LocalDateTime aNow = PDTFactory.getCurrentLocalDateTime();
    assertTrue(lm.getIssueDateTime().equals(aNow) || lm.getIssueDateTime().isBefore(aNow));
    assertSame(EErrorLevel.WARN, lm.getErrorLevel());
    assertEquals("Msg", lm.getMessage());
    assertNotNull(lm.getThrowable());
    CommonsTestHelper.testToStringImplementation(lm);
    try {
        new LogMessage(null, "Msg", new MockException());
        fail();
    } catch (final NullPointerException ex) {
    }
    try {
        new LogMessage(EErrorLevel.WARN, null, new MockException());
        fail();
    } catch (final NullPointerException ex) {
    }
}
Also used : MockException(com.helger.commons.exception.mock.MockException) LocalDateTime(java.time.LocalDateTime) Test(org.junit.Test)

Example 5 with MockException

use of com.helger.commons.exception.mock.MockException in project ph-commons by phax.

the class FileIOErrorTest method testCtor4.

@Test
public void testCtor4() {
    final FileIOError e = new FileIOError(EFileIOOperation.COPY_FILE, EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, new MockException());
    assertSame(EFileIOOperation.COPY_FILE, e.getOperation());
    assertSame(EFileIOErrorCode.SOURCE_DOES_NOT_EXIST, e.getErrorCode());
    assertNull(e.getFile1());
    assertNull(e.getFile2());
    assertTrue(e.getException() instanceof MockException);
    try {
        new FileIOError(null, EFileIOErrorCode.OPERATION_FAILED, new MockException());
        fail();
    } catch (final NullPointerException ex) {
    }
    try {
        new FileIOError(EFileIOOperation.CREATE_DIR, null, new MockException());
        fail();
    } catch (final NullPointerException ex) {
    }
    try {
        new FileIOError(EFileIOOperation.CREATE_DIR, EFileIOErrorCode.OPERATION_FAILED, (Exception) null);
        fail();
    } catch (final NullPointerException ex) {
    }
}
Also used : MockException(com.helger.commons.exception.mock.MockException) Test(org.junit.Test)

Aggregations

MockException (com.helger.commons.exception.mock.MockException)5 Test (org.junit.Test)5 ISMTPSettings (com.helger.smtp.settings.ISMTPSettings)2 MailTransportError (com.helger.smtp.transport.MailTransportError)2 MockIOException (com.helger.commons.exception.mock.MockIOException)1 EmailData (com.helger.smtp.data.EmailData)1 LocalDateTime (java.time.LocalDateTime)1