我正努力自学Mockito.
考虑下面的方法hasInventory(),它不应该以我的思维方式运行,而是设置为返回true或false,因为我松鼠笼罩我的测试.Class Warehouse是我的"模仿依赖".
public class Warehouse implements IWarehouse
{
private Map< String, Integer > inventory;
public Warehouse()
{
this.inventory = new HashMap< String, Integer >();
}
public final boolean hasInventory( String itemname, int quantity )
throws InventoryDoesNotExistException
{
if( inventory == null )
throw new InventoryDoesNotExistException();
if( !inventory.containsKey( itemname ) )
return false;
int current = ( inventory.containsKey( itemname ) ) ? inventory.get( itemname ) : 0;
return( current >= quantity );
} …Run Code Online (Sandbox Code Playgroud) 在lettable operator之前,我做了一个帮助来修改debounceTime方法,所以它使用了一个TestScheduler:
export function mockDebounceTime(
scheduler: TestScheduler,
overrideTime: number,
): void {
const originalDebounce = Observable.prototype.debounceTime;
spyOn(Observable.prototype, 'debounceTime').and.callFake(function(
time: number,
): void {
return originalDebounce.call(
this,
overrideTime,
scheduler,
);
});
}
Run Code Online (Sandbox Code Playgroud)
因此,以下Observable的测试很简单:
@Effect()
public filterUpdated$ = this.actions$
.ofType(UPDATE_FILTERS)
.debounceTime(DEFAULT_DEBOUNCE_TIME)
.mergeMap(action => [...])
Run Code Online (Sandbox Code Playgroud)
对于lettable运算符,filterUpdated $ Observable的编写方式如下:
@Effect()
public filterUpdated$ = this.actions$
.ofType(UPDATE_FILTERS)
.pipe(
debounceTime(DEFAULT_DEBOUNCE_TIME),
mergeMap(action => [...])
);
Run Code Online (Sandbox Code Playgroud)
我不能修复debounceTime运算符了!如何将testScheduler传递给debounceTime运算符?
我有一个表单和这样的底层模型
来自组件
myTextModel: string;
updateMyTextModel(): void {
this.myTextModel = "updated model value";
//todo- set form dirty (or invalid or touched) here
}
Run Code Online (Sandbox Code Playgroud)
Html模板
<form #testForm="ngForm" id="testForm">
<input type="text" id="myText" [(ngModel)]="myTextModel" name="myText" #myText="ngModel">
</form>
<button (click)="updateMyTextModel()">Update myTextModel</button>
<div *ngIf="testForm.dirty">testForm diry</div>
<div *ngIf="testForm.touched">testForm touched</div>
Run Code Online (Sandbox Code Playgroud)
如何从代码中设置触摸或脏的表单?
注意:在此示例中,我使用按钮来触发模型更改,但我也可能以其他方式更新模型,例如在来自web api异步请求的回调中.
ElementRef我有一个使用下面定义的方法。
@ViewChild('idNaicsRef') idNaicsRef: ElementRef;
Run Code Online (Sandbox Code Playgroud)
ElementRef然后使用 设置焦点.nativeElement.focus()。
该方法在运行规范时失败,提示“未定义是一个对象”
有了Spring4 + ActiveMQ,我想从队列接收JMS消息,并自动转换为POJO.所以我添加MappingJackson2MessageConverter到DefaultJmsListenerContainerFactory
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
// some other config
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("???");
factory.setMessageConverter(converter);
return factory;
}
Run Code Online (Sandbox Code Playgroud)
这是我的Listener配置
@JmsListener(destination = "queue.fas.flight.order", containerFactory = "jmsListenerContainerFactory")
public void processOrder(OrderRegisterDto registerParam) {
System.out.println(registerParam.toString());
}
Run Code Online (Sandbox Code Playgroud)
问题是,我不知道如何设置TypeIdPropertyName.队列不在我的控制之下,其他人发送JSON给它.
我想要一个普通的转换器.所以我使用String接收消息,并手动将其转换为POJO.
Spring4 + ActiveMQ
还有更好的方法吗?
我从他们发布它的那天起就一直在使用Angula2 + Universal,但今天我对它的实际工作方式感到困惑.
在他们的示例中,在server.ts文件中,您将找到:
app.get( '/data.json' , ( req , res ) => {
res.json( {
data : 'This fake data came from the server.'
} );
} );
Run Code Online (Sandbox Code Playgroud)
如果您运行该应用程序,右键单击并查看页面源代码,您将在源代码中找到"此伪造数据来自服务器",这意味着该页面已在服务器中呈现?( 它是否正确 ? )
到目前为止,太棒了.
接下来是app.ts,你可以找到:
ngOnInit () {
setTimeout( () => {
this.server = 'This was rendered from the server!';
} , 10 );
}
Run Code Online (Sandbox Code Playgroud)
同样,该文本也可以在页面源中找到.
现在这里是我的奇怪部分:
如果您出于任何原因增加服务器延迟,如:
app.get( '/data.json' , ( req , res ) => {
setTimeout( function() {
res.json( {
data : 'This fake data …Run Code Online (Sandbox Code Playgroud) 我正在使用 mat-select 来显示下拉菜单,我需要在 angular 下拉菜单中选择所有功能。
下面是我的html
<mat-select formControlName="myControl" multiple (ngModelChange)="resetSelect($event, 'myControl')">
<mat-option>Select All</mat-option>
<mat-option [value]="1">Option 1</mat-option>
<mat-option [value]="2">Option 2</mat-option>
<mat-option [value]="3">Option 3</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)
这是我的 ts 代码
/**
* click handler that resets a multiple select
* @param {Array} $event current value of the field
* @param {string} field name of the formControl in the formGroup
*/
protected resetSelect($event: string[], field: string) {
// when resetting the value, this method gets called again, so stop recursion if we have no values …Run Code Online (Sandbox Code Playgroud) 我只在带有atomikos的实时服务器上遇到问题,在我的本地服务器上它完美运行.
我在服务器上的问题是
init()出错:Log已在使用中?
完成异常堆栈跟踪
java.lang.RuntimeException: Log already in use?
at com.atomikos.icatch.standalone.UserTransactionServiceImp.createDefault(UserTransactionServiceImp.java:205)
at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:265)
at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:405)
at com.atomikos.icatch.jta.UserTransactionImp.checkSetup(UserTransactionImp.java:100)
at com.atomikos.icatch.jta.UserTransactionImp.begin(UserTransactionImp.java:115)
at com.vs.framework.service.BlfServiceAtomIkosBean.executeService(BlfServiceAtomIkosBean.java:32)
at com.dbhl.app.presentation.action.CreateUnitTypeAction.execute(CreateUnitTypeAction.java:128)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:662)
com.atomikos.icatch.SysException: Error in init(): Log …Run Code Online (Sandbox Code Playgroud) 我是Junit的新手而且我遇到了问题.任何帮助将非常感激.
public void testGuaranteedRates() throws Exception
{
ParticipantSummary summary = new ParticipantSummary();
EasyMock.expect( iRequest.getPIN() ).andReturn( "1060720" );
DateFormat dateFormat = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" );
Date date = new Date();
EasyMock.expect( iRequest.getTradeDate() ).andReturn( date ).anyTimes();
EasyMock.expect( control.prepareServiceRequest( iRequest ) ).andReturn( rtvint );
EasyMock.replay();
ems.replayAll();
}
Run Code Online (Sandbox Code Playgroud)
prepareServiceRequest()方法如下
org.tiaa.transact.generated.jaxb.inquiry.RetrieveRetirementVintages prepareServiceRequest(InquiryRequest inquiryRequest)
{
logger.debug( "prepareServiceRequest enter" );
org.tiaa.transact.generated.jaxb.inquiry.ObjectFactory objectFactory = new org.tiaa.transact.generated.jaxb.inquiry.ObjectFactory();
org.tiaa.transact.generated.jaxb.inquiry.RetrieveRetirementVintages retirementVintages = objectFactory.createRetrieveRetirementVintages();
if( ( inquiryRequest ) != null )
{
if( ( inquiryRequest.getPIN() ) != null )
{
retirementVintages.setPIN( …Run Code Online (Sandbox Code Playgroud) 再次需要帮助!
我正在使用Angular 4,并希望从我的组件中的url获取参数.URL是" http:// myhost/index?user = James&token = 123&picture = 3456abc.png "或" http:// myhost/index?user = Peter "
我试过这些不同的方法,但没有运气.
如何获取网址参数'user','token'和'picture'?
import { Routes, RouterModule, Router, ActivatedRoute, RouteSegment, Params, ROUTER_DIRECTIVES } from '@angular/router';
constructor(private restSvc: RestSvc, private router: Router, private domSanitizer: DomSanitizer,
private mdIconRegistry: MdIconRegistry, private activatedRoute: ActivatedRoute, private routeSegment: RouteSegment) {
// Method 1: subscribe to queryParamMap - not working - all values are undefined
/* this.activatedRoute.queryParamMap.subscribe(params => {
this.userName = params['user'];
this.userToken = params['token'];
this.userPicture = params['picture'];
}) */
// …Run Code Online (Sandbox Code Playgroud) angular ×5
typescript ×5
java ×4
angular5 ×1
atomikos ×1
easymock ×1
javascript ×1
junit ×1
mockito ×1
ngrx-effects ×1
rxjs5 ×1
spring-jms ×1