/*
 * Copyright (c) 2004-2019, University of Oslo
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the HISP project nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.hisp.dhis.android.core.trackedentity.internal;

import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore;
import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl;
import org.hisp.dhis.android.core.common.Access;
import org.hisp.dhis.android.core.common.ObjectStyle;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(JUnit4.class)
public class TrackedEntityAttributeHandlerShould {

    @Mock
    private IdentifiableObjectStore<TrackedEntityAttribute> trackedEntityAttributeStore;

    @Mock
    private TrackedEntityAttribute trackedEntityAttribute;

    @Mock
    private ObjectStyle objectStyle;

    @Mock
    private Access access;

    // object to test
    private List<TrackedEntityAttribute> trackedEntityAttributes;
    private TrackedEntityAttributeHandler trackedEntityAttributeHandler;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        trackedEntityAttributeHandler = new TrackedEntityAttributeHandler(trackedEntityAttributeStore);

        trackedEntityAttributes = new ArrayList<>();
        trackedEntityAttributes.add(trackedEntityAttribute);

        when(trackedEntityAttribute.uid()).thenReturn("test_tracked_entity_attribute_uid");
        when(trackedEntityAttribute.style()).thenReturn(objectStyle);
        when(trackedEntityAttribute.formName()).thenReturn("form_name");
        when(trackedEntityAttribute.access()).thenReturn(access);
        when(access.read()).thenReturn(true);
    }

    @Test
    public void extend_identifiable_handler_impl() {
        IdentifiableHandlerImpl<TrackedEntityAttribute> genericHandler =
                new TrackedEntityAttributeHandler(null);
    }

    @Test
    public void delete_tea_if_no_read_access() {
        when(access.read()).thenReturn(false);
        trackedEntityAttributeHandler.handleMany(trackedEntityAttributes);
        verify(trackedEntityAttributeStore).deleteIfExists(trackedEntityAttribute.uid());
    }
}
@@ -2444,78 +2444,8 @@
 e;%0A%0A
-    @Mock%0A    private TrackedEntityAttribute trackedEntityAttribute;%0A%0A
     
@@ -2526,16 +2526,76 @@
 ccess;%0A%0A
+    private TrackedEntityAttribute trackedEntityAttribute;%0A%0A
     // o
@@ -2986,146 +2986,64 @@
 bute
-s
  = 
-new ArrayList%3C%3E();%0A        trackedEntityAttributes.add(trackedEntityAttribute);%0A%0A        when(trackedEntityAttribute.uid()).thenReturn
+TrackedEntityAttribute.builder()%0A                .uid
 (%22te
@@ -3075,17 +3075,16 @@
 te_uid%22)
-;
 %0A       
@@ -3088,55 +3088,22 @@
     
-when(trackedEntityAttribute.style()).thenReturn
+        .style
 (obj
@@ -3111,26 +3111,26 @@
 ctStyle)
-;
 %0A
+ 
         
 when(tra
@@ -3125,58 +3125,99 @@
     
-when(trackedEntityAttribute.formName()).thenReturn
+       .name(%22name%22)%0A                .displayName(%22display_name%22)%0A                .formName
 (%22fo
@@ -3225,17 +3225,16 @@
 m_name%22)
-;
 %0A       
@@ -3238,66 +3238,174 @@
     
-when(trackedEntityAttribute.access()).thenReturn(access
+        .access(access)%0A                .build();%0A%0A        trackedEntityAttributes = new ArrayList%3C%3E();%0A        trackedEntityAttributes.add(trackedEntityAttribute
 );%0A
+%0A
     

Fix TEA handler test