Package gov.nasa.jpf.conformanceChecker.checkers

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

//
// 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.*;
import static gov.nasa.jpf.conformanceChecker.util.MockFactory.*;
import static java.lang.reflect.Modifier.*;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.*;
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;

public class OrphanFieldCheckerTest {

  @Test
  public void successInstanceTest() {
    ClassInfo model =
        cls("test.Class",
            field(PUBLIC, "java.lang.String", "name")           
            );
    ClassInfo standard =
        cls("test.Class",
            field(PUBLIC, "java.lang.String", "name"),
            field(PROTECTED, "java.lang.String", "fullName")
            );
    Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
    versions.put(just(6), standard);
    StandardClassProvider provider = createMock(StandardClassProvider.class);
    expect(provider.loadClassInfo("test.Class")).andReturn(versions);
    replay(provider);
    ProviderFactory.setStandardProvider(provider);

    Checker checker = new OrphanInstanceFieldChecker();
    assertTrue(checker.check(model));   

  }
 
  @Test
  public void successStaticTest() {
    ClassInfo model =
        cls("test.Class",
            field(PUBLIC | STATIC, "java.lang.String", "name")
            );
    ClassInfo standard =
        cls("test.Class",
            field(PUBLIC | STATIC, "java.lang.String", "name")
            );
    Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
    versions.put(just(6), standard);
    StandardClassProvider provider = createMock(StandardClassProvider.class);
    expect(provider.loadClassInfo("test.Class")).andReturn(versions);
    replay(provider);
    ProviderFactory.setStandardProvider(provider);

    Checker checker = new OrphanStaticFieldChecker();
    assertTrue(checker.check(model));   

  }
 
  @Test
  public void failureInstanceTest() {
    ClassInfo model =
        cls("test.Class",
            field(PUBLIC, "java.lang.String", "name"),
            field(PROTECTED, "java.lang.Thread", "t")
            );
    ClassInfo standard =
        cls("test.Class",
            field(PUBLIC, "java.lang.String", "name")
            );
    Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
    versions.put(just(6), standard);
    StandardClassProvider provider = createMock(StandardClassProvider.class);
    expect(provider.loadClassInfo("test.Class")).andReturn(versions);
    replay(provider);
    ProviderFactory.setStandardProvider(provider);

    Checker checker = new OrphanInstanceFieldChecker();
    assertFalse(checker.check(model));   

  }
 
  @Test
  public void failureStaticTest() {
    ClassInfo model =
        cls("test.Class",
            field(PUBLIC | STATIC, "java.lang.String", "name"),
            field(PROTECTED | STATIC, "int", "n")
            );
    ClassInfo standard =
        cls("test.Class",
            field(PUBLIC | STATIC, "java.lang.String", "name")
            );
    Map<MaybeVersion, ClassInfo> versions = new HashMap<MaybeVersion, ClassInfo>();
    versions.put(just(6), standard);
    StandardClassProvider provider = createMock(StandardClassProvider.class);
    expect(provider.loadClassInfo("test.Class")).andReturn(versions);
    replay(provider);
    ProviderFactory.setStandardProvider(provider);

    Checker checker = new OrphanStaticFieldChecker();
    assertFalse(checker.check(model));   

  }

}
TOP

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

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.