Stephan Richter
3 years ago
5 changed files with 178 additions and 22 deletions
@ -0,0 +1,144 @@ |
|||||||
|
package de.srsoftware.widerhall.data; |
||||||
|
|
||||||
|
import junit.framework.TestCase; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static de.srsoftware.widerhall.Constants.*; |
||||||
|
|
||||||
|
public class ListMemberTest extends TestCase { |
||||||
|
|
||||||
|
/*public void testConfirm() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
/*public void testCreate() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
/*public void testCreateTable() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
/*public void testFrom() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
public void testHasState() { |
||||||
|
int state = 32 | 8 | 2; |
||||||
|
ListMember lm = new ListMember(null,null,state,null); |
||||||
|
assertFalse(lm.hasState(1)); |
||||||
|
assertTrue(lm.hasState(2)); |
||||||
|
assertFalse(lm.hasState(4)); |
||||||
|
assertTrue(lm.hasState(8)); |
||||||
|
assertFalse(lm.hasState(16)); |
||||||
|
assertTrue(lm.hasState(32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(1|2)); |
||||||
|
assertFalse(lm.hasState(1|4)); |
||||||
|
assertTrue(lm.hasState(1|8)); |
||||||
|
assertFalse(lm.hasState(1|16)); |
||||||
|
assertTrue(lm.hasState(1|32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(2|4)); |
||||||
|
assertTrue(lm.hasState(2|8)); |
||||||
|
assertTrue(lm.hasState(2|16)); |
||||||
|
assertTrue(lm.hasState(2|32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(4|8)); |
||||||
|
assertFalse(lm.hasState(4|16)); |
||||||
|
assertTrue(lm.hasState(4|32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(8|16)); |
||||||
|
assertTrue(lm.hasState(8|32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(16|32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(1|2|4)); |
||||||
|
assertTrue(lm.hasState(1|2|8)); |
||||||
|
assertTrue(lm.hasState(1|2|16)); |
||||||
|
assertTrue(lm.hasState(1|2|32)); |
||||||
|
assertTrue(lm.hasState(1|4|8)); |
||||||
|
assertFalse(lm.hasState(1|4|16)); |
||||||
|
assertTrue(lm.hasState(1|4|32)); |
||||||
|
assertTrue(lm.hasState(1|8|16)); |
||||||
|
assertTrue(lm.hasState(1|8|32)); |
||||||
|
assertTrue(lm.hasState(1|16|32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(2|4|8)); |
||||||
|
assertTrue(lm.hasState(2|4|16)); |
||||||
|
assertTrue(lm.hasState(2|4|32)); |
||||||
|
assertTrue(lm.hasState(2|8|16)); |
||||||
|
assertTrue(lm.hasState(2|8|32)); |
||||||
|
assertTrue(lm.hasState(2|16|32)); |
||||||
|
|
||||||
|
assertTrue(lm.hasState(4|8|16)); |
||||||
|
assertTrue(lm.hasState(4|8|32)); |
||||||
|
assertTrue(lm.hasState(4|16|32)); |
||||||
|
assertTrue(lm.hasState(8|16|32)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void testIsOwner() { |
||||||
|
var guest = new ListMember(null,null,ListMember.STATE_SUBSCRIBER,null); |
||||||
|
var owner = new ListMember(null,null,ListMember.STATE_OWNER,null); |
||||||
|
var mod = new ListMember(null,null,ListMember.STATE_MODERATOR,null); |
||||||
|
assertFalse(guest.isOwner()); |
||||||
|
assertTrue(owner.isOwner()); |
||||||
|
assertFalse(mod.isOwner()); |
||||||
|
} |
||||||
|
|
||||||
|
public void testIsModerator() { |
||||||
|
var guest = new ListMember(null,null,ListMember.STATE_SUBSCRIBER,null); |
||||||
|
var owner = new ListMember(null,null,ListMember.STATE_OWNER,null); |
||||||
|
var mod = new ListMember(null,null,ListMember.STATE_MODERATOR,null); |
||||||
|
assertFalse(guest.isModerator()); |
||||||
|
assertTrue(owner.isModerator()); |
||||||
|
assertTrue(mod.isModerator()); |
||||||
|
} |
||||||
|
|
||||||
|
/*public void testListsOwnedBy() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
/*public void testLoad() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
/*public void testOf() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
public void testSafeMap() { |
||||||
|
var user = new User("email","name","salt","hash",0); |
||||||
|
var lm = new ListMember(null,user,ListMember.STATE_AWAITING_CONFIRMATION,"token"); |
||||||
|
assertEquals(Map.of(EMAIL,"email",NAME,"name",STATE,"awaiting confirmation"),lm.safeMap()); |
||||||
|
} |
||||||
|
|
||||||
|
public void testStateText() { |
||||||
|
var guest = new ListMember(null,null,ListMember.STATE_SUBSCRIBER,null); |
||||||
|
var owner = new ListMember(null,null,ListMember.STATE_OWNER,null); |
||||||
|
var mod = new ListMember(null,null,ListMember.STATE_MODERATOR,null); |
||||||
|
var await = new ListMember(null,null,ListMember.STATE_AWAITING_CONFIRMATION,null); |
||||||
|
|
||||||
|
assertEquals("subscriber",guest.stateText()); |
||||||
|
assertEquals("moderator, owner, subscriber",owner.stateText()); |
||||||
|
assertEquals("moderator, subscriber",mod.stateText()); |
||||||
|
assertEquals("awaiting confirmation",await.stateText()); |
||||||
|
} |
||||||
|
|
||||||
|
public void testToken() { |
||||||
|
var lm = new ListMember(null,null,0,"bam"); |
||||||
|
assertEquals("bam",lm.token()); |
||||||
|
} |
||||||
|
|
||||||
|
/*public void testUnsubscribe() { |
||||||
|
NEEDS MOCK |
||||||
|
}*/ |
||||||
|
|
||||||
|
public void testUser() { |
||||||
|
var user = new User("email","name","salt","hash",0); |
||||||
|
var lm = new ListMember(null,user,ListMember.STATE_AWAITING_CONFIRMATION,"token"); |
||||||
|
assertEquals(user,lm.user()); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue