ConfigTest.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package me.lortseam.completeconfig.data;
  2. import nl.altindag.log.LogCaptor;
  3. import org.junit.jupiter.api.AfterEach;
  4. import org.junit.jupiter.api.Test;
  5. import static org.assertj.core.api.Assertions.assertThat;
  6. import static org.junit.jupiter.api.Assertions.*;
  7. public class ConfigTest {
  8. private static final String MOD_ID = "test";
  9. private final LogCaptor logCaptor = LogCaptor.forName("CompleteConfig");
  10. @AfterEach
  11. public void afterEach() {
  12. logCaptor.clearLogs();
  13. }
  14. @Test
  15. public void _throwExceptionIfArgNull() {
  16. NullPointerException exception = assertThrows(NullPointerException.class, () -> new Config(null, false) {});
  17. assertEquals("modId is marked non-null but is null", exception.getMessage());
  18. exception = assertThrows(NullPointerException.class, () -> new Config(MOD_ID, null, false) {});
  19. assertEquals("branch is marked non-null but is null", exception.getMessage());
  20. assertThrows(NullPointerException.class, () -> new Config(MOD_ID, new String[]{null}, false) {});
  21. }
  22. @Test
  23. public void _logWarningIfEmpty() {
  24. new Config(MOD_ID, false) {};
  25. assertThat(logCaptor.getWarnLogs()).containsExactly("Empty config: " + MOD_ID + " []");
  26. }
  27. }