/*
 * 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.pdfbox.cos;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import org.apache.pdfbox.pdfwriter.COSWriter;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
 * Unittests for {@link COSBoolean}
 */
class TestCOSBoolean extends TestCOSBase
{
    final COSBoolean cosBooleanTrue = COSBoolean.TRUE;
    final COSBoolean cosBooleanFalse = COSBoolean.FALSE;

    @Test
    void testGetValue()
    {
        assertTrue(cosBooleanTrue.getValue());
        assertFalse(cosBooleanFalse.getValue());
    }

    @Test
    void testGetValueAsObject()
    {
        assertTrue(cosBooleanTrue.getValueAsObject() instanceof Boolean);
        assertEquals(Boolean.TRUE, cosBooleanTrue.getValueAsObject());
        assertTrue(cosBooleanFalse.getValueAsObject() instanceof Boolean);
        assertEquals(Boolean.FALSE, cosBooleanFalse.getValueAsObject());
    }

    @Test
    void testGetBoolean()
    {
        assertEquals(cosBooleanTrue, COSBoolean.getBoolean(Boolean.TRUE));
        assertEquals(cosBooleanFalse, COSBoolean.getBoolean(Boolean.FALSE));
    }

    @Test
    void testEquals()
    {
        COSBoolean test1 = COSBoolean.TRUE;
        COSBoolean test2 = COSBoolean.TRUE;
        COSBoolean test3 = COSBoolean.TRUE;
        // Reflexive (x == x)
        assertEquals(test1, test1);
        // Symmetric is preserved ( x==y then y===x)
        assertEquals(test2, test1);
        assertEquals(test1, test2);
        // Transitive (if x==y && y==z then x===z)
        assertEquals(test1, test2);
        assertEquals(test2, test3);
        assertEquals(test1, test3);

        assertNotEquals(COSBoolean.TRUE, COSBoolean.FALSE);
        // same 'value' but different type
        assertNotEquals(Boolean.TRUE, COSBoolean.TRUE);
        assertNotEquals(Boolean.FALSE, COSBoolean.FALSE);
        assertNotEquals(true, COSBoolean.TRUE);
        assertNotEquals(true, COSBoolean.FALSE);
    }

    @Override
    @Test
    void testAccept()
    {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        COSWriter visitor = new COSWriter(outStream);
        int index = 0;
        try
        {
            cosBooleanTrue.accept(visitor);
            testByteArrays(String.valueOf(cosBooleanTrue).getBytes(StandardCharsets.ISO_8859_1), outStream.toByteArray());
            outStream.reset();
            cosBooleanFalse.accept(visitor);
            testByteArrays(String.valueOf(cosBooleanFalse).getBytes(StandardCharsets.ISO_8859_1), outStream.toByteArray());
            outStream.reset();
        }
        catch (Exception e)
        {
            fail("Failed to write " + index + " exception: " + e.getMessage());
        }
    }

}

@@ -1017,69 +1017,8 @@
 ls;%0A
-import static org.junit.jupiter.api.Assertions.assertThrows;%0A
 impo
@@ -1072,16 +1072,16 @@
 rtTrue;%0A
+
 import s
@@ -1168,36 +1168,8 @@
 am;%0A
-import java.io.IOException;%0A
 impo
@@ -1209,33 +1209,8 @@
 ets;
-%0Aimport java.util.Arrays;
 %0A%0Aim
@@ -1529,16 +1529,107 @@
 FALSE;%0A%0A
+    @BeforeAll%0A    static void setUp()%0A    %7B%0A        testCOSBase = COSBoolean.TRUE;%0A    %7D%0A%0A
     @Tes
@@ -3918,11 +3918,10 @@
 %7D%0A    %7D%0A
-%0A
 %7D%0A

add missing test setup