-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
94d4897
commit f048c9d
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
...t/java/com/github/natche/gravatarjavaclient/profile/GravatarProfileTokenProviderTest.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,92 @@ | ||
package com.github.natche.gravatarjavaclient.profile; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* Tests for {@link GravatarProfileTokenProvider}s. | ||
*/ | ||
public class GravatarProfileTokenProviderTest { | ||
/** | ||
* Creates a new instance for testing purposes. | ||
*/ | ||
GravatarProfileTokenProviderTest() {} | ||
|
||
/** | ||
* | ||
*/ | ||
@Test | ||
void testCreation() { | ||
assertThrows(NullPointerException.class, | ||
() -> new GravatarProfileTokenProvider(null, null)); | ||
assertThrows(NullPointerException.class, | ||
() -> new GravatarProfileTokenProvider(() -> new byte[0], null)); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new GravatarProfileTokenProvider(() -> new byte[0], "")); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new GravatarProfileTokenProvider(() -> new byte[0], " ")); | ||
assertDoesNotThrow( | ||
() -> new GravatarProfileTokenProvider(() -> new byte[0], "source")); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Test | ||
void testGetToken() { | ||
byte[] bytes = "PostMalone".getBytes(StandardCharsets.US_ASCII); | ||
GravatarProfileTokenProvider provider = new GravatarProfileTokenProvider(() -> bytes, "source"); | ||
assertEquals(bytes, provider.getToken()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Test | ||
void testToString() { | ||
byte[] bytes = "PostMalone".getBytes(StandardCharsets.US_ASCII); | ||
GravatarProfileTokenProvider provider = new GravatarProfileTokenProvider(() -> bytes, "source"); | ||
GravatarProfileTokenProvider nonEqualProvider | ||
= new GravatarProfileTokenProvider(() -> new byte[0], "another source"); | ||
|
||
assertEquals("GravatarProfileTokenProvider{source=\"source\"}", provider.toString()); | ||
assertEquals("GravatarProfileTokenProvider{source=\"another source\"}", nonEqualProvider.toString()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Test | ||
void testEquals() { | ||
byte[] bytes = "PostMalone".getBytes(StandardCharsets.US_ASCII); | ||
GravatarProfileTokenProvider provider = new GravatarProfileTokenProvider(() -> bytes, "source"); | ||
GravatarProfileTokenProvider equalProvider = new GravatarProfileTokenProvider(() -> bytes, "source"); | ||
GravatarProfileTokenProvider nonEqualProvider | ||
= new GravatarProfileTokenProvider(() -> new byte[0], "another source"); | ||
|
||
assertEquals(provider, provider); | ||
assertEquals(provider, equalProvider); | ||
assertNotEquals(provider, nonEqualProvider); | ||
assertNotEquals(provider, new Object()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Test | ||
void testHashCode() { | ||
byte[] bytes = "PostMalone".getBytes(StandardCharsets.US_ASCII); | ||
GravatarProfileTokenProvider provider = new GravatarProfileTokenProvider(() -> bytes, "source"); | ||
GravatarProfileTokenProvider equalProvider = new GravatarProfileTokenProvider(() -> bytes, "source"); | ||
GravatarProfileTokenProvider nonEqualProvider | ||
= new GravatarProfileTokenProvider(() -> new byte[0], "another source"); | ||
|
||
assertEquals(-896505829, provider.hashCode()); | ||
assertEquals(-896505829, equalProvider.hashCode()); | ||
assertEquals(1165062104, nonEqualProvider.hashCode()); | ||
assertNotEquals(equalProvider.hashCode(), nonEqualProvider.hashCode()); | ||
} | ||
} |