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.

Revisions

  1. jonayGodoy renamed this gist Jul 1, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jonayGodoy created this gist Jul 1, 2017.
    51 changes: 51 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    @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");
    }
    }