Package gov.nasa.jpf.conformanceChecker.checkers

Source Code of gov.nasa.jpf.conformanceChecker.checkers.OrphanMethodCheckerTest

//
// Copyright (C) 2012 United States Government as represented by the
// Administrator of the National Aeronautics and Space Administration
// (NASA).  All Rights Reserved.
//
// This software is distributed under the NASA Open Source Agreement
// (NOSA), version 1.3.  The NOSA has been approved by the Open Source
// Initiative.  See the file NOSA-1.3-JPF at the top of the distribution
// directory tree for the complete NOSA document.
//
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
//
package gov.nasa.jpf.conformanceChecker.checkers;

import static gov.nasa.jpf.conformanceChecker.util.MaybeVersion.just;
import static gov.nasa.jpf.conformanceChecker.util.MockFactory.cls;
import static gov.nasa.jpf.conformanceChecker.util.MockFactory.method;
import static java.lang.reflect.Modifier.PROTECTED;
import static java.lang.reflect.Modifier.PUBLIC;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import gov.nasa.jpf.conformanceChecker.providers.ProviderFactory;
import gov.nasa.jpf.conformanceChecker.providers.StandardClassProvider;
import gov.nasa.jpf.conformanceChecker.util.MaybeVersion;
import gov.nasa.jpf.jvm.ClassInfo;

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

import org.junit.Test;

/**
* @author Matteo Ceccarello <matteo.ceccarello AT gmail.com>
*
*/
public class OrphanMethodCheckerTest {

  @Test
  public void testSuccess1() {
    ClassInfo model =
        cls("java.lang.Object",
            method(PUBLIC, "java.lang.String", "toString", new String[]{})
            );
    ClassInfo standard =
        cls("java.lang.Object",
            method(PUBLIC, "java.lang.String", "toString", new String[]{})
            );
    Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
    versions.put(just(6), standard);
    StandardClassProvider provider = createMock(StandardClassProvider.class);
    expect(provider.loadClassInfo("java.lang.Object")).andReturn(versions);
    replay(provider);
    ProviderFactory.setStandardProvider(provider);
   
    Checker checker = new OrphanMethodChecker();
    assertTrue(checker.check(model));   
  }
 
  @Test
  public void testSuccess2() {
    // methods missing are not detected by this checker
    ClassInfo model =
        cls("java.lang.Object",
            method(PUBLIC, "java.lang.String", "toString", new String[]{})
            );
    ClassInfo standard =
        cls("java.lang.Object",
            method(PUBLIC, "java.lang.String", "toString", new String[]{}),
            method(PROTECTED, "java.lang.Object", "clone", new String[]{})
            );
    Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
    versions.put(just(6), standard);
    StandardClassProvider provider = createMock(StandardClassProvider.class);
    expect(provider.loadClassInfo("java.lang.Object")).andReturn(versions);
    replay(provider);
    ProviderFactory.setStandardProvider(provider);
   
    Checker checker = new OrphanMethodChecker();
    assertTrue(checker.check(model));   
  }
 
  @Test
  public void testFailure1() {
    ClassInfo model =
        cls("java.lang.Object",
            method(PUBLIC, "java.lang.String", "toString", new String[]{}),
            method(PUBLIC, "void", "coolMethodThatDoesNotExist", new String[0])
            );
    ClassInfo standard =
        cls("java.lang.Object",
            method(PUBLIC, "java.lang.String", "toString", new String[]{})
            );
    Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
    versions.put(just(6), standard);
    StandardClassProvider provider = createMock(StandardClassProvider.class);
    expect(provider.loadClassInfo("java.lang.Object")).andReturn(versions);
    replay(provider);
    ProviderFactory.setStandardProvider(provider);
   
    Checker checker = new OrphanMethodChecker();
    assertFalse(checker.check(model));   
  }

}
TOP

Related Classes of gov.nasa.jpf.conformanceChecker.checkers.OrphanMethodCheckerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.