This commit is contained in:
Rob Winch
2020-10-21 15:32:21 -05:00
parent 657adb29fe
commit 790516c50b
4 changed files with 13 additions and 11 deletions

View File

@@ -16,18 +16,18 @@
package example;
import java.lang.reflect.Method;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.ReflectionUtils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
@@ -45,7 +45,7 @@ public class SecurityMessageRepositoryTests {
void findAllOnlyToCurrentUser() {
Method method = ReflectionUtils.findMethod(SecurityMessageRepositoryTests.class, "findAllOnlyToCurrentUser");
WithMockCustomUser withMockCustomUser = AnnotationUtils.findAnnotation(method, WithMockCustomUser.class);
List<Message> messages = repository.findAll();
List<Message> messages = this.repository.findAll();
assertThat(messages).hasSize(3);
for (Message m : messages) {
assertThat(m.getTo().getId()).isEqualTo(withMockCustomUser.id());

View File

@@ -16,11 +16,11 @@
package example;
import org.springframework.security.test.context.support.WithSecurityContext;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.springframework.security.test.context.support.WithSecurityContext;
@Retention(RetentionPolicy.RUNTIME)
@WithSecurityContext(factory = WithMockCustomUserSecurityContextFactory.class)
public @interface WithMockCustomUser {