viernes, 17 de abril de 2020

create a super-user in postgres

$ sudo -u postgres psql -c "ALTER USER <user_name> PASSWORD '<new_password>';"

=# SELECT usename FROM pg_user;
=# ALTER USER <user_name> WITH SUPERUSER; ALTER ROLE
=# \du

martes, 14 de abril de 2020

Técnica de las costuras y testear clases estáticas.

Refactoring and Design Skills for Test Driven Development SA2013 by Roy Osherove

--> SUT

public class LoginManager
{
    private IReadOnlyCollection<string> users;

    public LoginManager()
    {
        users = new[] { "john", "clare", "Mary", "Tom" };
    }

    public bool IsLoginOk(string user, string password)
    {
        log(user);
        return users.Contains(user);
    }

    protected virtual void log(string user)
    {
        Logger.Log(user);
    }
}

public static class Logger
{
    public static void Log(string message)
    {
    }
}

--> Test
public class LoginManagerShould
{
    private LoginManagerTesteable loginManager;
   
    [SetUp]
    public void SetUp()
    {
        loginManager = new LoginManagerTesteable();           
    }
   
    [Test]
    public void return_false_when_user_is_empty()
    {
        var result = loginManager.IsLoginOk(String.Empty, "password");
       
        Assert.IsFalse(result);
    }
   
    [Test]
    public void return_false_when_user_is_null()
    {
        var result = loginManager.IsLoginOk(null, "password");
       
        Assert.IsFalse(result);
    }

    [Test]
    public void return_true_when_user_is_valid()
    {
        var result = loginManager.IsLoginOk("Tom", "password");
       
        Assert.IsTrue(result);
    }
}

class LoginManagerTesteable : LoginManager
{
    protected override void log(string user)
    {
    }
}

install openjdk-13

different java versions -> apt search openjdk

add a repository -> sudo add-apt-repository ppa:openjdk-r/ppa

install openjdk-13 -> sudo apt install openjdk-13-jdk

domingo, 5 de abril de 2020

procedural polymorphism

New interesting concept, that I discovered when I read Understanding the Four Rules of Simple Design Corey Haines

And this post

The main idea behind this concept is replace the same kind of conditions by objects. Because with this conditions we are mixing two different concepts (breaking single responsibility principal).

I've applied this concept in this project