### Question:
UpgradeDAO { @RequiresSession public UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction) { TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createNamedQuery( "UpgradeEntity.findLatestForClusterInDirection", UpgradeEntity.class); query.setMaxResults(1); query.setParameter("clusterId", clusterId); query.setParameter("direction", direction); return daoUtils.selectSingle(query); }  @RequiresSession List<UpgradeEntity> findAll(); @RequiresSession List<UpgradeEntity> findUpgrades(long clusterId); @RequiresSession UpgradeEntity findUpgrade(long upgradeId); @RequiresSession UpgradeEntity findUpgradeByRequestId(Long requestId); @Transactional void create(UpgradeEntity entity); @Transactional void removeAll(long clusterId); @RequiresSession UpgradeGroupEntity findUpgradeGroup(Long groupId); @RequiresSession UpgradeItemEntity findUpgradeItemByRequestAndStage(Long requestId, Long stageId); @RequiresSession UpgradeEntity findLastUpgradeForCluster(long clusterId, Direction direction); @RequiresSession UpgradeEntity findLastUpgradeOrDowngradeForCluster(long clusterId); @RequiresSession UpgradeEntity findRevertable(long clusterId); @RequiresSession UpgradeEntity findRevertableUsingJPQL(long clusterId); @Transactional UpgradeEntity merge(UpgradeEntity upgradeEntity);  }### Answer:
@Test public void testFindLastUpgradeForCluster() throws Exception { RequestEntity requestEntity = new RequestEntity(); requestEntity.setRequestId(1L); requestEntity.setClusterId(clusterId.longValue()); requestEntity.setStatus(HostRoleStatus.PENDING); requestEntity.setStages(new ArrayList<>()); requestDAO.create(requestEntity); UpgradeEntity entity1 = new UpgradeEntity(); entity1.setId(11L); entity1.setClusterId(clusterId.longValue()); entity1.setDirection(Direction.UPGRADE); entity1.setRequestEntity(requestEntity); entity1.setRepositoryVersion(repositoryVersion2500); entity1.setUpgradeType(UpgradeType.ROLLING); entity1.setUpgradePackage("test-upgrade"); entity1.setDowngradeAllowed(true); dao.create(entity1); UpgradeEntity entity2 = new UpgradeEntity(); entity2.setId(22L); entity2.setClusterId(clusterId.longValue()); entity2.setDirection(Direction.DOWNGRADE); entity2.setRequestEntity(requestEntity); entity2.setRepositoryVersion(repositoryVersion2200); entity2.setUpgradeType(UpgradeType.ROLLING); entity2.setUpgradePackage("test-upgrade"); entity2.setDowngradeAllowed(true); dao.create(entity2); UpgradeEntity entity3 = new UpgradeEntity(); entity3.setId(33L); entity3.setClusterId(clusterId.longValue()); entity3.setDirection(Direction.UPGRADE); entity3.setRequestEntity(requestEntity); entity3.setRepositoryVersion(repositoryVersion2511); entity3.setUpgradeType(UpgradeType.ROLLING); entity3.setUpgradePackage("test-upgrade"); entity3.setDowngradeAllowed(true); dao.create(entity3); UpgradeEntity lastUpgradeForCluster = dao.findLastUpgradeForCluster(clusterId.longValue(), Direction.UPGRADE); assertNotNull(lastUpgradeForCluster); assertEquals(33L, (long)lastUpgradeForCluster.getId()); }