Advertisement
pongfactory

testCase1

Oct 3rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.52 KB | None | 0 0
  1.  
  2. Skip to content
  3. This repository
  4.  
  5.     Pull requests
  6.     Issues
  7.     Gist
  8.  
  9.     @pakaponk
  10.  
  11. 3
  12. 0
  13.  
  14.     0
  15.  
  16. 2110215-ProgMeth/2110215_Solution_MIDTERM Private
  17. Code
  18. Issues 0
  19. Pull requests 0
  20. Projects 0
  21. Wiki
  22. Pulse
  23. Graphs
  24. Settings
  25. 2110215_Solution_MIDTERM/src/test/TestAccessModifier.java
  26. f9d1118 on 30 Sep 2015
  27. @pichitpr pichitpr Add abstract testing
  28. @pakaponk
  29. @pichitpr
  30. 115 lines (98 sloc) 3.89 KB
  31. package test;
  32.  
  33. import static org.junit.Assert.*;
  34.  
  35. import java.lang.reflect.Field;
  36. import java.lang.reflect.Modifier;
  37.  
  38. import org.junit.Test;
  39.  
  40. import simInterface.ICharacter;
  41. import character.Chocobo;
  42. import character.JumperChocobo;
  43. import character.Pikachu;
  44.  
  45. public class TestAccessModifier {
  46.  
  47.     @Test
  48.     public void testFieldAccessModifier() {
  49.        
  50.         //Field 'speed' of Chocobo
  51.         try {
  52.             Field speedField = Chocobo.class.getDeclaredField("speed");
  53.             assertEquals("Wrong access modifier for 'speed' field in 'Chocobo'", Modifier.PROTECTED , speedField.getModifiers());
  54.         } catch (NoSuchFieldException e) {
  55.             // TODO Auto-generated catch block
  56.             fail("Chocobo doesn't have 'speed' field.");
  57.         } catch (SecurityException e) {
  58.             // TODO Auto-generated catch block
  59.             e.printStackTrace();
  60.         }
  61.        
  62.         //Field 'distance' of Chocobo
  63.         try {
  64.             Field distanceField = Chocobo.class.getDeclaredField("distance");
  65.             assertEquals("Wrong access modifier for 'distance' field in 'Chocobo'", Modifier.PROTECTED , distanceField.getModifiers());
  66.         } catch (NoSuchFieldException e) {
  67.             // TODO Auto-generated catch block
  68.             fail("Chocobo doesn't have 'distance' field.");
  69.         } catch (SecurityException e) {
  70.             // TODO Auto-generated catch block
  71.             e.printStackTrace();
  72.         }
  73.        
  74.         //Field 'turnCount' of JumperChocobo
  75.         try {
  76.             Field turnCountField = JumperChocobo.class.getDeclaredField("turnCount");
  77.             assertEquals("Wrong access modifier for 'turnCount' field in 'JumperChocobo'", Modifier.PRIVATE , turnCountField.getModifiers());
  78.         } catch (NoSuchFieldException e) {
  79.             // TODO Auto-generated catch block
  80.             fail("JumperChocobo doesn't have 'turnCount' field.");
  81.         } catch (SecurityException e) {
  82.             // TODO Auto-generated catch block
  83.             e.printStackTrace();
  84.         }
  85.        
  86.         //Field 'obstructedDuration' of JumperChocobo
  87.         try {
  88.             Field obstructedDurationField = JumperChocobo.class.getDeclaredField("obstructedDuration");
  89.             assertEquals("Wrong access modifier for 'obstructedDuration' field in 'JumperChocobo'", Modifier.PRIVATE , obstructedDurationField.getModifiers());
  90.         } catch (NoSuchFieldException e) {
  91.             // TODO Auto-generated catch block
  92.             fail("JumperChocobo doesn't have 'obstructedDuration' field.");
  93.         } catch (SecurityException e) {
  94.             // TODO Auto-generated catch block
  95.             e.printStackTrace();
  96.         }
  97.        
  98.         //Field 'speed' of Pikachu
  99.         try {
  100.             Field speedField = Pikachu.class.getDeclaredField("speed");
  101.             assertEquals("Wrong access modifier for 'speed' field in 'Pikachu'", Modifier.PRIVATE , speedField.getModifiers());
  102.         } catch (NoSuchFieldException e) {
  103.             // TODO Auto-generated catch block
  104.             fail("Pikachu doesn't have 'speed' field.");
  105.         } catch (SecurityException e) {
  106.             // TODO Auto-generated catch block
  107.             e.printStackTrace();
  108.         }
  109.        
  110.         //Field 'distance' of Pikachu
  111.         try {
  112.             Field distanceField = Pikachu.class.getDeclaredField("distance");
  113.             assertEquals("Wrong access modifier for 'distance' field in 'Pikachu'", Modifier.PRIVATE , distanceField.getModifiers());
  114.         } catch (NoSuchFieldException e) {
  115.             // TODO Auto-generated catch block
  116.             fail("Pikachu doesn't have 'distance' field.");
  117.         } catch (SecurityException e) {
  118.             // TODO Auto-generated catch block
  119.             e.printStackTrace();
  120.         }
  121.        
  122.         //Field 'obstructedDuration' of Pikachu
  123.         try {
  124.             Field obstructedDurationField = Pikachu.class.getDeclaredField("obstructedDuration");
  125.             assertEquals("Wrong access modifier for 'obstructedDuration' field in 'Pikachu'", Modifier.PRIVATE , obstructedDurationField.getModifiers());
  126.         } catch (NoSuchFieldException e) {
  127.             // TODO Auto-generated catch block
  128.             fail("Pikachu doesn't have 'obstructedDuration' field.");
  129.         } catch (SecurityException e) {
  130.             // TODO Auto-generated catch block
  131.             e.printStackTrace();
  132.         }
  133.        
  134.     }
  135.  
  136.     @Test
  137.     public void testAbstractAndInterfaceModifier() {
  138.         //interface ICharacter
  139.         assertTrue(Modifier.isInterface(ICharacter.class.getModifiers()));
  140.        
  141.         //abstract class Chocobo
  142.         assertTrue(Modifier.isAbstract(Chocobo.class.getModifiers()));
  143.     }
  144. }
  145.  
  146.     Contact GitHub API Training Shop Blog About
  147.  
  148.     © 2016 GitHub, Inc. Terms Privacy Security Status Help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement