本文整理汇总了Java中org.springframework.test.util.ReflectionTestUtils.setField方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionTestUtils.setField方法的具体用法?Java ReflectionTestUtils.setField怎么用?Java ReflectionTestUtils.setField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.test.util.ReflectionTestUtils
的用法示例。
在下文中一共展示了ReflectionTestUtils.setField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
urlRules = buildURLRules(buildDefaultStatement(PORT, PROTOCOL, URN, "4"));
stubNamespacedListsHolder = new StubNamespacedListsHolder();
Config config = new Config();
ServiceProviderManagerFactory serviceProviderManagerFactory = new ServiceProviderManagerFactory();
serviceProviderManagerFactory.setConfig(config);
serviceProviderManagerFactory.setProviderStrategy(new RoundRobinStrategy<>());
factory = new RedirectorEngineFactory(serviceProviderManagerFactory);
ReflectionTestUtils.setField(factory, "config", config);
ReflectionTestUtils.setField(factory, "isStaticDiscoveryNeededForApp", Predicate.isEqual(APP_NAME));
ReflectionTestUtils.setField(factory, "serializer", serializer);
}
示例2: sendPasswordResetEmailSMTP
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Test
public void sendPasswordResetEmailSMTP() {
ReflectionTestUtils.setField(sut, "mailEnabled", true);
String id = "1234567890";
String email = "[email protected]";
String subject = "Password recovery";
String expected = "Hello!\nSomeone has requested a password recovery on this email address. If this was not " +
"you then just ignore this message. If not then click the link bellow.\n\n" +
"http://localhost:8080/update-password/" + id;
sut.sendPasswordResetEmail(id, email);
ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
verify(sender, times(1)).send(captor.capture());
SimpleMailMessage message = captor.getValue();
assertEquals(1, message.getTo().length);
assertEquals(email, message.getTo()[0]);
assertEquals(subject, message.getSubject());
assertEquals(expected, message.getText());
}
示例3: sendOrganizationChangeDenialEmailSMTP
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Test
public void sendOrganizationChangeDenialEmailSMTP() {
ReflectionTestUtils.setField(sut, "mailEnabled", true);
String email = "[email protected]";
String subject = "Your organization change was denied";
String expected = "Hello!\nYour organization change was denied by an administrator";
sut.sendDenialEmail(email, "organization change");
ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
verify(sender, times(1)).send(captor.capture());
SimpleMailMessage message = captor.getValue();
assertEquals(1, message.getTo().length);
assertEquals(email, message.getTo()[0]);
assertEquals(subject, message.getSubject());
assertEquals(expected, message.getText());
}
示例4: setUp
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
layoutMapper = new LayoutMapper();
YamlMapFactoryBean yamlMapFactoryBean = new YamlMapFactoryBean();
yamlMapFactoryBean.setResources(new FileSystemResource(LayoutMapperTest.class.getResource("layout.yml").getPath()));
// String layout = "" +
// "category:\n" +
// " _default_: \"category/_layout\"\n" +
// "food:\n" +
// " detail: \"food/_layout\"\n" +
// "boo:\n" +
// " _default_: \"boo/_layout\"\n" +
// " index: \"_boo\"\n" +
// " foo:\n" +
// " detail: \"boo/_detail\"" +
// "";
// yamlMapFactoryBean.setResources(new ByteArrayResource(layout.getBytes("UTF-8")));
yamlMapFactoryBean.afterPropertiesSet();
ReflectionTestUtils.setField(layoutMapper, "layout", yamlMapFactoryBean.getObject());
ReflectionTestUtils.invokeMethod(layoutMapper, "init");
}
示例5: init
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Before
public void init() {
MockitoAnnotations.initMocks(this);
ReflectionTestUtils.setField(jwtUtils, "expirationInSecs", EXPIRATION_PERIOD);
ReflectionTestUtils.setField(jwtUtils, "secret", SECRET_KEY);
ReflectionTestUtils.setField(jwtUtils, "allowedClockSkewInSecs", ALLOWED_CLOCK_SKEW_IN_SECS);
ReflectionTestUtils.setField(jwtUtils, "issuer", ISSUER);
ReflectionTestUtils.setField(jwtUtils, "audience", AUDIENCE);
}
示例6: shouldNotAddACustomerIfCustomerAlreadyExists
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Test
public void shouldNotAddACustomerIfCustomerAlreadyExists() throws Exception {
// Given
when(repo.existsById(any(ObjectId.class))).thenReturn(Mono.just(true));
final ObjectId id = ObjectId.get();
final Customer customer = Customer.ofType(PERSON).build();
ReflectionTestUtils.setField(customer, "id", id);
// When
// Then
assertThatThrownBy(() -> controller.addCustomer(customer).block())
.isInstanceOf(CustomerServiceException.class)
.hasMessageContaining("Customer already exists");
}
示例7: beforeEachTest
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Before
public void beforeEachTest() {
MockitoAnnotations.initMocks(this);
producer = new PrivilegeEventProducer(template);
ReflectionTestUtils.setField(producer, "appName", "test-ms");
ReflectionTestUtils.setField(producer, "topicName", topicSystemQueue);
}
示例8: setup
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@PostConstruct
public void setup() {
MockitoAnnotations.initMocks(this);
ImageResourceResource imageResourceResource = new ImageResourceResource();
ReflectionTestUtils.setField(imageResourceResource, "imageResourceRepository", imageResourceRepository);
this.restImageResourceMockMvc = MockMvcBuilders.standaloneSetup(imageResourceResource)
.setCustomArgumentResolvers(pageableArgumentResolver)
.setMessageConverters(jacksonMessageConverter).build();
}
示例9: setup
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
TimeFrameResource timeFrameResource = new TimeFrameResource();
ReflectionTestUtils.setField(timeFrameResource, "timeFrameService", timeFrameService);
this.restTimeFrameMockMvc = MockMvcBuilders.standaloneSetup(timeFrameResource)
.setCustomArgumentResolvers(pageableArgumentResolver)
.setMessageConverters(jacksonMessageConverter).build();
}
示例10: setup
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
SubscriberResource subscriberResource = new SubscriberResource();
ReflectionTestUtils.setField(subscriberResource, "subscriberService", subscriberService);
this.restSubscriberMockMvc = MockMvcBuilders.standaloneSetup(subscriberResource)
.setCustomArgumentResolvers(pageableArgumentResolver)
.setMessageConverters(jacksonMessageConverter).build();
}
示例11: setup
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@PostConstruct
public void setup() {
MockitoAnnotations.initMocks(this);
PostResource postResource = new PostResource();
ReflectionTestUtils.setField(postResource, "postRepository", postRepository);
ReflectionTestUtils.setField(postResource, "postMapper", postMapper);
this.restPostMockMvc = MockMvcBuilders.standaloneSetup(postResource)
.setCustomArgumentResolvers(pageableArgumentResolver)
.setMessageConverters(jacksonMessageConverter).build();
}
示例12: testGetCanonicalizedResourcePathEncodingException
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
/**
* Test method for
* {@link org.ligoj.app.plugin.prov.aws.auth.AWS4SignerBase#getCanonicalizedResourcePath(java.lang.String)}.
*/
@Test(expected = TechnicalException.class)
public void testGetCanonicalizedResourcePathEncodingException() throws Exception {
final AWS4SignerBase signer = new AWS4SignerForAuthorizationHeader();
final URLCodec urlCodec = Mockito.mock(URLCodec.class);
ReflectionTestUtils.setField(signer, "urlCodec", urlCodec);
Mockito.when(urlCodec.encode(ArgumentMatchers.anyString())).thenThrow(new EncoderException());
signer.getCanonicalizedResourcePath("/path");
}
示例13: setUp
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
appNamespaceServiceWithCache = new AppNamespaceServiceWithCache();
ReflectionTestUtils.setField(appNamespaceServiceWithCache, "appNamespaceRepository",
appNamespaceRepository);
ReflectionTestUtils.setField(appNamespaceServiceWithCache, "bizConfig", bizConfig);
scanInterval = 50;
scanIntervalTimeUnit = TimeUnit.MILLISECONDS;
when(bizConfig.appNamespaceCacheRebuildInterval()).thenReturn(scanInterval);
when(bizConfig.appNamespaceCacheRebuildIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit);
when(bizConfig.appNamespaceCacheScanInterval()).thenReturn(scanInterval);
when(bizConfig.appNamespaceCacheScanIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit);
}
示例14: setup
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@Before
public void setup() {
jHipsterProperties = Mockito.mock(JHipsterProperties.class);
tokenProvider = new TokenProvider(jHipsterProperties);
ReflectionTestUtils.setField(tokenProvider, "secretKey", secretKey);
ReflectionTestUtils.setField(tokenProvider, "tokenValidityInMilliseconds", ONE_MINUTE);
}
示例15: setup
import org.springframework.test.util.ReflectionTestUtils; //导入方法依赖的package包/类
@PostConstruct
public void setup() {
MockitoAnnotations.initMocks(this);
PhotoLocationExtraImageResource photoLocationExtraImageResource = new PhotoLocationExtraImageResource();
ReflectionTestUtils.setField(photoLocationExtraImageResource, "photoLocationExtraImageRepository", photoLocationExtraImageRepository);
this.restPhotoLocationExtraImageMockMvc = MockMvcBuilders.standaloneSetup(photoLocationExtraImageResource)
.setCustomArgumentResolvers(pageableArgumentResolver)
.setMessageConverters(jacksonMessageConverter).build();
}