-
Notifications
You must be signed in to change notification settings - Fork 21
/
Factory.cls
33 lines (27 loc) · 896 Bytes
/
Factory.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public virtual class Factory {
public final RepoFactory repoFactory = new RepoFactory();
@TestVisible
private static Factory factory;
protected Factory() {
// enforce getFactory() as the sole entry point for usage
}
public static Factory getFactory() {
// production code can only initialize the factory through this method
// but tests can provide an alternative factory implementation
if (factory == null) {
factory = new Factory();
}
return factory;
}
// create methods to initialize your objects here
// (an example is included in the example-app folder)
@TestVisible
private Factory withMocks {
// you can call "withMocks" after "getFactory" in tests to swap out
// how repositories are created and DML is performed
get {
this.repoFactory.setFacade(new RepoFactoryMock.FacadeMock());
return this;
}
}
}