@Test public void shouldThrowIfVersionIsMisrepresented() throws IOException, ClassNotFoundException { IndexAnalysisSettings obj = new IndexAnalysisSettings(); obj.setAnalyzerGuruVersion(ANALYZER_GURU_VERSION); obj.setProjectName(PROJECT_NAME); obj.setTabSize(TABSIZE); byte[] bin = obj.serialize(); IndexAnalysisSettingsUpgrader upgrader = new IndexAnalysisSettingsUpgrader(); IndexAnalysisSettings3 res = null; try { res = upgrader.upgrade(bin, 3); } catch (ClassCastException e) { } assertNull("should not have produced an instance", res); }
public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } } }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }  }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }  IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion); }
IndexAnalysisSettingsUpgrader { public IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion) throws ClassNotFoundException, IOException { switch (objectVersion) { case 1: throw new IOException("Too old version " + objectVersion); case 2: IndexAnalysisSettings old2 = IndexAnalysisSettings.deserialize(bytes); return convertFromV2(old2); case 3: return IndexAnalysisSettings3.deserialize(bytes); default: throw new IllegalArgumentException("Unknown version " + objectVersion); } }  IndexAnalysisSettings3 upgrade(byte[] bytes, int objectVersion);  }