Skip to content

Instantly share code, notes, and snippets.

@jonayGodoy
Last active July 1, 2017 16:33
Show Gist options
  • Select an option

  • Save jonayGodoy/b090fd1d9512b625c23a39e9b89975fe to your computer and use it in GitHub Desktop.

Select an option

Save jonayGodoy/b090fd1d9512b625c23a39e9b89975fe to your computer and use it in GitHub Desktop.
static not static 2
@Test
public void user_only_can_delete_own_commentary() throws Exception {
User user = new UserStub("user");
Commentary userCommentary = new Commentary("Hola mundo", anyUser);
Commentary anyCommentary = new Commentary("Hola mundo", new User("anyUser", new Authentication()));
Assert.assertTrue(user.deleteCommentary(userCommentary));
Assert.assertFalse(user.deleteCommentary(anyCommentary));
}
@Test
public void admin_can_delete_all_commentary() throws Exception {
User user = new AdminStub("JonayRules");
Commentary userCommentary = new Commentary("Hola mundo", anyUser);
Commentary anyCommentary = new Commentary("Hola mundo", new User("anyUser", new Authentication()));
Assert.assertTrue(user.deleteCommentary(userCommentary));
Assert.assertTrue(user.deleteCommentary(anyCommentary));
}
}
public class UserStub extends User{
private String name;
private String authenticationLevel;
private Authentication authentication;
public UserStub(String name,String authenticationLevel) {
super(name);
this.authenticationLevel = authenticationLevel;
}
protected Authentication getAuthentication() {
return AnyFramework.generateAuthentication("USER");
}
}
public class AdminStub extends User{
private String name;
private Authentication authentication;
public UserStub(String name,String authenticationLevel) {
super(name);
this.authenticationLevel = authenticationLevel;
}
protected Authentication getAuthentication() {
return AnyFramework.generateAuthentication("ADMIN");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment