//
// 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 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 static gov.nasa.jpf.conformanceChecker.util.MockFactory.*;
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 MissingFieldCheckerTest {
@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")
);
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 MissingInstanceFieldChecker();
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 MissingStaticFieldChecker();
assertTrue(checker.check(model));
}
@Test
public void failureInstanceTest() {
ClassInfo model =
cls("test.Class",
field(PUBLIC, "java.lang.String", "name")
);
ClassInfo standard =
cls("test.Class",
field(PUBLIC, "java.lang.String", "name"),
field(PUBLIC, "int", "number")
);
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 MissingInstanceFieldChecker();
assertFalse(checker.check(model));
}
@Test
public void failureStaticTest() {
ClassInfo model =
cls("test.Class",
field(PUBLIC | STATIC, "java.lang.String", "name")
);
ClassInfo standard =
cls("test.Class",
field(PUBLIC | STATIC, "java.lang.String", "name"),
field(PUBLIC | STATIC, "int", "number")
);
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 MissingStaticFieldChecker();
assertFalse(checker.check(model));
}
}