本文整理匯總了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();
}