-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
168 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/test/java/io/github/mmm/base/exception/ApplicationExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.github.mmm.base.exception; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.util.Locale; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test of {@link ApplicationException}. | ||
*/ | ||
public class ApplicationExceptionTest extends Assertions { | ||
|
||
@Test | ||
public void testWithCode() { | ||
|
||
// arrange | ||
String message = "Something went wrong."; | ||
String code = "MagicCode"; | ||
// act | ||
ApplicationException exception = new ApplicationException(message) { | ||
@Override | ||
public String getCode() { | ||
|
||
return code; | ||
} | ||
}; | ||
StringWriter sw = new StringWriter(1024); | ||
PrintWriter pw = new PrintWriter(sw); | ||
exception.printStackTrace(pw); | ||
String stackTrace = sw.toString(); | ||
// assert | ||
assertThat(exception.getLocalizedMessage()).isEqualTo(message); | ||
assertThat(exception.getLocalizedMessage(Locale.ROOT)).isEqualTo(message); | ||
assertThat(exception.getNlsMessage().getMessage()).isEqualTo(message); | ||
String msg = code + ": " + message + System.lineSeparator() + exception.getUuid(); | ||
assertThat(exception.getMessage()).isEqualTo(msg); | ||
String toString = exception.getClass().getName() + ": " + msg; | ||
assertThat(exception.toString()).isEqualTo(toString); | ||
assertThat(stackTrace).startsWith(toString) | ||
.contains("io.github.mmm.base.exception.ApplicationExceptionTest.testWithCode("); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
core/src/test/java/io/github/mmm/base/exception/ObjectNotFoundExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.github.mmm.base.exception; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test of {@link ObjectNotFoundException}. | ||
*/ | ||
public class ObjectNotFoundExceptionTest extends Assertions { | ||
|
||
@Test | ||
public void testSimple() { | ||
|
||
// arrange | ||
String name = "io.github.mmm.UndefinedObject"; | ||
// act | ||
ObjectNotFoundException exception = new ObjectNotFoundException(name); | ||
// assert | ||
assertThat(exception.getLocalizedMessage()).isEqualTo("Could not find " + name); | ||
} | ||
|
||
@Test | ||
public void testWithKey() { | ||
|
||
// arrange | ||
String name = "Entity"; | ||
String key = "MagicKey"; | ||
// act | ||
ObjectNotFoundException exception = new ObjectNotFoundException(name, key); | ||
// assert | ||
assertThat(exception.getLocalizedMessage()).isEqualTo("Could not find " + name + " for key '" + key + "'"); | ||
} | ||
|
||
@Test | ||
public void testWithKeyAndOptions() { | ||
|
||
// arrange | ||
String name = "Entity"; | ||
String key = "MagicKey"; | ||
Collection<String> options = List.of("NormalKey", "Key", "HolyKey"); | ||
// act | ||
ObjectNotFoundException exception = new ObjectNotFoundException(name, key, options, null); | ||
// assert | ||
assertThat(exception.getLocalizedMessage()) | ||
.isEqualTo("Could not find " + name + " for key '" + key + "' in [NormalKey, Key, HolyKey]"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters