Skip to content

Instantly share code, notes, and snippets.

View iporsut's full-sized avatar
🏠
Working from home

Weerasak Chongnguluam iporsut

🏠
Working from home
View GitHub Profile
@iporsut
iporsut / gist:b53b3e3af38af76cf64f
Created October 21, 2014 15:16
AcceptingAuthorizerFake Java
public class AcceptingAuthorizerFake implements Authorizer {
public Boolean authorize(String username, String password) {
return username.equals("Bob");
}
}
@iporsut
iporsut / gist:d35af8ec0ec6bf2266c1
Created October 21, 2014 15:15
AcceptingAuthorizerVerificationMock Go
type AcceptingAuthorizerVerificationMock struct {
AuthorizeWasCalled bool
}
func (mock *AcceptingAuthorizerVerificationMock) Authorize(username, password string) (bool, error) {
mock.AuthorizeWasCalled = true
return true, nil
}
func (mock *AcceptingAuthorizerVerificationMock) Verify() bool {
@iporsut
iporsut / gist:0ad151bec4f55156b6a5
Created October 21, 2014 15:14
AcceptingAuthorizerVerificationMock Java
public class AcceptingAuthorizerVerificationMock implements Authorizer {
public boolean authorizeWasCalled = false;
public Boolean authorize(String username, String password) {
authorizeWasCalled = true;
return true;
}
public boolean verify() {
return authorizedWasCalled;
@iporsut
iporsut / gist:db2ab5538646487a9696
Created October 21, 2014 15:14
AcceptingAuthorizerSpy Go
type AcceptingAuthorizerSpy struct {
AuthorizeWasCalled bool
}
func (spy *AcceptingAuthorizerSpy) Authorize(username, password string) (bool, error) {
spy.AuthorizeWasCalled = true
return true, nil
}
@iporsut
iporsut / gist:1929201c6e70e9e7b917
Created October 21, 2014 15:13
AcceptingAuthorizerSpy Java
public class AcceptingAuthorizerSpy implements Authorizer {
public boolean authorizeWasCalled = false;
public Boolean authorize(String username, String password) {
authorizeWasCalled = true;
return true;
}
}
@iporsut
iporsut / gist:2e495d4be456cdc66af1
Created October 21, 2014 15:12
AcceptingAuthorizerStub Go
type AcceptingAuthorizerStub struct {
}
func (stub *AcceptingAuthorizerStub) Authorize(username, password string) (bool, error) {
return true, nil
}
@iporsut
iporsut / gist:d2fd845322e811d753ff
Created October 21, 2014 15:11
AcceptingAuthorizerStub Java
public class AcceptingAuthorizerStub implements Authorizer {
public Boolean authorize(String username, String password) {
return true;
}
}
@iporsut
iporsut / gist:41bfe0a2c43e0a2ae884
Created October 21, 2014 15:11
System Test Go
type System struct {
Authorizer authorizer.Authorizer
}
func (system *System) LoginCount() int {
return 0
}
func TestNewlyCreatedSystemHasNoLoggedInUsers(t *testing.T) {
system := &System { &authorizer.DummyAuthorizer{} }
@iporsut
iporsut / gist:b3e95478733c1f28fabd
Created October 21, 2014 15:10
System Test Java
public class System {
public System(Authorizer authorizer) {
this.authorizer = authorizer;
}
public int loginCount() {
//returns number of logged in users.
}
}
@iporsut
iporsut / gist:a9d5c98c3240a89507f6
Created October 21, 2014 15:08
DummyAuthorizer Go
type DummyAuthorizer struct {
}
func (dummy *DummyAuthorizer) Authorize(username, password string) (bool, error) {
return false, errors.New("Don't used Dummy")
}