This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#141] add AppUserTest + AppUserServiceTest
- Loading branch information
Showing
4 changed files
with
196 additions
and
8 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
44 changes: 44 additions & 0 deletions
44
src/test/java/de/bonndan/nivio/appuser/AppUserServiceTest.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,44 @@ | ||
package de.bonndan.nivio.appuser; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@DataJpaTest | ||
class AppUserServiceTest { | ||
|
||
|
||
@Test | ||
void loadUserByUsername() { | ||
|
||
// given | ||
AppUser appUser = mock(AppUser.class); | ||
AppUserRepository appUserRepository = mock(AppUserRepository.class); | ||
AppUserService appUserService = new AppUserService(appUserRepository); | ||
|
||
// when | ||
doReturn(Optional.of(appUser)).when(appUserRepository).findByExternalId("123"); | ||
UserDetails userDetails = appUserService.loadUserByUsername("123"); | ||
|
||
// then | ||
assertThat(userDetails).isEqualTo(appUser); | ||
assertNull(userDetails.getUsername()); | ||
assertNull(userDetails.getPassword()); | ||
assertFalse(userDetails.isAccountNonExpired()); | ||
assertFalse(userDetails.isAccountNonLocked()); | ||
assertFalse(userDetails.isCredentialsNonExpired()); | ||
|
||
assertThrows(UsernameNotFoundException.class, () -> { | ||
appUserService.loadUserByUsername(""); | ||
}); | ||
} | ||
|
||
} |
146 changes: 146 additions & 0 deletions
146
src/test/java/de/bonndan/nivio/appuser/AppUserTest.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,146 @@ | ||
package de.bonndan.nivio.appuser; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class AppUserTest { | ||
|
||
AppUser appUser = new AppUser(); | ||
|
||
@Test | ||
void isEnabled() { | ||
appUser.setEnabled(true); | ||
assertEquals(true, appUser.getEnabled()); | ||
} | ||
|
||
@Test | ||
void getId() { | ||
appUser.setId(1L); | ||
assertEquals(1L, appUser.getId()); | ||
} | ||
|
||
@Test | ||
void getName() { | ||
appUser.setName("name"); | ||
assertEquals("name", appUser.getName()); | ||
} | ||
|
||
@Test | ||
void getAlias() { | ||
appUser.setAlias("alias"); | ||
assertEquals("alias", appUser.getAlias()); | ||
} | ||
|
||
@Test | ||
void getEmail() { | ||
appUser.setEmail("email"); | ||
assertEquals("email", appUser.getEmail()); | ||
} | ||
|
||
@Test | ||
void getAvatarUrl() { | ||
appUser.setAvatarUrl("avatarUrl"); | ||
assertEquals("avatarUrl", appUser.getAvatarUrl()); | ||
} | ||
|
||
@Test | ||
void getAppUserRole() { | ||
appUser.setAppUserRole(AppUserRole.USER); | ||
assertEquals(AppUserRole.USER, appUser.getAppUserRole()); | ||
} | ||
|
||
@Test | ||
void getExternalId() { | ||
appUser.setExternalId("123"); | ||
assertEquals("123", appUser.getExternalId()); | ||
} | ||
|
||
@Test | ||
void getIdp() { | ||
appUser.setIdp("github"); | ||
assertEquals("github", appUser.getIdp()); | ||
} | ||
|
||
@Test | ||
void getLocked() { | ||
appUser.setLocked(false); | ||
assertEquals(false, appUser.getLocked()); | ||
} | ||
|
||
@Test | ||
void getEnabled() { | ||
appUser.setEnabled(true); | ||
assertEquals(true, appUser.getEnabled()); | ||
} | ||
|
||
@Test | ||
void setId() { | ||
Long id = 1L; | ||
appUser.setId(id); | ||
assertEquals(id, appUser.getId()); | ||
} | ||
|
||
@Test | ||
void setName() { | ||
String name = "name"; | ||
appUser.setName(name); | ||
assertEquals(name, appUser.getName()); | ||
} | ||
|
||
@Test | ||
void setAlias() { | ||
String alias = "login"; | ||
appUser.setAlias(alias); | ||
assertEquals(alias, appUser.getAlias()); | ||
} | ||
|
||
@Test | ||
void setEmail() { | ||
String email = "email"; | ||
appUser.setEmail(email); | ||
assertEquals(email, appUser.getEmail()); | ||
} | ||
|
||
@Test | ||
void setAvatarUrl() { | ||
String avatarUrl = "avatarUrl"; | ||
appUser.setAvatarUrl(avatarUrl); | ||
assertEquals(avatarUrl, appUser.getAvatarUrl()); | ||
} | ||
|
||
@Test | ||
void setAppUserRole() { | ||
appUser.setAppUserRole(AppUserRole.USER); | ||
assertEquals(AppUserRole.USER, appUser.getAppUserRole()); | ||
} | ||
|
||
@Test | ||
void setLocked() { | ||
Boolean locked = false; | ||
appUser.setLocked(locked); | ||
assertEquals(locked, appUser.getLocked()); | ||
} | ||
|
||
@Test | ||
void setEnabled() { | ||
Boolean enabled = true; | ||
appUser.setEnabled(enabled); | ||
assertEquals(enabled, appUser.getEnabled()); | ||
} | ||
|
||
@Test | ||
void setExternalId() { | ||
String externalId = "123"; | ||
appUser.setExternalId(externalId); | ||
assertEquals(externalId, appUser.getExternalId()); | ||
} | ||
|
||
@Test | ||
void setIdp() { | ||
String idp = "github"; | ||
appUser.setIdp(idp); | ||
assertEquals(idp, appUser.getIdp()); | ||
} | ||
} |