refactor(tests): removed @IMPLEMENTS

This commit is contained in:
vsavkin
2015-08-26 11:41:41 -07:00
parent 457eb5d69c
commit 343dcfa0c0
43 changed files with 402 additions and 426 deletions

View File

@ -23,11 +23,6 @@ class ABSTRACT {
const ABSTRACT();
}
class IMPLEMENTS {
final interfaceClass;
const IMPLEMENTS(this.interfaceClass);
}
bool isPresent(obj) => obj != null;
bool isBlank(obj) => obj == null;
bool isString(obj) => obj is String;

View File

@ -71,13 +71,6 @@ export function ABSTRACT(): ClassDecorator {
return (t) => t;
}
// Note: This is only a marker annotation needed for ts2dart.
// This is written so that is can be used as a Traceur annotation
// or a Typescript decorator.
export function IMPLEMENTS(_): ClassDecorator {
return (t) => t;
}
export function isPresent(obj: any): boolean {
return obj !== undefined && obj !== null;
}

View File

@ -5,15 +5,14 @@ import {ReadyStates} from '../enums';
import {Connection, ConnectionBackend} from '../interfaces';
import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async';
import {isPresent} from 'angular2/src/core/facade/lang';
import {IMPLEMENTS, BaseException} from 'angular2/src/core/facade/lang';
import {BaseException} from 'angular2/src/core/facade/lang';
/**
*
* Mock Connection to represent a {@link Connection} for tests.
*
**/
@IMPLEMENTS(Connection)
export class MockConnection {
export class MockConnection implements Connection {
// TODO Name `readyState` should change to be more generic, and states could be made to be more
// descriptive than XHR states.
/**
@ -130,8 +129,7 @@ export class MockConnection {
* This method only exists in the mock implementation, not in real Backends.
**/
@Injectable()
@IMPLEMENTS(ConnectionBackend)
export class MockBackend {
export class MockBackend implements ConnectionBackend {
/**
* {@link EventEmitter}
* of {@link MockConnection} instances that have been created by this backend. Can be subscribed

View File

@ -1,26 +1,12 @@
import {SpyObject, proxy} from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {List, ListWrapper} from 'angular2/src/core/facade/collection';
import {Location} from 'angular2/src/router/location';
@proxy
@IMPLEMENTS(Location)
export class SpyLocation extends SpyObject {
urlChanges: List<string>;
_path: string;
_subject: EventEmitter;
_baseHref: string;
constructor() {
super();
this._path = '';
this.urlChanges = [];
this._subject = new EventEmitter();
this._baseHref = '';
}
export class SpyLocation implements Location {
urlChanges: List<string> = [];
_path: string = '';
_subject: EventEmitter = new EventEmitter();
_baseHref: string = '';
setInitialPath(url: string) { this._path = url; }
@ -54,5 +40,7 @@ export class SpyLocation extends SpyObject {
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
}
noSuchMethod(m: any) { super.noSuchMethod(m); }
// TODO: remove these once Location is an interface, and can be implemented cleanly
platformStrategy: any = null;
normalize(url: string): string { return null; }
}

View File

@ -18,12 +18,12 @@ export const APP_BASE_HREF: OpaqueToken = CONST_EXPR(new OpaqueToken('appBaseHre
*/
@Injectable()
export class Location {
private _subject: EventEmitter = new EventEmitter();
private _baseHref: string;
_subject: EventEmitter = new EventEmitter();
_baseHref: string;
constructor(public _platformStrategy: LocationStrategy,
constructor(public platformStrategy: LocationStrategy,
@Optional() @Inject(APP_BASE_HREF) href?: string) {
var browserBaseHref = isPresent(href) ? href : this._platformStrategy.getBaseHref();
var browserBaseHref = isPresent(href) ? href : this.platformStrategy.getBaseHref();
if (isBlank(browserBaseHref)) {
throw new BaseException(
@ -31,48 +31,31 @@ export class Location {
}
this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
this._platformStrategy.onPopState((_) => this._onPopState(_));
this.platformStrategy.onPopState(
(_) => { ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true}); });
}
_onPopState(_): void {
ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true});
}
path(): string { return this.normalize(this._platformStrategy.path()); }
path(): string { return this.normalize(this.platformStrategy.path()); }
normalize(url: string): string {
return stripTrailingSlash(this._stripBaseHref(stripIndexHtml(url)));
return stripTrailingSlash(_stripBaseHref(this._baseHref, stripIndexHtml(url)));
}
normalizeAbsolutely(url: string): string {
if (!url.startsWith('/')) {
url = '/' + url;
}
return stripTrailingSlash(this._addBaseHref(url));
}
_stripBaseHref(url: string): string {
if (this._baseHref.length > 0 && url.startsWith(this._baseHref)) {
return url.substring(this._baseHref.length);
}
return url;
}
_addBaseHref(url: string): string {
if (!url.startsWith(this._baseHref)) {
return this._baseHref + url;
}
return url;
return stripTrailingSlash(_addBaseHref(this._baseHref, url));
}
go(url: string): void {
var finalUrl = this.normalizeAbsolutely(url);
this._platformStrategy.pushState(null, '', finalUrl);
this.platformStrategy.pushState(null, '', finalUrl);
}
forward(): void { this._platformStrategy.forward(); }
forward(): void { this.platformStrategy.forward(); }
back(): void { this._platformStrategy.back(); }
back(): void { this.platformStrategy.back(); }
subscribe(onNext: (value: any) => void, onThrow: (exception: any) => void = null,
onReturn: () => void = null): void {
@ -80,7 +63,19 @@ export class Location {
}
}
function _stripBaseHref(baseHref: string, url: string): string {
if (baseHref.length > 0 && url.startsWith(baseHref)) {
return url.substring(baseHref.length);
}
return url;
}
function _addBaseHref(baseHref: string, url: string): string {
if (!url.startsWith(baseHref)) {
return baseHref + url;
}
return url;
}
function stripIndexHtml(url: string): string {
if (/\/index.html$/g.test(url)) {

View File

@ -15,7 +15,6 @@ import {
List,
ListWrapper
} from 'angular2/src/core/facade/collection';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {RouteHandler} from './route_handler';
import {Url, RootUrl, serializeParams} from './url_parser';

View File

@ -1,36 +0,0 @@
library test_lib.spies;
import 'package:angular2/src/core/change_detection/change_detection.dart';
import 'package:angular2/di.dart';
import './test_lib.dart';
@proxy
class SpyChangeDetector extends SpyObject implements ChangeDetector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyProtoChangeDetector extends SpyObject implements ProtoChangeDetector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyDependencyProvider extends SpyObject implements DependencyProvider {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyChangeDetectorRef extends SpyObject implements ChangeDetectorRef {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyIterableDifferFactory extends SpyObject
implements IterableDifferFactory {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyInjector extends SpyObject implements Injector {
noSuchMethod(m) => super.noSuchMethod(m);
}

View File

@ -1,28 +0,0 @@
import {
ChangeDetector,
ChangeDetectorRef,
ProtoChangeDetector,
DynamicChangeDetector
} from 'angular2/src/core/change_detection/change_detection';
import {DependencyProvider} from 'angular2/di';
import {SpyObject, proxy} from './test_lib';
export class SpyChangeDetector extends SpyObject {
constructor() { super(DynamicChangeDetector); }
}
export class SpyProtoChangeDetector extends SpyObject {
constructor() { super(DynamicChangeDetector); }
}
export class SpyDependencyProvider extends SpyObject {}
export class SpyIterableDifferFactory extends SpyObject {}
export class SpyInjector extends SpyObject {}
export class SpyChangeDetectorRef extends SpyObject {
constructor() { super(ChangeDetectorRef); }
}

View File

@ -209,6 +209,10 @@ class SpyObject extends gns.SpyObject {
SpyFunction spy(String funcName) =>
_spyFuncs.putIfAbsent(funcName, () => new SpyFunction(funcName));
void prop(String funcName, value) {
_spyFuncs.putIfAbsent("get:${funcName}", () => new SpyFunction(funcName)).andReturn(value);
}
static stub([object = null, config = null, overrides = null]) {
if (object is! SpyObject) {
overrides = config;

View File

@ -353,6 +353,8 @@ export class SpyObject {
return this[name];
}
prop(name, value) { this[name] = value; }
static stub(object = null, config = null, overrides = null) {
if (!(object instanceof SpyObject)) {
overrides = config;