@Test public void testPrimaryKeyMethodXmlAttributeNotInKeyClass() { Method getUserTutorialId = null; Class<UserTutorial> cls = UserTutorial.class; try { getUserTutorialId = cls.getDeclaredMethod("getUserTutorialId"); } catch (NoSuchMethodException e) { Assert.fail( "NoSuchMethodException thrown. Check MyBatisGeneratorConfig.xml: " + e.getMessage()); } // getUserTutorialId.setAccessible(true); Annotation annt = getUserTutorialId.getAnnotation(XmlAttribute.class); Assert.assertNotNull( "@XmlAttribute annotation missing from UserTutorial.getUserTutorialId() method", annt); String name = ((XmlAttribute) annt).name(); boolean required = ((XmlAttribute) annt).required(); Assert.assertEquals( "name attribute of the @XmlAttribute annotation is wrong or missing in UserTutorial.getUserTutorialId() method", "tutorialId", name); Assert.assertTrue( "required attribute of @XmlAttribute annotation is wrong or missing in UserTutorial.getUserTutorialId() method", required); }
@Test public void testMethodInBaseClassIsAnnotated() { Method getUserId = null; try { getUserId = UserTutorial.class.getDeclaredMethod("getUserId"); } catch (NoSuchMethodException e) { Assert.fail( "NoSuchMethodException thrown. Check SetupDbTestScripts.sql file: " + e.getMessage()); } // getUserId.setAccessible(true); Annotation annt = getUserId.getAnnotation(XmlElement.class); Assert.assertNotNull( "@XmlElement annotation missing from UserTutorial.getUserId() method", annt); String name = ((XmlElement) annt).name(); boolean required = ((XmlElement) annt).required(); Assert.assertEquals( "name attribute of the @XmlElement annotation is wrong or missing in UserTutorial.getUserId() method", "userId", name); Assert.assertTrue( "required attribute of @XmlElement annotation is wrong or missing in UserTutorial.getUserId() method", required); }
@Test public void testGetNarrativeMethodNotAnnotatedInBlobsClass() { Method getNarrative = null; try { getNarrative = UserTutorialWithBLOBs.class.getDeclaredMethod("getNarrative"); } catch (NoSuchMethodException e) { Assert.fail( "NoSuchMethodException thrown. Check SetupDbTestScripts.sql file: " + e.getMessage()); } // getNarrative.setAccessible(true); Annotation annt = getNarrative.getAnnotation(XmlElement.class); Assert.assertNotNull( "UserTutorialWithBLOBs.getNarrative() method should be annotated, but it isn't.", annt); String name = ((XmlElement) annt).name(); boolean required = ((XmlElement) annt).required(); Assert.assertEquals( "The name attribute of @XmlElement of UserTutorialWithBLOBs.getNarrative() method is wrong.", "TheFullContent", name); Assert.assertFalse( "The required attribute of @XmlElement of UserTutorialWithBLOBs.getNarrative() method should be false but it isn't.", required); }