/testability-explorer/src/test/java/com/google/test/metric/LocalVariableStateTest.java

http://testability-explorer.googlecode.com/ · Java · 61 lines · 36 code · 10 blank · 15 comment · 0 complexity · 28ece8fc82b49cde97245f1746a0df4f MD5 · raw file

  1. /*
  2. * Copyright 2008 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.test.metric;
  17. import junit.framework.TestCase;
  18. public class LocalVariableStateTest extends TestCase {
  19. VariableState globals = new VariableState();
  20. LocalVariableState locals = new LocalVariableState(globals);
  21. Variable instance = new Variable("var", null, false, false);
  22. Variable lod = new Variable("lod", null, false, false);
  23. FieldInfo field = new FieldInfo(null, "field", null, false, false, false);
  24. public void testGlobalRouting() throws Exception {
  25. locals.setGlobal(field);
  26. locals.setInjectable(field);
  27. assertTrue(globals.isGlobal(field));
  28. assertTrue(globals.isInjectable(field));
  29. }
  30. public void testLocalRouting() throws Exception {
  31. locals.setGlobal(instance);
  32. locals.setInjectable(instance);
  33. assertTrue(locals.isGlobal(instance));
  34. assertTrue(locals.isInjectable(instance));
  35. }
  36. public void testToString() throws Exception {
  37. locals.setGlobal(instance);
  38. locals.setInjectable(field);
  39. locals.setLoDCount(lod, 123);
  40. String text = locals.toString();
  41. assertTrue(text, text.contains("var"));
  42. assertTrue(text, text.contains("field"));
  43. assertTrue(text, text.contains("lod"));
  44. assertTrue(text, text.contains("123"));
  45. }
  46. public void testLodCount() throws Exception {
  47. locals.setLoDCount(lod, 123);
  48. assertEquals(123, locals.getLoDCount(lod));
  49. assertEquals(0, locals.getLoDCount(instance));
  50. }
  51. }