Skip to content

Commit

Permalink
Basic test for enum
Browse files Browse the repository at this point in the history
  • Loading branch information
zodac committed Dec 4, 2023
1 parent 5eceb09 commit 6313eeb
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions common-utils/src/test/java/me/zodac/advent/ColourTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* BSD Zero Clause License
*
* Copyright (c) 2021-2023 zodac.me
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package me.zodac.advent;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

/**
* Unit tests for {@link Colour}.
*/
class ColourTest {

@ParameterizedTest
@CsvSource({
"blue,BLUE", // Lowercase
"BLUE,BLUE", // Uppercase
"BlUe,BLUE", // Mixed case
"green,GREEN", // Green
"red,RED" // Red
})
void testGet(final String input, final Colour expected) {
assertThat(Colour.get(input))
.isEqualTo(expected);
}

@Test
void testGet_givenInvalidInput() {
assertThatThrownBy(() -> Colour.get("invalid"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Unable to find Colour for input 'invalid'");
}
}

0 comments on commit 6313eeb

Please sign in to comment.