/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 ****************************************************************/

package org.apache.mailet.base;

import static org.assertj.core.api.Assertions.assertThat;

import javax.mail.MessagingException;

import org.apache.mailet.Mail;
import org.junit.Before;
import org.junit.Test;

public class GenericMailetTest {

    private static class TestingMailet extends GenericMailet {

        @Override
        public void service(Mail mail) throws MessagingException {
        }
    }

    private TestingMailet testee;

    @Before
    public void setup() {
        testee = new TestingMailet();
    }

    @Test
    public void getBooleanParameterShouldReturnFalseWhenValueNullAndDefaultFalse() throws Exception {
        String value = null;
        boolean actual = testee.getBooleanParameter(value, false);
        assertThat(actual).isFalse();
    }
    
    @Test
    public void getBooleanParameterShouldReturnTrueWhenValueTrueAndDefaultFalse() throws Exception {
        String value = "true";
        boolean actual = testee.getBooleanParameter(value, false);
        assertThat(actual).isTrue();
    }
    
    @Test
    public void getBooleanParameterShouldReturnTrueWhenValueYesAndDefaultFalse() throws Exception {
        String value = "yes";
        boolean actual = testee.getBooleanParameter(value, false);
        assertThat(actual).isTrue();
    }

    @Test
    public void getBooleanParameterShouldReturnFalseWhenValueOtherAndDefaultFalse() throws Exception {
        String value = "other";
        boolean actual = testee.getBooleanParameter(value, false);
        assertThat(actual).isFalse();
    }

    @Test
    public void getBooleanParameterShouldReturnTrueWhenValueNullAndDefaultTrue() throws Exception {
        String value = null;
        boolean actual = testee.getBooleanParameter(value, true);
        assertThat(actual).isTrue();
    }

    @Test
    public void getBooleanParameterShouldReturnFalseWhenValueNoAndDefaultTrue() throws Exception {
        String value = "no";
        boolean actual = testee.getBooleanParameter(value, true);
        assertThat(actual).isFalse();
    }

    @Test
    public void getBooleanParameterShouldReturnFalseWhenValueFalseAndDefaultTrue() throws Exception {
        String value = "false";
        boolean actual = testee.getBooleanParameter(value, true);
        assertThat(actual).isFalse();
    }

    @Test
    public void getBooleanParameterShouldReturnTrueWhenValueOtherAndDefaultTrue() throws Exception {
        String value = "other";
        boolean actual = testee.getBooleanParameter(value, true);
        assertThat(actual).isTrue();
    }

}
