/**
 * Copyright (c) 2008-2009 Andrey Somov
 *
 * Licensed 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.yaml.snakeyaml.constructor;

import junit.framework.TestCase;

import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.Yaml;

public class FilterClassesConstructorTest extends TestCase {

    public void testGetClassForName() {
        Yaml yaml = new Yaml(new Loader(new FilterConstructor(true)));
        try {
            yaml
                    .load("!!org.yaml.snakeyaml.constructor.FilterClassesConstructorTestt$LoaderBean {name: Andrey, number: 555}");
            fail("Filter is expected.");
        } catch (Exception e) {
            assertEquals(
                    "null; Can't construct a java object for tag:yaml.org,2002:org.yaml.snakeyaml.constructor.FilterClassesConstructorTestt$LoaderBean; exception=Filter is applied.",
                    e.getMessage());
        }
        yaml = new Yaml(new Loader(new FilterConstructor(false)));
        LoaderBean s = (LoaderBean) yaml
                .load("!!org.yaml.snakeyaml.constructor.FilterClassesConstructorTest$LoaderBean {name: Andrey, number: 555}");
        assertEquals("Andrey", s.getName());
    }

    class FilterConstructor extends Constructor {
        private boolean filter;

        public FilterConstructor(boolean f) {
            filter = f;
        }

        @Override
        protected Class<?> getClassForName(String name) throws ClassNotFoundException {
            if (filter && name.startsWith("org.yaml")) {
                throw new RuntimeException("Filter is applied.");
            }
            return super.getClassForName(name);
        }
    }

    public static class LoaderBean {
        private String name;
        private int number;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getNumber() {
            return number;
        }

        public void setNumber(int number) {
            this.number = number;
        }
    }
}

@@ -952,59 +952,23 @@
     
+S
 tr
-y %7B%0D%0A            yaml%0D%0A                    .load(
+ing input = 
 %22!!o
@@ -1021,32 +1021,33 @@
 structorTest
-t$Loader
+$Filtered
 Bean %7Bname: 
@@ -1055,36 +1055,81 @@
 ndrey, number: 5
-55%7D%22
+43%7D%22;%0D%0A        try %7B%0D%0A            yaml.load(input
 );%0D%0A            
@@ -1213,234 +1213,57 @@
 sert
-Equals(%0D%0A                    %22null; Can't construct a java object for tag:yaml.org,2002:org.yaml.snakeyaml.constructor.FilterClassesConstructorTestt$LoaderBean; exception=Filter is applied.%22,%0D%0A                    e.getMessage(
+True(e.getMessage().contains(%22Filter is applied.%22
 ));%0D
@@ -1350,22 +1350,24 @@
         
-Loader
+Filtered
 Bean s =
@@ -1368,22 +1368,24 @@
 an s = (
-Loader
+Filtered
 Bean) ya
@@ -1390,134 +1390,19 @@
 yaml
-%0D%0A                .load(%22!!org.yaml.snakeyaml.constructor.FilterClassesConstructorTest$LoaderBean %7Bname: Andrey, number: 555%7D%22
+.load(input
 );%0D%0A
@@ -1968,22 +1968,24 @@
 c class 
-Loader
+Filtered
 Bean %7B%0D%0A

update test