// Path: service/src/main/java/info/rolandkrueger/userservice/UserMicroserviceApplication.java
// @SpringBootApplication
// @PropertySource("userservice.properties")
// public class UserMicroserviceApplication {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(
//                 new Object[]{
//                         UserMicroserviceApplication.class,
//                         DevelopmentProfileConfiguration.class}
//                 , args);
//     }
// }
// 
// Path: service/src/main/java/info/rolandkrueger/userservice/model/Authority.java
// @Entity
// public class Authority implements GrantedAuthority {
//     private Long id;
//     @Version
//     Long version;
//     @LastModifiedDate
//     LocalDateTime lastModified;
// 
//     @NotBlank
//     private String authority;
// 
//     private String description;
// 
//     private Authority() {
//         lastModified = LocalDateTime.now();
//         version = 1L;
//     }
// 
//     public Authority(String authority) {
//         this();
//         setAuthority(authority);
//     }
// 
//     public Authority(String authority, String description) {
//         this(authority);
//         this.description = description;
//     }
// 
//     @Id
//     @GeneratedValue
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     protected void setAuthority(String authority) {
//         Preconditions.checkArgument(!Strings.isNullOrEmpty(MoreObjects.firstNonNull(authority, "").trim()));
//         this.authority = authority;
//     }
// 
//     @Override
//     @Column(unique = true)
//     public String getAuthority() {
//         return authority;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public void setDescription(String description) {
//         this.description = description;
//     }
// 
//     public Long getVersion() {
//         return version;
//     }
// 
//     public void setVersion(Long version) {
//         this.version = version;
//     }
// 
//     public LocalDateTime getLastModified() {
//         return lastModified;
//     }
// 
//     public void setLastModified(LocalDateTime lastModified) {
//         this.lastModified = lastModified;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(Authority.class)
//                 .add("authority", authority)
//                 .toString();
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null || !(obj instanceof Authority)) {
//             return false;
//         }
//         if (obj == this) {
//             return true;
//         }
//         Authority other = (Authority) obj;
//         return Objects.equals(authority, other.authority);
//     }
// 
//     @Override
//     public int hashCode() {
//         return authority.hashCode();
//     }
// }
// 
// Path: service/src/test/java/info/rolandkrueger/userservice/testsupport/AbstractServiceTest.java
// @Transactional
// public abstract class AbstractServiceTest {
// 
//     public Authority adminAuthority, userAuthority, developerAuthority;
//     public User alice, bob, charly;
// 
//     public AbstractServiceTest() {
//         adminAuthority = new Authority("admin", "The admin role");
//         userAuthority = new Authority("user", "The user role");
//         developerAuthority = new Authority("developer", "The developer role");
//     }
// 
//     protected void createTestData(AuthorityService authorityService, UserService userService) {
//         Arrays.asList(adminAuthority, userAuthority, developerAuthority)
//                 .stream()
//                 .forEach(authorityService::create);
// 
//         alice = new User("alice");
//         alice.setUnencryptedPassword("alice");
//         alice.createRegistrationConfirmationToken();
//         alice.setEmail("alice@example.com");
//         alice.addAuthority(adminAuthority);
// 
//         bob = new User("bob");
//         bob.setUnencryptedPassword("bob");
//         bob.addAuthority(developerAuthority);
//         bob.addAuthority(userAuthority);
// 
//         charly = new User("charly");
//         charly.setLastLogin(LocalDateTime.now());
//         charly.setUnencryptedPassword("charly");
// 
//         Arrays.asList(alice, bob, charly)
//                 .stream()
//                 .forEach(userService::save);
//     }
// }


import info.rolandkrueger.userservice.UserMicroserviceApplication;
import info.rolandkrueger.userservice.model.Authority;
import info.rolandkrueger.userservice.testsupport.AbstractServiceTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.number.OrderingComparison.greaterThan;
package info.rolandkrueger.userservice.service;




/**
 * @author Roland Krüger
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = UserMicroserviceApplication.class)
@Transactional
// Path: service/src/main/java/info/rolandkrueger/userservice/UserMicroserviceApplication.java
// @SpringBootApplication
// @PropertySource("userservice.properties")
// public class UserMicroserviceApplication {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(
//                 new Object[]{
//                         UserMicroserviceApplication.class,
//                         DevelopmentProfileConfiguration.class}
//                 , args);
//     }
// }
// 
// Path: service/src/main/java/info/rolandkrueger/userservice/model/Authority.java
// @Entity
// public class Authority implements GrantedAuthority {
//     private Long id;
//     @Version
//     Long version;
//     @LastModifiedDate
//     LocalDateTime lastModified;
// 
//     @NotBlank
//     private String authority;
// 
//     private String description;
// 
//     private Authority() {
//         lastModified = LocalDateTime.now();
//         version = 1L;
//     }
// 
//     public Authority(String authority) {
//         this();
//         setAuthority(authority);
//     }
// 
//     public Authority(String authority, String description) {
//         this(authority);
//         this.description = description;
//     }
// 
//     @Id
//     @GeneratedValue
//     public Long getId() {
//         return id;
//     }
// 
//     public void setId(Long id) {
//         this.id = id;
//     }
// 
//     protected void setAuthority(String authority) {
//         Preconditions.checkArgument(!Strings.isNullOrEmpty(MoreObjects.firstNonNull(authority, "").trim()));
//         this.authority = authority;
//     }
// 
//     @Override
//     @Column(unique = true)
//     public String getAuthority() {
//         return authority;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public void setDescription(String description) {
//         this.description = description;
//     }
// 
//     public Long getVersion() {
//         return version;
//     }
// 
//     public void setVersion(Long version) {
//         this.version = version;
//     }
// 
//     public LocalDateTime getLastModified() {
//         return lastModified;
//     }
// 
//     public void setLastModified(LocalDateTime lastModified) {
//         this.lastModified = lastModified;
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(Authority.class)
//                 .add("authority", authority)
//                 .toString();
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null || !(obj instanceof Authority)) {
//             return false;
//         }
//         if (obj == this) {
//             return true;
//         }
//         Authority other = (Authority) obj;
//         return Objects.equals(authority, other.authority);
//     }
// 
//     @Override
//     public int hashCode() {
//         return authority.hashCode();
//     }
// }
// 
// Path: service/src/test/java/info/rolandkrueger/userservice/testsupport/AbstractServiceTest.java
// @Transactional
// public abstract class AbstractServiceTest {
// 
//     public Authority adminAuthority, userAuthority, developerAuthority;
//     public User alice, bob, charly;
// 
//     public AbstractServiceTest() {
//         adminAuthority = new Authority("admin", "The admin role");
//         userAuthority = new Authority("user", "The user role");
//         developerAuthority = new Authority("developer", "The developer role");
//     }
// 
//     protected void createTestData(AuthorityService authorityService, UserService userService) {
//         Arrays.asList(adminAuthority, userAuthority, developerAuthority)
//                 .stream()
//                 .forEach(authorityService::create);
// 
//         alice = new User("alice");
//         alice.setUnencryptedPassword("alice");
//         alice.createRegistrationConfirmationToken();
//         alice.setEmail("alice@example.com");
//         alice.addAuthority(adminAuthority);
// 
//         bob = new User("bob");
//         bob.setUnencryptedPassword("bob");
//         bob.addAuthority(developerAuthority);
//         bob.addAuthority(userAuthority);
// 
//         charly = new User("charly");
//         charly.setLastLogin(LocalDateTime.now());
//         charly.setUnencryptedPassword("charly");
// 
//         Arrays.asList(alice, bob, charly)
//                 .stream()
//                 .forEach(userService::save);
//     }
// }


// Path: service/src/test/java/info/rolandkrueger/userservice/service/AuthorityServiceTest.java
import info.rolandkrueger.userservice.UserMicroserviceApplication;
import info.rolandkrueger.userservice.model.Authority;
import info.rolandkrueger.userservice.testsupport.AbstractServiceTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.number.OrderingComparison.greaterThan;

package info.rolandkrueger.userservice.service;




/**
 * @author Roland Krüger
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = UserMicroserviceApplication.class)
@Transactional
public class AuthorityServiceTest extends AbstractServiceTest {