/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.properties.internal;

import java.util.HashMap;
import java.util.Map;

import org.xwiki.properties.BeanManager;
import org.xwiki.properties.PropertyException;
import org.xwiki.properties.PropertyMandatoryException;
import org.xwiki.properties.internal.DefaultBeanDescriptorTest.BeanTest;
import org.xwiki.test.AbstractXWikiComponentTestCase;

/**
 * Validate {@link DefaultBeanManager}.
 * 
 * @version $Id$
 */
public class DefaultPropertiesManagerTest extends AbstractXWikiComponentTestCase
{
    BeanManager defaultPropertiesManager;

    @Override
    public void setUp() throws Exception
    {
        this.defaultPropertiesManager = getComponentManager().lookup(BeanManager.class);
    }

    public void testPopulate() throws PropertyException
    {
        BeanTest beanTest = new BeanTest();

        Map<String, String> values = new HashMap<String, String>();

        values.put("lowerprop", "lowerpropvalue");
        values.put("upperprop", "upperPropvalue");
        values.put("prop2", "42");
        values.put("prop3", "true");
        values.put("hiddenProperty", "hiddenPropertyvalue");
        values.put("publicField", "publicFieldvalue");

        this.defaultPropertiesManager.populate(beanTest, values);

        assertEquals("lowerpropvalue", beanTest.getLowerprop());
        assertEquals("upperPropvalue", beanTest.getUpperProp());
        assertEquals(42, beanTest.getProp2());
        assertEquals(true, beanTest.getProp3());
        assertEquals(null, beanTest.getHiddenProperty());
        assertEquals("publicFieldvalue", beanTest.publicField);
    }

    public void testPopulateWhenMissingMandatoryProperty() throws PropertyException
    {
        BeanTest beanTest = new BeanTest();

        Map<String, String> values = new HashMap<String, String>();

        try {
            this.defaultPropertiesManager.populate(beanTest, values);
            fail("Should have thrown a PropertyMandatoryException exception");
        } catch (PropertyMandatoryException e) {
            // expected
        }
    }
}

@@ -976,16 +976,64 @@
 l.Map;%0A%0A
+import org.junit.Assert;%0Aimport org.junit.Test;%0A
 import o
@@ -1263,37 +1263,32 @@
 ki.test.Abstract
-XWiki
 ComponentTestCas
@@ -1422,13 +1422,8 @@
 ract
-XWiki
 Comp
@@ -1438,24 +1438,32 @@
 tCase%0A%7B%0A    
+private 
 BeanManager 
@@ -1512,24 +1512,40 @@
    p
-ublic void setUp
+rotected void registerComponents
 () t
@@ -1654,32 +1654,42 @@
 .class);%0A    %7D%0A%0A
+    @Test%0A
     public void 
@@ -2206,32 +2206,39 @@
 lues);%0A%0A        
+Assert.
 assertEquals(%22lo
@@ -2278,32 +2278,39 @@
 rop());%0A        
+Assert.
 assertEquals(%22up
@@ -2350,32 +2350,39 @@
 rop());%0A        
+Assert.
 assertEquals(42,
@@ -2404,32 +2404,39 @@
 op2());%0A        
+Assert.
 assertEquals(tru
@@ -2460,32 +2460,39 @@
 op3());%0A        
+Assert.
 assertEquals(nul
@@ -2533,16 +2533,23 @@
         
+Assert.
 assertEq
@@ -2599,24 +2599,79 @@
 ld);%0A    %7D%0A%0A
+    @Test(expected = PropertyMandatoryException.class)%0A
     public v
@@ -2752,140 +2752,8 @@
   %7B%0A
-        BeanTest beanTest = new BeanTest();%0A%0A        Map%3CString, String%3E values = new HashMap%3CString, String%3E();%0A%0A        try %7B%0A    
     
@@ -2799,188 +2799,55 @@
 ate(
-b
+new B
 eanTest
-, values);%0A            fail(%22Should have thrown a PropertyMandatoryException exception%22);%0A        %7D catch (PropertyMandatoryException e) %7B%0A            // expected%0A        %7D
+(), new HashMap%3CString, String%3E());
 %0A   

Convert unit test to JUnit 4